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-12-03 03:39:55 +01:00
|
|
|
import java.util.Optional;
|
2023-09-11 22:20:03 +02:00
|
|
|
import java.util.function.Supplier;
|
2020-10-08 13:16:16 +02:00
|
|
|
|
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;
|
2023-12-03 03:39:55 +01:00
|
|
|
import com.minelittlepony.unicopia.diet.DietView;
|
2022-03-26 22:51:34 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl.GroundTickCallback;
|
2023-12-03 03:39:55 +01:00
|
|
|
import com.minelittlepony.unicopia.item.ItemDuck;
|
2020-04-25 22:03:36 +02:00
|
|
|
import net.minecraft.item.FoodComponent;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
|
|
|
@Mixin(Item.class)
|
2023-12-03 03:39:55 +01:00
|
|
|
abstract class MixinItem implements ItemDuck, DietView.Holder {
|
2022-09-30 12:43:07 +02:00
|
|
|
private final List<ItemImpl.GroundTickCallback> tickCallbacks = new ArrayList<>();
|
2023-12-03 03:39:55 +01:00
|
|
|
private final Supplier<Optional<FoodComponent>> originalFoodComponent = Suppliers.memoize(() -> {
|
|
|
|
return Optional.ofNullable(((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-12-03 03:39:55 +01:00
|
|
|
public Optional<FoodComponent> getOriginalFoodComponent() {
|
|
|
|
return originalFoodComponent.get();
|
2020-10-08 13:16:16 +02:00
|
|
|
}
|
2020-04-25 22:03:36 +02:00
|
|
|
}
|