diff --git a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java index 70c1fdb2..f43ea159 100644 --- a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java @@ -7,6 +7,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.jumpingcastle.api.Target; +import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer; import com.minelittlepony.unicopia.hud.UHud; import com.minelittlepony.unicopia.input.Keyboard; import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; @@ -22,10 +23,10 @@ import com.mojang.authlib.GameProfile; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiOptions; +import net.minecraft.client.gui.GuiShareToLan; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; @@ -110,10 +111,7 @@ public class UnicopiaClient extends UClient { @Nonnull public EntityPlayer createPlayer(Entity observer, GameProfile profile) { - if (!observer.world.isRemote) { - return super.createPlayer(observer, profile); - } - return new EntityOtherPlayerMP(observer.world, profile); + return new EntityFakeClientPlayer(observer.world, profile); } @Override @@ -137,7 +135,7 @@ public class UnicopiaClient extends UClient { @SideOnly(Side.CLIENT) @SubscribeEvent public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) { - if (event.getGui() instanceof GuiOptions) { + if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) { addUniButton(event); } } @@ -198,24 +196,28 @@ public class UnicopiaClient extends UClient { if (iplayer.hasEffect()) { RenderManager renderMan = Minecraft.getMinecraft().getRenderManager(); - IMagicEffect effect = iplayer.getEffect(); + IMagicEffect effect = iplayer.getEffect(false); if (!effect.getDead() && effect instanceof SpellDisguise) { - Entity e = ((SpellDisguise)effect).getDisguise(); if (renderMan.isRenderShadow() && !(e instanceof EntityPlayer)) { return; } - effect.update(iplayer); - - - // Check for a disguise and render it in our place. if (e != null) { e.setInvisible(false); - renderMan.renderEntity(e, 0, 0, 0, 0, 1, false); + + float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks(); + + if (renderMan.isRenderShadow()) { + renderMan.renderEntityStatic(e, partialTicks, false); + } else { + e.setAlwaysRenderNameTag(false); + effect.update(iplayer); + renderMan.renderEntity(e, 0, 0, 0, 0, 1, false); + } } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java new file mode 100644 index 00000000..54752e27 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java @@ -0,0 +1,77 @@ +package com.minelittlepony.unicopia.entity; + +import java.util.UUID; + +import javax.annotation.Nullable; + +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.NetworkPlayerInfo; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.World; + +public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned { + + private final GameProfile profile; + + private NetworkPlayerInfo playerInfo; + + private UUID owner; + + public EntityFakeClientPlayer(World world, GameProfile profile) { + super(world, profile); + + this.profile = profile; + } + + @Nullable + protected NetworkPlayerInfo getPlayerInfo() { + if (playerInfo == null) { + playerInfo = new NetworkPlayerInfo(profile); + } + + return playerInfo; + } + + @Override + public boolean isPlayer() { + return false; + } + + @Override + protected void playEquipSound(ItemStack stack) { + /*noop*/ + } + + @Override + public boolean isUser() { + return false; + } + + @Override + public boolean getAlwaysRenderNameTagForRender() { + return !(Minecraft.getMinecraft().player != null + && Minecraft.getMinecraft().player.getGameProfile().getId().equals(getOwner())); + } + + @Override + public UUID getOwner() { + return owner; + } + + @Override + public void setOwner(UUID owner) { + this.owner = owner; + } + + @Override + public ITextComponent getDisplayName() { + ITextComponent name = super.getDisplayName(); + name.getStyle().setItalic(true); + return name; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpell.java b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpell.java index 8fcb51d4..b5cc37d3 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpell.java @@ -91,8 +91,8 @@ public class EntitySpell extends EntityLiving implements IMagicals, ICaster { return effect != null; } - public IMagicEffect get() { + public IMagicEffect get(boolean update) { + if (!update) { + return effect; + } + NBTTagCompound comp = owned.getEntity().getDataManager().get(param); if (comp == null || !comp.hasKey("effect_id")) { diff --git a/src/main/java/com/minelittlepony/unicopia/player/IOwned.java b/src/main/java/com/minelittlepony/unicopia/player/IOwned.java index a43fc034..d5984890 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/IOwned.java +++ b/src/main/java/com/minelittlepony/unicopia/player/IOwned.java @@ -2,10 +2,13 @@ package com.minelittlepony.unicopia.player; public interface IOwned { - default void setOwner(E owner) { - - } + void setOwner(E owner); E getOwner(); + + @SuppressWarnings("unchecked") + static IOwned cast(Object o) { + return (IOwned)o; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java index c3d34345..0792b16e 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java @@ -351,8 +351,8 @@ class PlayerCapabilities implements IPlayer { @Nullable @Override - public IMagicEffect getEffect() { - return effectDelegate.get(); + public IMagicEffect getEffect(boolean update) { + return effectDelegate.get(update); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java b/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java index e84d317f..fc24a6bc 100644 --- a/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java @@ -1,9 +1,12 @@ package com.minelittlepony.unicopia.power; +import java.util.UUID; + import javax.annotation.Nullable; import org.lwjgl.input.Keyboard; +import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -11,6 +14,7 @@ import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.SpellDisguise; import com.minelittlepony.util.vector.VecHelper; +import com.mojang.authlib.GameProfile; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/com/minelittlepony/unicopia/spell/ICaster.java b/src/main/java/com/minelittlepony/unicopia/spell/ICaster.java index 712b99ef..b6651ba9 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/ICaster.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/ICaster.java @@ -23,7 +23,12 @@ public interface ICaster extends IOwned, ILevelle void setEffect(@Nullable IMagicEffect effect); @Nullable - IMagicEffect getEffect(); + IMagicEffect getEffect(boolean update); + + @Nullable + default IMagicEffect getEffect() { + return getEffect(true); + } boolean hasEffect(); diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java index 4020df8b..310dae36 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java @@ -7,6 +7,7 @@ import javax.annotation.Nullable; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.player.IOwned; import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.mojang.authlib.GameProfile; @@ -17,6 +18,7 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; public class SpellDisguise extends AbstractSpell { @@ -87,6 +89,7 @@ public class SpellDisguise extends AbstractSpell { return this; } + @SuppressWarnings("unchecked") @Override public boolean update(ICaster source) { if (entity == null && entityNbt != null) { @@ -97,6 +100,7 @@ public class SpellDisguise extends AbstractSpell { 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);; @@ -121,10 +125,27 @@ public class SpellDisguise extends AbstractSpell { entity.onGround = owner.onGround; entity.onUpdate(); - if (entity instanceof EntityLiving) { - EntityLiving l = (EntityLiving)entity; + entity.copyLocationAndAnglesFrom(owner); - l.setNoAI(true); + entity.setNoGravity(true); + + entity.prevPosX = owner.prevPosX; + entity.prevPosY = owner.prevPosY; + entity.prevPosZ = owner.prevPosZ; + + entity.motionX = owner.motionX; + entity.motionY = owner.motionY; + entity.motionZ = owner.motionZ; + + entity.prevRotationPitch = owner.prevRotationPitch; + entity.prevRotationYaw = owner.prevRotationYaw; + + entity.distanceWalkedOnStepModified = owner.distanceWalkedOnStepModified; + entity.distanceWalkedModified = owner.distanceWalkedModified; + entity.prevDistanceWalkedModified = owner.prevDistanceWalkedModified; + + if (entity instanceof EntityLivingBase) { + EntityLivingBase l = (EntityLivingBase)entity; l.rotationYawHead = owner.rotationYawHead; l.prevRotationYawHead = owner.prevRotationYawHead; @@ -145,32 +166,27 @@ public class SpellDisguise extends AbstractSpell { l.setHealth(owner.getHealth()); for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) { - l.setItemStackToSlot(i, owner.getItemStackFromSlot(i)); + ItemStack neu = owner.getItemStackFromSlot(i); + ItemStack old = l.getItemStackFromSlot(i); + if (old != neu) { + l.setItemStackToSlot(i, neu); + } } } - if (owner.world.isRemote) { - // entity.setPositionAndRotationDirect(owner.posX, owner.posY, owner.posZ, owner.rotationYaw, owner.rotationPitch, 1, false); + if (entity instanceof EntityLiving) { + EntityLiving l = (EntityLiving)entity; + + l.setNoAI(true); } - entity.copyLocationAndAnglesFrom(owner); + if (entity instanceof EntityPlayer) { + EntityPlayer l = (EntityPlayer)entity; - entity.setNoGravity(true); - - entity.prevPosX = owner.prevPosX; - entity.prevPosY = owner.prevPosY; - entity.prevPosZ = owner.prevPosZ; - - entity.motionX = owner.motionX; - entity.motionY = owner.motionY; - entity.motionZ = owner.motionZ; - - entity.prevRotationPitch = owner.prevRotationPitch; - entity.prevRotationYaw = owner.prevRotationYaw; - - entity.distanceWalkedOnStepModified = owner.distanceWalkedOnStepModified; - entity.distanceWalkedModified = owner.distanceWalkedModified; - entity.prevDistanceWalkedModified = owner.prevDistanceWalkedModified; + l.chasingPosX = l.posX; + l.chasingPosY = l.posY; + l.chasingPosZ = l.posZ; + } if (owner.isBurning()) { entity.setFire(1); @@ -195,6 +211,10 @@ public class SpellDisguise extends AbstractSpell { player.eyeHeight = entity.getEyeHeight(); + if (entity instanceof IOwned) { + IOwned.cast(entity).setOwner(player.getGameProfile().getId()); + } + if (UClient.instance().isClientPlayer(player)) { entity.setAlwaysRenderNameTag(false); entity.setCustomNameTag("");