Fixed disguises

This commit is contained in:
Sollace 2020-05-05 16:42:14 +02:00
parent 4e3db62e78
commit c12b67e909
3 changed files with 59 additions and 21 deletions

View file

@ -27,6 +27,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.Flutterer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.data.TrackedData;
@ -43,7 +44,6 @@ import net.minecraft.entity.projectile.ShulkerBulletEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.MathHelper;
public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect, SuppressableEffect, FlightPredicate, HeightPredicate {
@ -204,13 +204,15 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
protected void copyBaseAttributes(LivingEntity from, Entity to) {
// Set first because position calculations rely on it
to.age = from.age;
to.removed = from.removed;
to.onGround = from.onGround;
if (isAttachedEntity(entity)) {
double x = Math.floor(from.getX()) + 0.5;
double y = Math.floor(from.getX());
double z = Math.floor(from.getX()) + 0.5;
double y = Math.floor(from.getY());
double z = Math.floor(from.getZ()) + 0.5;
to.prevX = x;
to.prevY = y;
@ -220,7 +222,11 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
to.lastRenderY = y;
to.lastRenderZ = z;
to.setPos(x, y, z);
to.updatePosition(x, y, z);
if (entity instanceof FallingBlockEntity) {
((FallingBlockEntity)entity).setFallingBlockPos(from.getBlockPos());
}
} else {
to.copyPositionAndRotation(from);
@ -228,6 +234,10 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
to.prevY = from.prevY;
to.prevZ = from.prevZ;
to.trackedX = from.trackedX;
to.trackedY = from.trackedY;
to.trackedZ = from.trackedZ;
to.lastRenderX = from.lastRenderX;
to.lastRenderY = from.lastRenderY;
to.lastRenderZ = from.lastRenderZ;
@ -243,8 +253,13 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
to.setVelocity(from.getVelocity());
to.pitch = from.pitch;
to.prevPitch = from.prevPitch;
to.yaw = from.yaw;
to.prevYaw = from.prevYaw;
to.horizontalSpeed = from.horizontalSpeed;
to.prevHorizontalSpeed = from.prevHorizontalSpeed;
to.distanceTraveled = from.distanceTraveled;
if (to instanceof LivingEntity) {
@ -266,6 +281,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
l.hurtTime = from.hurtTime;
l.deathTime = from.deathTime;
l.field_20347 = from.field_20347;
l.setHealth(from.getHealth());
for (EquipmentSlot i : EquipmentSlot.values()) {
@ -305,9 +321,13 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
return update(caster);
}
@SuppressWarnings("unchecked")
@Override
public boolean update(Caster<?> source) {
return update(source, true);
}
@SuppressWarnings("unchecked")
public boolean update(Caster<?> source, boolean tick) {
LivingEntity owner = source.getOwner();
if (getSuppressed()) {
@ -355,7 +375,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
copyBaseAttributes(owner, entity);
if (!skipsUpdate(entity)) {
if (tick && !skipsUpdate(entity)) {
entity.tick();
}
@ -363,24 +383,26 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
ShulkerEntity shulker = ((ShulkerEntity)entity);
shulker.yaw = 0;
//shulker.renderYawOffset = 0;
//shulker.prevRenderYawOffset = 0;
shulker.prevHeadYaw = 0;
shulker.headYaw = 0;
shulker.prevBodyYaw = 0;
shulker.bodyYaw = 0;
shulker.setAttachedBlock(null);
if (source.isClient() && source instanceof Pony) {
Pony player = (Pony)source;
//Pony player = (Pony)source;
float peekAmount = 0.3F;
float peekAmount = 30;
if (!owner.isSneaking()) {
double speed = Math.sqrt(Entity.squaredHorizontalLength(owner.getVelocity()));
//if (!owner.isSneaking()) {
//Math.sqrt(Entity.squaredHorizontalLength(owner.getVelocity()));
peekAmount = (float)MathHelper.clamp(speed * 30, 0, 1);
}
//peekAmount = (float)MathHelper.clamp(speed * 30, 0, 1);
//}
peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);
//peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);
shulker.setPeekAmount((int)peekAmount);
}
@ -488,6 +510,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|| entity instanceof EnderDragonEntity
|| entity instanceof VexEntity
|| entity instanceof ShulkerBulletEntity
|| entity instanceof Flutterer
|| ProjectileUtil.isProjectile(entity);
}

View file

@ -34,7 +34,7 @@ abstract class MixinLivingEntity extends Entity implements PonyContainer<Ponylik
return caster;
}
@Inject(method = "canSee(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"))
@Inject(method = "canSee(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"), cancellable = true)
private void onCanSee(Entity other, CallbackInfoReturnable<Boolean> info) {
if (get().isInvisible()) {
info.setReturnValue(false);

View file

@ -7,20 +7,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.magic.spell.DisguiseSpell;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@Mixin(EntityRenderDispatcher.class)
abstract class MixinEntityRenderDispatcher {
private static final String RENDER = "render(Lnet/minecraft/entity/Entity;DDDFFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V";
@Inject(method = RENDER, at = @At("HEAD"))
@Inject(method = RENDER, at = @At("HEAD"), cancellable = true)
private <E extends Entity> void beforeRender(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
matrices.push();
if (!(entity instanceof PlayerEntity)) {
return;
@ -29,29 +32,40 @@ abstract class MixinEntityRenderDispatcher {
Pony pony = Pony.of((PlayerEntity)entity);
if (pony.getGravity().getGravitationConstant() < 0) {
matrices.push();
matrices.translate(0, entity.getDimensions(entity.getPose()).height, 0);
matrices.scale(1, -1, 1);
entity.prevPitch *= -1;
entity.pitch *= -1;
}
DisguiseSpell effect = pony.getEffect(DisguiseSpell.class, false);
DisguiseSpell effect = pony.getEffect(DisguiseSpell.class, true);
if (effect == null || effect.isDead()) {
return;
}
effect.update(pony, false);
Entity e = effect.getDisguise();
if (e != null) {
info.cancel();
((EntityRenderDispatcher)(Object)this).render(entity, x, y, z, yaw, tickDelta, matrices, vertexConsumers, light);
if (DisguiseSpell.isAttachedEntity(e) && (x != 0 || y != 0 || z != 0)) {
Vec3d cam = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
x = MathHelper.lerp(tickDelta, e.lastRenderX, e.getX()) - cam.x;
y = MathHelper.lerp(tickDelta, e.lastRenderY, e.getY()) - cam.y;
z = MathHelper.lerp(tickDelta, e.lastRenderZ, e.getZ()) - cam.z;
}
((EntityRenderDispatcher)(Object)this).render(e, x, y, z, yaw, tickDelta, matrices, vertexConsumers, light);
}
}
@Inject(method = RENDER, at = @At("HEAD"))
private <E extends Entity> void afterRender(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
matrices.pop();
if (!(entity instanceof PlayerEntity)) {
return;
@ -60,6 +74,7 @@ abstract class MixinEntityRenderDispatcher {
Pony pony = Pony.of((PlayerEntity)entity);
if (pony.getGravity().getGravitationConstant() < 0) {
matrices.pop();
entity.prevPitch *= -1;
entity.pitch *= -1;
}