Unicopia/src/main/java/com/minelittlepony/unicopia/mixin/MixinItem.java

44 lines
1.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.mixin;
import java.util.ArrayList;
import java.util.List;
2023-09-11 22:20:03 +02:00
import java.util.function.Supplier;
2023-11-10 15:11:53 +01:00
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
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;
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.*;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@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);
@Override
public List<GroundTickCallback> getCallbacks() {
return tickCallbacks;
}
@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);
}
}