diff --git a/src/main/java/com/minelittlepony/unicopia/UClient.java b/src/main/java/com/minelittlepony/unicopia/UClient.java index 1a472359..5dda06f3 100644 --- a/src/main/java/com/minelittlepony/unicopia/UClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UClient.java @@ -2,12 +2,17 @@ package com.minelittlepony.unicopia; import java.util.UUID; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.unicopia.forgebullshit.FUF; +import com.mojang.authlib.GameProfile; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.IInteractionObject; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; @@ -60,6 +65,16 @@ public class UClient { return 0; } + /** + * Side-independent method to create a new player. + * + * Returns an implementation of EntityPlayer appropriate to the side being called on. + */ + @Nonnull + public EntityPlayer createPlayer(Entity observer, GameProfile profile) { + return new FakePlayer((WorldServer)observer.world, profile); + } + public void preInit(FMLPreInitializationEvent event) {} public void init(FMLInitializationEvent event) {} diff --git a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java index ce2363ae..70c1fdb2 100644 --- a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia; import java.util.List; import java.util.UUID; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.jumpingcastle.api.Target; @@ -17,9 +18,11 @@ import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.SpellDisguise; import com.minelittlepony.util.gui.ButtonGridLayout; import com.minelittlepony.util.gui.UButton; +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; @@ -105,6 +108,14 @@ public class UnicopiaClient extends UClient { return mc.world.getPlayerEntityByUUID(playerId); } + @Nonnull + public EntityPlayer createPlayer(Entity observer, GameProfile profile) { + if (!observer.world.isRemote) { + return super.createPlayer(observer, profile); + } + return new EntityOtherPlayerMP(observer.world, profile); + } + @Override public boolean isClientPlayer(@Nullable EntityPlayer player) { if (getPlayer() == player) { @@ -166,6 +177,14 @@ public class UnicopiaClient extends UClient { public static void preEntityRender(RenderLivingEvent.Pre event) { if (event.getEntity() instanceof EntityPlayer) { IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)event.getEntity()); + System.out.println(event.getEntity().getName()); + + if (!MineLP.modIsActive()) { + 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.isInvisible()) { event.setCanceled(true); @@ -179,17 +198,20 @@ public class UnicopiaClient extends UClient { if (iplayer.hasEffect()) { RenderManager renderMan = Minecraft.getMinecraft().getRenderManager(); - if (renderMan.isRenderShadow()) { - return; - } - - // I assume we're in the inventory now. IMagicEffect effect = iplayer.getEffect(); + if (!effect.getDead() && effect instanceof SpellDisguise) { - effect.update(iplayer); 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); diff --git a/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java b/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java index 80a7c063..e84d317f 100644 --- a/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/power/PowerDisguise.java @@ -6,6 +6,7 @@ import org.lwjgl.input.Keyboard; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.SpellDisguise; @@ -39,6 +40,17 @@ public class PowerDisguise extends PowerFeed { EntityPlayer player = iplayer.getOwner(); Entity looked = VecHelper.getLookedAtEntity(player, 17); + if (looked instanceof EntityPlayer) { + IPlayer ilooked = PlayerSpeciesList.instance().getPlayer((EntityPlayer)looked); + IMagicEffect ef = ilooked.getEffect(); + if (ef instanceof SpellDisguise && !ef.getDead()) { + Entity e = ((SpellDisguise)ef).getDisguise(); + if (e != null) { + looked = e; + } + } + } + player.world.playSound(null, player.getPosition(), SoundEvents.E_PARROT_IM_POLAR_BEAR, SoundCategory.PLAYERS, 1.4F, 0.4F); IMagicEffect effect = iplayer.getEffect(); diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java index ef6346d7..4020df8b 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellDisguise.java @@ -1,11 +1,15 @@ package com.minelittlepony.unicopia.spell; +import java.util.UUID; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; +import com.mojang.authlib.GameProfile; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -65,9 +69,19 @@ public class SpellDisguise extends AbstractSpell { this.entityId = ""; if (entity != null) { - this.entityId = EntityList.getKey(entity).toString(); - this.entityNbt = entity.writeToNBT(new NBTTagCompound()); - this.entityNbt.setString("id", entityId); + 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); + } + } return this; @@ -76,13 +90,25 @@ public class SpellDisguise extends AbstractSpell { @Override public boolean update(ICaster source) { if (entity == null && entityNbt != null) { - entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld()); + if ("player".equals(entityId)) { - if (entity != null && source.getWorld().isRemote) { - source.getWorld().spawnEntity(entity); + GameProfile profile = new GameProfile( + entityNbt.getUniqueId("playerId"), + entityNbt.getString("playerName")); + + entity = UClient.instance().createPlayer(source.getEntity(), profile); + entity.setUniqueId(UUID.randomUUID()); + entity.readFromNBT(entityNbt.getCompoundTag("playerNbt")); + PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);; + } else { + entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld()); + + if (entity != null && source.getWorld().isRemote) { + source.getWorld().spawnEntity(entity); + } + + entityNbt = null; } - - entityNbt = null; } EntityLivingBase owner = source.getOwner(); @@ -123,6 +149,9 @@ public class SpellDisguise extends AbstractSpell { } } + if (owner.world.isRemote) { + // entity.setPositionAndRotationDirect(owner.posX, owner.posY, owner.posZ, owner.rotationYaw, owner.rotationPitch, 1, false); + } entity.copyLocationAndAnglesFrom(owner);