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-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.ducks.IItemEntity;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemEntityCapabilities;
|
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;
|
|
|
|
|
|
|
|
@Mixin(ItemEntity.class)
|
2020-01-27 11:05:22 +01:00
|
|
|
public abstract class MixinItemEntity extends Entity implements IItemEntity {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
private final ItemEntityCapabilities caster = create();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private MixinItemEntity() { super(null, null); }
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public ItemEntityCapabilities create() {
|
2020-01-16 12:35:46 +01:00
|
|
|
return new ItemEntityCapabilities((ItemEntity)(Object)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public ItemEntityCapabilities get() {
|
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-01-27 11:05:22 +01:00
|
|
|
if (caster.beforeUpdate()) {
|
|
|
|
info.cancel();
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "tick()V", at = @At("RETURN"))
|
|
|
|
private void afterTick(CallbackInfo info) {
|
|
|
|
caster.onUpdate();
|
|
|
|
}
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
@Accessor("age")
|
|
|
|
@Override
|
|
|
|
public abstract int getAge();
|
|
|
|
|
|
|
|
@Accessor("pickupDelay")
|
|
|
|
@Override
|
|
|
|
public abstract int getPickupDelay();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|