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;
|
|
|
|
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.IItemEntity;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl;
|
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;
|
2020-04-26 16:48:48 +02:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
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
|
2020-05-10 17:18:45 +02:00
|
|
|
public ItemImpl create() {
|
|
|
|
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) {
|
|
|
|
caster = create();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "writeCustomDataToTag(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("HEAD"))
|
|
|
|
private void onWriteCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
|
|
|
if (tag.contains("unicopia_caster")) {
|
|
|
|
get().fromNBT(tag.getCompound("unicopia_caster"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("HEAD"))
|
|
|
|
private void onReadCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
|
|
|
tag.put("unicopia_caster", get().toNBT());
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
@Accessor("age")
|
|
|
|
@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
|
|
|
}
|