2020-04-25 22:03:36 +02:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
|
|
|
|
2020-10-08 13:16:16 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2020-04-25 22:03:36 +02:00
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
2020-10-08 13:16:16 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
2020-04-25 22:03:36 +02:00
|
|
|
|
2020-10-08 13:16:16 +02:00
|
|
|
import com.minelittlepony.unicopia.item.toxin.Toxic;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
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;
|
|
|
|
import net.minecraft.world.World;
|
2020-04-25 22:03:36 +02:00
|
|
|
|
|
|
|
@Mixin(Item.class)
|
|
|
|
abstract class MixinItem implements ToxicHolder {
|
2020-10-08 13:16:16 +02:00
|
|
|
|
|
|
|
private Optional<Toxic> toxic = Optional.empty();
|
|
|
|
|
2020-04-25 22:03:36 +02:00
|
|
|
@Override
|
|
|
|
@Accessor("foodComponent")
|
|
|
|
public abstract void setFood(FoodComponent food);
|
2020-10-08 13:16:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setToxic(Toxic toxic) {
|
|
|
|
this.toxic = Optional.of(toxic);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<Toxic> getToxic() {
|
|
|
|
return toxic;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
|
|
|
|
private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable<ItemStack> info) {
|
|
|
|
if (getToxic().isPresent()) {
|
|
|
|
getToxic().get().finishUsing(stack, world, entity);
|
|
|
|
}
|
|
|
|
}
|
2020-04-25 22:03:36 +02:00
|
|
|
}
|