2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
2020-01-27 11:05:22 +01:00
|
|
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
2020-01-16 12:35:46 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.*;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.ItemEntity;
|
2021-08-04 15:38:03 +02:00
|
|
|
import net.minecraft.nbt.NbtCompound;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
@Mixin(ItemEntity.class)
|
2020-04-24 17:10:45 +02:00
|
|
|
abstract class MixinItemEntity extends Entity implements IItemEntity {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
private ItemImpl caster;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private MixinItemEntity() { super(null, null); }
|
|
|
|
|
|
|
|
@Override
|
2022-12-25 16:01:12 +01:00
|
|
|
public Equine<?> create() {
|
2020-05-10 17:18:45 +02:00
|
|
|
return new ItemImpl((ItemEntity)(Object)this);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public ItemImpl get() {
|
2020-04-26 16:48:48 +02:00
|
|
|
if (caster == null) {
|
2022-12-25 16:01:12 +01:00
|
|
|
caster = (ItemImpl)create();
|
2020-04-26 16:48:48 +02:00
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
return caster;
|
|
|
|
}
|
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
@Inject(method = "tick()V", at = @At("HEAD"), cancellable = true)
|
2020-01-16 12:35:46 +01:00
|
|
|
private void beforeTick(CallbackInfo info) {
|
2020-04-26 16:48:48 +02:00
|
|
|
if (get().beforeUpdate()) {
|
2020-01-27 11:05:22 +01:00
|
|
|
info.cancel();
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "tick()V", at = @At("RETURN"))
|
|
|
|
private void afterTick(CallbackInfo info) {
|
2020-05-10 17:18:45 +02:00
|
|
|
get().tick();
|
2020-04-26 16:48:48 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
@Inject(method = "writeCustomDataToNbt(Lnet/minecraft/nbt/NbtCompound;)V", at = @At("HEAD"))
|
|
|
|
private void onWriteCustomDataToTag(NbtCompound tag, CallbackInfo info) {
|
2021-02-22 14:53:59 +01:00
|
|
|
tag.put("unicopia_caster", get().toNBT());
|
2020-04-26 16:48:48 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
@Inject(method = "readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V", at = @At("HEAD"))
|
|
|
|
private void onReadCustomDataFromTag(NbtCompound tag, CallbackInfo info) {
|
2021-02-22 14:53:59 +01:00
|
|
|
if (tag.contains("unicopia_caster")) {
|
|
|
|
get().fromNBT(tag.getCompound("unicopia_caster"));
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
@Accessor("itemAge")
|
2020-01-27 11:05:22 +01:00
|
|
|
@Override
|
|
|
|
public abstract int getAge();
|
|
|
|
|
|
|
|
@Accessor("pickupDelay")
|
|
|
|
@Override
|
|
|
|
public abstract int getPickupDelay();
|
2020-04-26 16:48:48 +02:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|