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;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.ducks.PonyContainer;
|
|
|
|
import com.minelittlepony.unicopia.entity.Ponylike;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.LivingEntityCapabilities;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
|
|
|
|
@Mixin(LivingEntity.class)
|
2020-04-15 18:12:00 +02:00
|
|
|
public abstract class MixinLivingEntity extends Entity implements PonyContainer<Ponylike> {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
private final Ponylike caster = create();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private MixinLivingEntity() { super(null, null); }
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public Ponylike create() {
|
2020-01-16 12:35:46 +01:00
|
|
|
return new LivingEntityCapabilities((LivingEntity)(Object)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public Ponylike get() {
|
2020-01-16 12:35:46 +01:00
|
|
|
return caster;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "canSee(Lnet/minecraft/entity/Entity)Z", at = @At("HEAD"))
|
|
|
|
private void onCanSee(Entity other, CallbackInfoReturnable<Boolean> info) {
|
|
|
|
if (caster.isInvisible()) {
|
|
|
|
info.setReturnValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "method_6040()V", at = @At("HEAD"))
|
|
|
|
protected void onFinishUsing(CallbackInfo info) {
|
|
|
|
LivingEntity self = (LivingEntity)(Object)this;
|
|
|
|
|
|
|
|
if (!self.getActiveItem().isEmpty() && self.isUsingItem()) {
|
|
|
|
caster.onUse(self.getActiveItem());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "jump()V", at = @At("RETURN"))
|
|
|
|
private void onJump(CallbackInfo info) {
|
|
|
|
caster.onJump();
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:37: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 17:37: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "<clinit>()V", at = @At("RETURN"))
|
|
|
|
private static void clinit(CallbackInfo info) {
|
|
|
|
LivingEntityCapabilities.boostrap();
|
|
|
|
}
|
2020-04-22 20:23:54 +02:00
|
|
|
|
|
|
|
// ---------- temporary
|
2020-04-24 00:17:38 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2020-04-22 20:23:54 +02:00
|
|
|
@Inject(method = "isClimbing()Z", at = @At("HEAD"), cancellable = true)
|
|
|
|
public void onIsClimbing(CallbackInfoReturnable<Boolean> info) {
|
|
|
|
LivingEntity self = (LivingEntity)(Object)this;
|
|
|
|
|
|
|
|
if (!self.isSpectator() && self.getBlockState().getBlock() instanceof com.minelittlepony.unicopia.ducks.Climbable) {
|
|
|
|
info.setReturnValue(true);
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|