mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 23:27:59 +01:00
Added preliminary support for changelings disguised as players
This commit is contained in:
parent
0d837f89da
commit
10ed8fe920
4 changed files with 92 additions and 14 deletions
|
@ -2,12 +2,17 @@ package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.forgebullshit.FUF;
|
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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.world.IInteractionObject;
|
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.FMLCommonHandler;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
@ -60,6 +65,16 @@ public class UClient {
|
||||||
return 0;
|
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 preInit(FMLPreInitializationEvent event) {}
|
||||||
|
|
||||||
public void init(FMLInitializationEvent event) {}
|
public void init(FMLInitializationEvent event) {}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.jumpingcastle.api.Target;
|
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.unicopia.spell.SpellDisguise;
|
||||||
import com.minelittlepony.util.gui.ButtonGridLayout;
|
import com.minelittlepony.util.gui.ButtonGridLayout;
|
||||||
import com.minelittlepony.util.gui.UButton;
|
import com.minelittlepony.util.gui.UButton;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
import net.minecraft.client.entity.EntityOtherPlayerMP;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiOptions;
|
import net.minecraft.client.gui.GuiOptions;
|
||||||
|
@ -105,6 +108,14 @@ public class UnicopiaClient extends UClient {
|
||||||
return mc.world.getPlayerEntityByUUID(playerId);
|
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
|
@Override
|
||||||
public boolean isClientPlayer(@Nullable EntityPlayer player) {
|
public boolean isClientPlayer(@Nullable EntityPlayer player) {
|
||||||
if (getPlayer() == player) {
|
if (getPlayer() == player) {
|
||||||
|
@ -166,6 +177,14 @@ public class UnicopiaClient extends UClient {
|
||||||
public static void preEntityRender(RenderLivingEvent.Pre<?> event) {
|
public static void preEntityRender(RenderLivingEvent.Pre<?> event) {
|
||||||
if (event.getEntity() instanceof EntityPlayer) {
|
if (event.getEntity() instanceof EntityPlayer) {
|
||||||
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)event.getEntity());
|
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()) {
|
if (iplayer.isInvisible()) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
|
@ -179,16 +198,19 @@ public class UnicopiaClient extends UClient {
|
||||||
if (iplayer.hasEffect()) {
|
if (iplayer.hasEffect()) {
|
||||||
RenderManager renderMan = Minecraft.getMinecraft().getRenderManager();
|
RenderManager renderMan = Minecraft.getMinecraft().getRenderManager();
|
||||||
|
|
||||||
if (renderMan.isRenderShadow()) {
|
IMagicEffect effect = iplayer.getEffect();
|
||||||
|
|
||||||
|
if (!effect.getDead() && effect instanceof SpellDisguise) {
|
||||||
|
|
||||||
|
Entity e = ((SpellDisguise)effect).getDisguise();
|
||||||
|
|
||||||
|
if (renderMan.isRenderShadow() && !(e instanceof EntityPlayer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// I assume we're in the inventory now.
|
|
||||||
IMagicEffect effect = iplayer.getEffect();
|
|
||||||
if (!effect.getDead() && effect instanceof SpellDisguise) {
|
|
||||||
effect.update(iplayer);
|
effect.update(iplayer);
|
||||||
|
|
||||||
Entity e = ((SpellDisguise)effect).getDisguise();
|
|
||||||
|
|
||||||
// Check for a disguise and render it in our place.
|
// Check for a disguise and render it in our place.
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.UParticles;
|
import com.minelittlepony.unicopia.UParticles;
|
||||||
import com.minelittlepony.unicopia.player.IPlayer;
|
import com.minelittlepony.unicopia.player.IPlayer;
|
||||||
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||||
import com.minelittlepony.unicopia.power.data.Hit;
|
import com.minelittlepony.unicopia.power.data.Hit;
|
||||||
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
import com.minelittlepony.unicopia.spell.SpellDisguise;
|
import com.minelittlepony.unicopia.spell.SpellDisguise;
|
||||||
|
@ -39,6 +40,17 @@ public class PowerDisguise extends PowerFeed {
|
||||||
EntityPlayer player = iplayer.getOwner();
|
EntityPlayer player = iplayer.getOwner();
|
||||||
Entity looked = VecHelper.getLookedAtEntity(player, 17);
|
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);
|
player.world.playSound(null, player.getPosition(), SoundEvents.E_PARROT_IM_POLAR_BEAR, SoundCategory.PLAYERS, 1.4F, 0.4F);
|
||||||
|
|
||||||
IMagicEffect effect = iplayer.getEffect();
|
IMagicEffect effect = iplayer.getEffect();
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package com.minelittlepony.unicopia.spell;
|
package com.minelittlepony.unicopia.spell;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.UClient;
|
import com.minelittlepony.unicopia.UClient;
|
||||||
import com.minelittlepony.unicopia.player.IPlayer;
|
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.Entity;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
|
@ -65,17 +69,38 @@ public class SpellDisguise extends AbstractSpell {
|
||||||
this.entityId = "";
|
this.entityId = "";
|
||||||
|
|
||||||
if (entity != null) {
|
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.entityId = EntityList.getKey(entity).toString();
|
||||||
this.entityNbt = entity.writeToNBT(new NBTTagCompound());
|
this.entityNbt = entity.writeToNBT(new NBTTagCompound());
|
||||||
this.entityNbt.setString("id", entityId);
|
this.entityNbt.setString("id", entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(ICaster<?> source) {
|
public boolean update(ICaster<?> source) {
|
||||||
if (entity == null && entityNbt != null) {
|
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.setUniqueId(UUID.randomUUID());
|
||||||
|
entity.readFromNBT(entityNbt.getCompoundTag("playerNbt"));
|
||||||
|
PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);;
|
||||||
|
} else {
|
||||||
entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld());
|
entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld());
|
||||||
|
|
||||||
if (entity != null && source.getWorld().isRemote) {
|
if (entity != null && source.getWorld().isRemote) {
|
||||||
|
@ -84,6 +109,7 @@ public class SpellDisguise extends AbstractSpell {
|
||||||
|
|
||||||
entityNbt = null;
|
entityNbt = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EntityLivingBase owner = source.getOwner();
|
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);
|
entity.copyLocationAndAnglesFrom(owner);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue