2020-04-25 22:03:36 +02:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
|
|
|
|
2022-03-26 22:51:34 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2023-09-11 22:20:03 +02:00
|
|
|
import java.util.function.Supplier;
|
2020-10-08 13:16:16 +02:00
|
|
|
|
2023-11-10 15:11:53 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-04-25 22:03:36 +02:00
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
2021-06-21 23:49:55 +02:00
|
|
|
import org.spongepowered.asm.mixin.Mutable;
|
2023-09-11 22:20:03 +02:00
|
|
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
|
|
import com.google.common.base.Suppliers;
|
2022-03-26 22:51:34 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl.GroundTickCallback;
|
2022-09-30 12:43:07 +02:00
|
|
|
import com.minelittlepony.unicopia.item.toxin.*;
|
2020-04-25 22:03:36 +02:00
|
|
|
|
2020-10-08 13:16:16 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2020-04-25 22:03:36 +02:00
|
|
|
import net.minecraft.item.FoodComponent;
|
|
|
|
import net.minecraft.item.Item;
|
2020-10-08 13:16:16 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-04-25 22:03:36 +02:00
|
|
|
|
|
|
|
@Mixin(Item.class)
|
2023-09-11 22:20:03 +02:00
|
|
|
abstract class MixinItem implements ItemDuck {
|
2022-09-30 12:43:07 +02:00
|
|
|
private final List<ItemImpl.GroundTickCallback> tickCallbacks = new ArrayList<>();
|
2023-09-11 22:20:03 +02:00
|
|
|
private final Supplier<FoodComponent> originalFoodComponent = Suppliers.memoize(((Item)(Object)this)::getFoodComponent);
|
2022-03-26 22:51:34 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<GroundTickCallback> getCallbacks() {
|
|
|
|
return tickCallbacks;
|
|
|
|
}
|
|
|
|
|
2020-10-08 13:16:16 +02:00
|
|
|
@Override
|
2023-09-11 22:20:03 +02:00
|
|
|
@Mutable
|
|
|
|
@Accessor("foodComponent")
|
|
|
|
public abstract void setFoodComponent(FoodComponent food);
|
2022-09-30 12:43:07 +02:00
|
|
|
|
|
|
|
@Override
|
2023-11-10 15:11:53 +01:00
|
|
|
public Toxic getToxic(ItemStack stack, @Nullable LivingEntity entity) {
|
|
|
|
if (entity != null) {
|
|
|
|
setFoodComponent(originalFoodComponent.get());
|
|
|
|
}
|
|
|
|
return Toxics.lookup(this, entity);
|
2020-10-08 13:16:16 +02:00
|
|
|
}
|
2020-04-25 22:03:36 +02:00
|
|
|
}
|