Fixed player skins, fixed disguises rendering at the observer's location, fixed players not being persisted correctly

This commit is contained in:
Sollace 2019-02-12 11:32:36 +02:00
parent dcb10f81b8
commit 3f0805b1d8
4 changed files with 101 additions and 102 deletions

View file

@ -183,15 +183,6 @@ public class UnicopiaClient extends UClient {
if (iplayer.isInvisible()) { if (iplayer.isInvisible()) {
event.setCanceled(true); 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()) { if (iplayer.hasEffect()) {
@ -203,14 +194,6 @@ public class UnicopiaClient extends UClient {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@SubscribeEvent @SubscribeEvent
public static void postEntityRender(RenderLivingEvent.Post<?> event) { 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. // This fixes lighting errors on the armour slots.
// #MahjongPls // #MahjongPls
// @FUF(reason = "Forge should fix this. Cancelling their event skips neccessary state resetting at the end of the render method") // @FUF(reason = "Forge should fix this. Cancelling their event skips neccessary state resetting at the end of the render method")

View file

@ -6,7 +6,9 @@ import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.player.IOwned; import com.minelittlepony.unicopia.player.IOwned;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -15,23 +17,25 @@ import net.minecraft.world.World;
public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned<EntityPlayer> { public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned<EntityPlayer> {
private final GameProfile profile;
private NetworkPlayerInfo playerInfo; private NetworkPlayerInfo playerInfo;
private EntityPlayer owner; private EntityPlayer owner;
public EntityFakeClientPlayer(World world, GameProfile profile) { public EntityFakeClientPlayer(World world, GameProfile profile) {
super(world, profile); super(world, profile);
this.profile = profile;
} }
@Override @Override
@Nullable @Nullable
protected NetworkPlayerInfo getPlayerInfo() { protected NetworkPlayerInfo getPlayerInfo() {
if (playerInfo == null) { 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; return playerInfo;

View file

@ -26,17 +26,8 @@ public class DisguiseRenderer {
if (entity.getEntityData().hasKey("disguise") && entity.getEntityData().getBoolean("disguise")) { if (entity.getEntityData().hasKey("disguise") && entity.getEntityData().getBoolean("disguise")) {
entity.getEntityData().setBoolean("disguise", false); entity.getEntityData().setBoolean("disguise", false);
renderMan.setRenderShadow(true); renderMan.setRenderShadow(!isAttachedEntity(entity));
renderDisguise(renderMan, entity);
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(false); renderMan.setRenderShadow(false);
entity.getEntityData().setBoolean("disguise", true); entity.getEntityData().setBoolean("disguise", true);
@ -49,6 +40,21 @@ public class DisguiseRenderer {
return false; 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) { public boolean renderDisguiseToGui(IPlayer player) {
IMagicEffect effect = player.getEffect(false); IMagicEffect effect = player.getEffect(false);

View file

@ -28,6 +28,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntitySkull;
public class SpellDisguise extends AbstractSpell implements IFlyingPredicate { public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
@ -69,58 +70,76 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
entity = null; entity = null;
} }
this.entityNbt = null; this.entityNbt = null;
if (this.entity != null) {
this.entity.setDead();
}
this.entity = null;
this.entityId = ""; this.entityId = "";
if (entity != null) { removeDisguise();
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);
}
if (entity != null) {
entityNbt = encodeEntityToNBT(entity);
entityId = entityNbt.getString("id");
} }
return this; return this;
} }
@SuppressWarnings("unchecked") protected void removeDisguise() {
@Override if (entity != null) {
public boolean update(ICaster<?> source) { entity.setDead();
if (entity == null && entityNbt != null) { entity = null;
if ("player".equals(entityId)) { }
}
GameProfile profile = new GameProfile( protected NBTTagCompound encodeEntityToNBT(Entity entity) {
entityNbt.getUniqueId("playerId"), NBTTagCompound entityNbt = new NBTTagCompound();
entityNbt.getString("playerName"));
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 = UClient.instance().createPlayer(source.getEntity(), profile);
entity.setCustomNameTag(source.getOwner().getName()); entity.setCustomNameTag(source.getOwner().getName());
((EntityPlayer)entity).readFromNBT(nbt.getCompoundTag("playerNbt"));
entity.setUniqueId(UUID.randomUUID()); entity.setUniqueId(UUID.randomUUID());
entity.readFromNBT(entityNbt.getCompoundTag("playerNbt"));
PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);; PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);
if (entity != null && source.getWorld().isRemote) { if (entity != null && source.getWorld().isRemote) {
source.getWorld().spawnEntity(entity); source.getWorld().spawnEntity(entity);
} }
}
protected void checkAndCreateDisguiseEntity(ICaster<?> source) {
if (entity == null && entityNbt != null) {
if ("player".equals(entityId)) {
NBTTagCompound nbt = entityNbt;
entityNbt = null; 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 { } 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) {
source.getWorld().spawnEntity(entity); source.getWorld().spawnEntity(entity);
@ -130,6 +149,11 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
} }
} }
@SuppressWarnings("unchecked")
@Override
public boolean update(ICaster<?> source) {
checkAndCreateDisguiseEntity(source);
EntityLivingBase owner = source.getOwner(); EntityLivingBase owner = source.getOwner();
if (owner == null) { if (owner == null) {
@ -139,7 +163,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
if (entity != null) { if (entity != null) {
entity.onGround = owner.onGround; entity.onGround = owner.onGround;
if (!(entity instanceof EntityFallingBlock)) { if (!(entity instanceof EntityFallingBlock || entity instanceof EntityPlayer)) {
entity.onUpdate(); entity.onUpdate();
} }
@ -209,15 +233,9 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
if (entity instanceof EntityShulker || entity instanceof EntityFallingBlock) { if (entity instanceof EntityShulker || entity instanceof EntityFallingBlock) {
if (entity instanceof EntityFallingBlock) {
entity.posX = Math.floor(owner.posX) + 0.5; entity.posX = Math.floor(owner.posX) + 0.5;
entity.posY = Math.floor(owner.posY); entity.posY = Math.floor(owner.posY + 0.2);
entity.posZ = Math.floor(owner.posZ) + 0.5; entity.posZ = Math.floor(owner.posZ) + 0.5;
} else {
entity.posX = owner.posX;
entity.posY = owner.posY;
entity.posZ = owner.posZ;
}
entity.lastTickPosX = entity.posX; entity.lastTickPosX = entity.posX;
entity.lastTickPosY = entity.posY; entity.lastTickPosY = entity.posY;
@ -314,11 +332,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
@Override @Override
public void setDead() { public void setDead() {
super.setDead(); super.setDead();
removeDisguise();
if (entity != null) {
entity.setDead();
entity = null;
}
} }
@Override @Override
@ -336,11 +350,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
if (entityNbt != null) { if (entityNbt != null) {
compound.setTag("entity", entityNbt); compound.setTag("entity", entityNbt);
} else if (entity != null) { } else if (entity != null) {
NBTTagCompound entityTag = new NBTTagCompound(); compound.setTag("entity", encodeEntityToNBT(entity));
entity.writeToNBT(entityTag);
entityTag.setString("id", entityId);
compound.setTag("entity", entityTag);
} }
} }
@ -352,11 +362,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
if (!newId.contentEquals(entityId)) { if (!newId.contentEquals(entityId)) {
entityNbt = null; entityNbt = null;
removeDisguise();
if (entity != null) {
entity.setDead();
entity = null;
}
} }
if (compound.hasKey("entity")) { if (compound.hasKey("entity")) {