mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Fixed disguises
This commit is contained in:
parent
4e3db62e78
commit
c12b67e909
3 changed files with 59 additions and 21 deletions
|
@ -27,6 +27,7 @@ import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.FallingBlockEntity;
|
import net.minecraft.entity.FallingBlockEntity;
|
||||||
|
import net.minecraft.entity.Flutterer;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
|
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
|
||||||
import net.minecraft.entity.data.TrackedData;
|
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.entity.vehicle.MinecartEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect, SuppressableEffect, FlightPredicate, HeightPredicate {
|
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) {
|
protected void copyBaseAttributes(LivingEntity from, Entity to) {
|
||||||
|
|
||||||
// Set first because position calculations rely on it
|
// Set first because position calculations rely on it
|
||||||
|
to.age = from.age;
|
||||||
to.removed = from.removed;
|
to.removed = from.removed;
|
||||||
to.onGround = from.onGround;
|
to.onGround = from.onGround;
|
||||||
|
|
||||||
if (isAttachedEntity(entity)) {
|
if (isAttachedEntity(entity)) {
|
||||||
|
|
||||||
double x = Math.floor(from.getX()) + 0.5;
|
double x = Math.floor(from.getX()) + 0.5;
|
||||||
double y = Math.floor(from.getX());
|
double y = Math.floor(from.getY());
|
||||||
double z = Math.floor(from.getX()) + 0.5;
|
double z = Math.floor(from.getZ()) + 0.5;
|
||||||
|
|
||||||
to.prevX = x;
|
to.prevX = x;
|
||||||
to.prevY = y;
|
to.prevY = y;
|
||||||
|
@ -220,7 +222,11 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
to.lastRenderY = y;
|
to.lastRenderY = y;
|
||||||
to.lastRenderZ = z;
|
to.lastRenderZ = z;
|
||||||
|
|
||||||
to.setPos(x, y, z);
|
to.updatePosition(x, y, z);
|
||||||
|
|
||||||
|
if (entity instanceof FallingBlockEntity) {
|
||||||
|
((FallingBlockEntity)entity).setFallingBlockPos(from.getBlockPos());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
to.copyPositionAndRotation(from);
|
to.copyPositionAndRotation(from);
|
||||||
|
|
||||||
|
@ -228,6 +234,10 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
to.prevY = from.prevY;
|
to.prevY = from.prevY;
|
||||||
to.prevZ = from.prevZ;
|
to.prevZ = from.prevZ;
|
||||||
|
|
||||||
|
to.trackedX = from.trackedX;
|
||||||
|
to.trackedY = from.trackedY;
|
||||||
|
to.trackedZ = from.trackedZ;
|
||||||
|
|
||||||
to.lastRenderX = from.lastRenderX;
|
to.lastRenderX = from.lastRenderX;
|
||||||
to.lastRenderY = from.lastRenderY;
|
to.lastRenderY = from.lastRenderY;
|
||||||
to.lastRenderZ = from.lastRenderZ;
|
to.lastRenderZ = from.lastRenderZ;
|
||||||
|
@ -243,8 +253,13 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
|
|
||||||
to.setVelocity(from.getVelocity());
|
to.setVelocity(from.getVelocity());
|
||||||
|
|
||||||
|
to.pitch = from.pitch;
|
||||||
to.prevPitch = from.prevPitch;
|
to.prevPitch = from.prevPitch;
|
||||||
|
to.yaw = from.yaw;
|
||||||
to.prevYaw = from.prevYaw;
|
to.prevYaw = from.prevYaw;
|
||||||
|
to.horizontalSpeed = from.horizontalSpeed;
|
||||||
|
to.prevHorizontalSpeed = from.prevHorizontalSpeed;
|
||||||
|
|
||||||
to.distanceTraveled = from.distanceTraveled;
|
to.distanceTraveled = from.distanceTraveled;
|
||||||
|
|
||||||
if (to instanceof LivingEntity) {
|
if (to instanceof LivingEntity) {
|
||||||
|
@ -266,6 +281,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
|
|
||||||
l.hurtTime = from.hurtTime;
|
l.hurtTime = from.hurtTime;
|
||||||
l.deathTime = from.deathTime;
|
l.deathTime = from.deathTime;
|
||||||
|
l.field_20347 = from.field_20347;
|
||||||
l.setHealth(from.getHealth());
|
l.setHealth(from.getHealth());
|
||||||
|
|
||||||
for (EquipmentSlot i : EquipmentSlot.values()) {
|
for (EquipmentSlot i : EquipmentSlot.values()) {
|
||||||
|
@ -305,9 +321,13 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
return update(caster);
|
return update(caster);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(Caster<?> source) {
|
public boolean update(Caster<?> source) {
|
||||||
|
return update(source, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public boolean update(Caster<?> source, boolean tick) {
|
||||||
LivingEntity owner = source.getOwner();
|
LivingEntity owner = source.getOwner();
|
||||||
|
|
||||||
if (getSuppressed()) {
|
if (getSuppressed()) {
|
||||||
|
@ -355,7 +375,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
|
|
||||||
copyBaseAttributes(owner, entity);
|
copyBaseAttributes(owner, entity);
|
||||||
|
|
||||||
if (!skipsUpdate(entity)) {
|
if (tick && !skipsUpdate(entity)) {
|
||||||
entity.tick();
|
entity.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,24 +383,26 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
ShulkerEntity shulker = ((ShulkerEntity)entity);
|
ShulkerEntity shulker = ((ShulkerEntity)entity);
|
||||||
|
|
||||||
shulker.yaw = 0;
|
shulker.yaw = 0;
|
||||||
//shulker.renderYawOffset = 0;
|
shulker.prevHeadYaw = 0;
|
||||||
//shulker.prevRenderYawOffset = 0;
|
shulker.headYaw = 0;
|
||||||
|
shulker.prevBodyYaw = 0;
|
||||||
|
shulker.bodyYaw = 0;
|
||||||
|
|
||||||
shulker.setAttachedBlock(null);
|
shulker.setAttachedBlock(null);
|
||||||
|
|
||||||
if (source.isClient() && source instanceof Pony) {
|
if (source.isClient() && source instanceof Pony) {
|
||||||
Pony player = (Pony)source;
|
//Pony player = (Pony)source;
|
||||||
|
|
||||||
|
|
||||||
float peekAmount = 0.3F;
|
float peekAmount = 30;
|
||||||
|
|
||||||
if (!owner.isSneaking()) {
|
//if (!owner.isSneaking()) {
|
||||||
double speed = Math.sqrt(Entity.squaredHorizontalLength(owner.getVelocity()));
|
//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);
|
shulker.setPeekAmount((int)peekAmount);
|
||||||
}
|
}
|
||||||
|
@ -488,6 +510,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachedMagicEffect,
|
||||||
|| entity instanceof EnderDragonEntity
|
|| entity instanceof EnderDragonEntity
|
||||||
|| entity instanceof VexEntity
|
|| entity instanceof VexEntity
|
||||||
|| entity instanceof ShulkerBulletEntity
|
|| entity instanceof ShulkerBulletEntity
|
||||||
|
|| entity instanceof Flutterer
|
||||||
|| ProjectileUtil.isProjectile(entity);
|
|| ProjectileUtil.isProjectile(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ abstract class MixinLivingEntity extends Entity implements PonyContainer<Ponylik
|
||||||
return caster;
|
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) {
|
private void onCanSee(Entity other, CallbackInfoReturnable<Boolean> info) {
|
||||||
if (get().isInvisible()) {
|
if (get().isInvisible()) {
|
||||||
info.setReturnValue(false);
|
info.setReturnValue(false);
|
||||||
|
|
|
@ -7,20 +7,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.magic.spell.DisguiseSpell;
|
import com.minelittlepony.unicopia.magic.spell.DisguiseSpell;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
@Mixin(EntityRenderDispatcher.class)
|
@Mixin(EntityRenderDispatcher.class)
|
||||||
abstract class MixinEntityRenderDispatcher {
|
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";
|
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) {
|
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)) {
|
if (!(entity instanceof PlayerEntity)) {
|
||||||
return;
|
return;
|
||||||
|
@ -29,29 +32,40 @@ abstract class MixinEntityRenderDispatcher {
|
||||||
Pony pony = Pony.of((PlayerEntity)entity);
|
Pony pony = Pony.of((PlayerEntity)entity);
|
||||||
|
|
||||||
if (pony.getGravity().getGravitationConstant() < 0) {
|
if (pony.getGravity().getGravitationConstant() < 0) {
|
||||||
|
matrices.push();
|
||||||
matrices.translate(0, entity.getDimensions(entity.getPose()).height, 0);
|
matrices.translate(0, entity.getDimensions(entity.getPose()).height, 0);
|
||||||
matrices.scale(1, -1, 1);
|
matrices.scale(1, -1, 1);
|
||||||
entity.prevPitch *= -1;
|
entity.prevPitch *= -1;
|
||||||
entity.pitch *= -1;
|
entity.pitch *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisguiseSpell effect = pony.getEffect(DisguiseSpell.class, false);
|
DisguiseSpell effect = pony.getEffect(DisguiseSpell.class, true);
|
||||||
|
|
||||||
if (effect == null || effect.isDead()) {
|
if (effect == null || effect.isDead()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
effect.update(pony, false);
|
||||||
|
|
||||||
Entity e = effect.getDisguise();
|
Entity e = effect.getDisguise();
|
||||||
|
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
info.cancel();
|
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"))
|
@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) {
|
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)) {
|
if (!(entity instanceof PlayerEntity)) {
|
||||||
return;
|
return;
|
||||||
|
@ -60,6 +74,7 @@ abstract class MixinEntityRenderDispatcher {
|
||||||
Pony pony = Pony.of((PlayerEntity)entity);
|
Pony pony = Pony.of((PlayerEntity)entity);
|
||||||
|
|
||||||
if (pony.getGravity().getGravitationConstant() < 0) {
|
if (pony.getGravity().getGravitationConstant() < 0) {
|
||||||
|
matrices.pop();
|
||||||
entity.prevPitch *= -1;
|
entity.prevPitch *= -1;
|
||||||
entity.pitch *= -1;
|
entity.pitch *= -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue