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;
|
2020-10-08 13:16:16 +02:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-06-12 17:16:42 +02:00
|
|
|
|
2021-06-21 22:05:40 +02:00
|
|
|
import org.spongepowered.asm.mixin.Final;
|
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;
|
2021-06-21 22:05:40 +02:00
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
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
|
|
|
|
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;
|
|
|
|
import net.minecraft.world.World;
|
2020-04-25 22:03:36 +02:00
|
|
|
|
|
|
|
@Mixin(Item.class)
|
2022-03-26 22:51:34 +01:00
|
|
|
abstract class MixinItem implements ToxicHolder, ItemImpl.TickableItem {
|
2020-10-08 13:16:16 +02:00
|
|
|
|
2021-06-21 22:05:40 +02:00
|
|
|
private boolean foodLoaded;
|
2021-06-12 17:16:42 +02:00
|
|
|
@Nullable
|
|
|
|
private FoodComponent originalFoodComponent;
|
2020-10-08 13:16:16 +02:00
|
|
|
|
2021-06-21 23:49:55 +02:00
|
|
|
@Shadow @Mutable
|
2021-06-21 22:05:40 +02:00
|
|
|
private @Final FoodComponent foodComponent;
|
2020-10-08 13:16:16 +02:00
|
|
|
|
2022-09-30 12:43:07 +02:00
|
|
|
private final List<ItemImpl.GroundTickCallback> tickCallbacks = new ArrayList<>();
|
2022-03-26 22:51:34 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<GroundTickCallback> getCallbacks() {
|
|
|
|
return tickCallbacks;
|
|
|
|
}
|
|
|
|
|
2020-10-08 13:16:16 +02:00
|
|
|
@Override
|
2022-09-30 12:43:07 +02:00
|
|
|
public void clearFoodOverride() {
|
|
|
|
foodComponent = getOriginalFoodComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFoodOverride(FoodComponent component) {
|
|
|
|
if (getOriginalFoodComponent() == null) {
|
|
|
|
foodComponent = component;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FoodComponent getOriginalFoodComponent() {
|
2021-06-21 22:05:40 +02:00
|
|
|
if (!foodLoaded) {
|
|
|
|
foodLoaded = true;
|
2021-06-12 17:16:42 +02:00
|
|
|
originalFoodComponent = ((Item)(Object)this).getFoodComponent();
|
|
|
|
}
|
2022-09-30 12:43:07 +02:00
|
|
|
return originalFoodComponent;
|
2020-10-08 13:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
|
|
|
|
private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable<ItemStack> info) {
|
2022-09-30 12:43:07 +02:00
|
|
|
getToxic(stack).finishUsing(stack, world, entity);
|
2020-10-08 13:16:16 +02:00
|
|
|
}
|
2020-04-25 22:03:36 +02:00
|
|
|
}
|