diff --git a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java index 8f8b405f..9f63a73a 100644 --- a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java @@ -183,15 +183,6 @@ public class UnicopiaClient extends UClient { if (iplayer.isInvisible()) { event.setCanceled(true); - } else { - GlStateManager.pushMatrix(); - - if (!MineLP.modIsActive() && !entity.onGround) { - float roll = iplayer.getCamera().calculateRoll(); - float pitch = iplayer.getCamera().calculatePitch(0); - GlStateManager.rotate(roll, 0, 0, 1); - GlStateManager.rotate(pitch, 1, 0, 0); - } } if (iplayer.hasEffect()) { @@ -203,14 +194,6 @@ public class UnicopiaClient extends UClient { @SideOnly(Side.CLIENT) @SubscribeEvent public static void postEntityRender(RenderLivingEvent.Post event) { - Entity entity = event.getEntity(); - - if (entity instanceof EntityPlayer) { - GlStateManager.popMatrix(); - - - } - // This fixes lighting errors on the armour slots. // #MahjongPls // @FUF(reason = "Forge should fix this. Cancelling their event skips neccessary state resetting at the end of the render method") diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java index b8a4bcbf..8ef1be07 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java @@ -6,7 +6,9 @@ import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.player.IOwned; import com.mojang.authlib.GameProfile; +import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -15,23 +17,25 @@ import net.minecraft.world.World; public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned { - private final GameProfile profile; - private NetworkPlayerInfo playerInfo; private EntityPlayer owner; public EntityFakeClientPlayer(World world, GameProfile profile) { super(world, profile); - - this.profile = profile; } @Override @Nullable protected NetworkPlayerInfo getPlayerInfo() { if (playerInfo == null) { - playerInfo = new NetworkPlayerInfo(profile); + NetHandlerPlayClient connection = Minecraft.getMinecraft().getConnection(); + + playerInfo = connection.getPlayerInfo(getGameProfile().getId()); + + if (playerInfo == null) { + playerInfo = new NetworkPlayerInfo(getGameProfile()); + } } return playerInfo; diff --git a/src/main/java/com/minelittlepony/unicopia/render/DisguiseRenderer.java b/src/main/java/com/minelittlepony/unicopia/render/DisguiseRenderer.java index 1245efc3..b1c41edd 100644 --- a/src/main/java/com/minelittlepony/unicopia/render/DisguiseRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/render/DisguiseRenderer.java @@ -26,17 +26,8 @@ public class DisguiseRenderer { if (entity.getEntityData().hasKey("disguise") && entity.getEntityData().getBoolean("disguise")) { entity.getEntityData().setBoolean("disguise", false); - renderMan.setRenderShadow(true); - - if (isAttachedEntity(entity)) { - double blockMoveX = entity.posX - Math.round(entity.posX - 0.5F); - double blockMoveY = entity.posY - Math.round(entity.posY); - double blockMoveZ = entity.posZ - Math.round(entity.posZ - 0.5F); - - renderMan.renderEntity(entity, -blockMoveX + 0.5, -blockMoveY, -blockMoveZ + 0.5, 0, 1, false); - } else { - renderMan.renderEntity(entity, 0, 0, 0, 0, 1, false); - } + renderMan.setRenderShadow(!isAttachedEntity(entity)); + renderDisguise(renderMan, entity); renderMan.setRenderShadow(false); entity.getEntityData().setBoolean("disguise", true); @@ -49,6 +40,21 @@ public class DisguiseRenderer { return false; } + protected void renderDisguise(RenderManager renderMan, Entity entity) { + + Entity observer = Minecraft.getMinecraft().getRenderViewEntity(); + + double x = entity.posX - observer.posX; + double y = entity.posY - observer.posY; + double z = entity.posZ - observer.posZ; + + renderMan.renderEntity(entity, x, y, z, 0, 0, false); + } + + protected void renderDisguiseFixedToBlock(RenderManager renderMan, Entity entity) { + + } + public boolean renderDisguiseToGui(IPlayer player) { IMagicEffect effect = player.getEffect(false); diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java index 99f6670e..f93060e5 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java @@ -28,6 +28,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntitySkull; public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { @@ -69,66 +70,89 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { entity = null; } this.entityNbt = null; - - if (this.entity != null) { - this.entity.setDead(); - } - - this.entity = null; - this.entityId = ""; - if (entity != null) { - if (entity instanceof EntityPlayer) { - GameProfile profile = ((EntityPlayer)entity).getGameProfile(); - this.entityId = "player"; - this.entityNbt = new NBTTagCompound(); - this.entityNbt.setUniqueId("playerId", profile.getId()); - this.entityNbt.setString("playerName", profile.getName()); - this.entityNbt.setTag("playerNbt", entity.writeToNBT(new NBTTagCompound())); - } else { - this.entityId = EntityList.getKey(entity).toString(); - this.entityNbt = entity.writeToNBT(new NBTTagCompound()); - this.entityNbt.setString("id", entityId); - } + removeDisguise(); + if (entity != null) { + entityNbt = encodeEntityToNBT(entity); + entityId = entityNbt.getString("id"); } return this; } - @SuppressWarnings("unchecked") - @Override - public boolean update(ICaster source) { + protected void removeDisguise() { + if (entity != null) { + entity.setDead(); + entity = null; + } + } + + protected NBTTagCompound encodeEntityToNBT(Entity entity) { + NBTTagCompound entityNbt = new NBTTagCompound(); + + if (entity instanceof EntityPlayer) { + GameProfile profile = ((EntityPlayer)entity).getGameProfile(); + + entityNbt.setString("id", "player"); + entityNbt.setUniqueId("playerId", profile.getId()); + entityNbt.setString("playerName", profile.getName()); + entityNbt.setTag("playerNbt", entity.writeToNBT(new NBTTagCompound())); + } else { + entityNbt = entity.writeToNBT(entityNbt); + entityNbt.setString("id", EntityList.getKey(entity).toString()); + } + + return entityNbt; + } + + protected synchronized void createPlayer(NBTTagCompound nbt, GameProfile profile, ICaster source) { + removeDisguise(); + + entity = UClient.instance().createPlayer(source.getEntity(), profile); + entity.setCustomNameTag(source.getOwner().getName()); + ((EntityPlayer)entity).readFromNBT(nbt.getCompoundTag("playerNbt")); + entity.setUniqueId(UUID.randomUUID()); + + PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null); + + if (entity != null && source.getWorld().isRemote) { + source.getWorld().spawnEntity(entity); + } + } + + protected void checkAndCreateDisguiseEntity(ICaster source) { if (entity == null && entityNbt != null) { if ("player".equals(entityId)) { - GameProfile profile = new GameProfile( - entityNbt.getUniqueId("playerId"), - entityNbt.getString("playerName")); - - entity = UClient.instance().createPlayer(source.getEntity(), profile); - entity.setCustomNameTag(source.getOwner().getName()); - entity.setUniqueId(UUID.randomUUID()); - entity.readFromNBT(entityNbt.getCompoundTag("playerNbt")); - - PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);; - - if (entity != null && source.getWorld().isRemote) { - source.getWorld().spawnEntity(entity); - } - + NBTTagCompound nbt = entityNbt; entityNbt = null; + + createPlayer(nbt, new GameProfile( + nbt.getUniqueId("playerId"), + nbt.getString("playerName") + ), source); + new Thread(() -> createPlayer(nbt, TileEntitySkull.updateGameProfile(new GameProfile( + null, + nbt.getString("playerName") + )), source)).start(); } else { entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld()); - - if (entity != null && source.getWorld().isRemote) { - source.getWorld().spawnEntity(entity); - } - - entityNbt = null; } + + if (entity != null && source.getWorld().isRemote) { + source.getWorld().spawnEntity(entity); + } + + entityNbt = null; } + } + + @SuppressWarnings("unchecked") + @Override + public boolean update(ICaster source) { + checkAndCreateDisguiseEntity(source); EntityLivingBase owner = source.getOwner(); @@ -139,7 +163,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { if (entity != null) { entity.onGround = owner.onGround; - if (!(entity instanceof EntityFallingBlock)) { + if (!(entity instanceof EntityFallingBlock || entity instanceof EntityPlayer)) { entity.onUpdate(); } @@ -209,15 +233,9 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { if (entity instanceof EntityShulker || entity instanceof EntityFallingBlock) { - if (entity instanceof EntityFallingBlock) { - entity.posX = Math.floor(owner.posX) + 0.5; - entity.posY = Math.floor(owner.posY); - entity.posZ = Math.floor(owner.posZ) + 0.5; - } else { - entity.posX = owner.posX; - entity.posY = owner.posY; - entity.posZ = owner.posZ; - } + entity.posX = Math.floor(owner.posX) + 0.5; + entity.posY = Math.floor(owner.posY + 0.2); + entity.posZ = Math.floor(owner.posZ) + 0.5; entity.lastTickPosX = entity.posX; entity.lastTickPosY = entity.posY; @@ -314,11 +332,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { @Override public void setDead() { super.setDead(); - - if (entity != null) { - entity.setDead(); - entity = null; - } + removeDisguise(); } @Override @@ -336,11 +350,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { if (entityNbt != null) { compound.setTag("entity", entityNbt); } else if (entity != null) { - NBTTagCompound entityTag = new NBTTagCompound(); - entity.writeToNBT(entityTag); - entityTag.setString("id", entityId); - - compound.setTag("entity", entityTag); + compound.setTag("entity", encodeEntityToNBT(entity)); } } @@ -352,11 +362,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { if (!newId.contentEquals(entityId)) { entityNbt = null; - - if (entity != null) { - entity.setDead(); - entity = null; - } + removeDisguise(); } if (compound.hasKey("entity")) {