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;
|
2020-05-10 17:18:45 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.Constant;
|
2020-01-16 12:35:46 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
2020-05-10 17:18:45 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
2020-01-16 12:35:46 +01:00
|
|
|
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;
|
2020-06-26 11:44:47 +02:00
|
|
|
import com.minelittlepony.unicopia.equine.Creature;
|
|
|
|
import com.minelittlepony.unicopia.equine.Ponylike;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
2020-04-26 16:48:48 +02:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
2020-05-10 17:18:45 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
@Mixin(LivingEntity.class)
|
2020-05-10 17:18:45 +02:00
|
|
|
abstract class MixinLivingEntity extends Entity implements PonyContainer<Ponylike<?>> {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
private Ponylike<?> caster;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private MixinLivingEntity() { super(null, null); }
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public Ponylike<?> create() {
|
|
|
|
return new Creature((LivingEntity)(Object)this);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public Ponylike<?> get() {
|
2020-04-24 19:36:30 +02:00
|
|
|
if (caster == null) {
|
|
|
|
caster = create();
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
return caster;
|
|
|
|
}
|
|
|
|
|
2020-05-05 16:42:14 +02:00
|
|
|
@Inject(method = "canSee(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"), cancellable = true)
|
2020-01-16 12:35:46 +01:00
|
|
|
private void onCanSee(Entity other, CallbackInfoReturnable<Boolean> info) {
|
2020-04-24 19:36:30 +02:00
|
|
|
if (get().isInvisible()) {
|
2020-01-16 12:35:46 +01:00
|
|
|
info.setReturnValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "jump()V", at = @At("RETURN"))
|
|
|
|
private void onJump(CallbackInfo info) {
|
2020-04-24 19:36:30 +02:00
|
|
|
get().onJump();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
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-04-24 19:36:30 +02:00
|
|
|
if (get().beforeUpdate()) {
|
2020-01-27 17:37: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-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 17:10:45 +02:00
|
|
|
@Inject(method = "<clinit>()V", at = @At("RETURN"), remap = false)
|
2020-01-16 12:35:46 +01:00
|
|
|
private static void clinit(CallbackInfo info) {
|
2020-05-10 17:18:45 +02:00
|
|
|
Creature.boostrap();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-04-22 20:23:54 +02:00
|
|
|
|
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) {
|
2020-05-03 19:45:23 +02:00
|
|
|
tag.put("unicopia_caster", get().toNBT());
|
2020-04-26 16:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("HEAD"))
|
|
|
|
private void onReadCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
2020-05-03 19:45:23 +02:00
|
|
|
if (tag.contains("unicopia_caster")) {
|
|
|
|
get().fromNBT(tag.getCompound("unicopia_caster"));
|
|
|
|
}
|
2020-04-26 16:48:48 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
@ModifyConstant(method = "travel(Lnet/minecraft/util/math/Vec3d;)V", constant = {
|
|
|
|
@Constant(doubleValue = 0.08D),
|
|
|
|
@Constant(doubleValue = 0.01D)
|
|
|
|
})
|
|
|
|
private double modifyGravity(double initial) {
|
|
|
|
return get().getPhysics().calcGravity(initial);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockPos getLandingPos() {
|
|
|
|
if (get().getPhysics().isGravityNegative()) {
|
|
|
|
return get().getPhysics().getHeadPosition();
|
|
|
|
}
|
|
|
|
return super.getLandingPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void spawnSprintingParticles() {
|
|
|
|
if (get().getPhysics().isGravityNegative()) {
|
|
|
|
get().getPhysics().spawnSprintingParticles();
|
|
|
|
} else {
|
|
|
|
super.spawnSprintingParticles();
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|