Now let's optimise this a bit. Fixes particle trails on shulker bullets

This commit is contained in:
Sollace 2019-02-12 17:57:41 +02:00
parent 64edc23f2e
commit 0ab3867b9d
2 changed files with 170 additions and 171 deletions

View file

@ -5,6 +5,11 @@ import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
/**
* Generic container for an entity that has a race.
*
* @param <T> The type of owner
*/
public interface IRaceContainer<T extends Entity> extends InbtSerialisable, IUpdatable<T> { public interface IRaceContainer<T extends Entity> extends InbtSerialisable, IUpdatable<T> {
Race getPlayerSpecies(); Race getPlayerSpecies();

View file

@ -14,7 +14,6 @@ import com.minelittlepony.unicopia.player.IOwned;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.IPlayerHeightPredicate; import com.minelittlepony.unicopia.player.IPlayerHeightPredicate;
import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.render.DisguiseRenderer;
import com.minelittlepony.util.ProjectileUtil; import com.minelittlepony.util.ProjectileUtil;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -35,6 +34,7 @@ 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; import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.math.MathHelper;
public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IPlayerHeightPredicate { public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IPlayerHeightPredicate {
@ -123,18 +123,15 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null); PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).setEffect(null);
if (entity != null && source.getWorld().isRemote) { onEntityLoaded(source);
source.getWorld().spawnEntity(entity);
}
} }
protected void checkAndCreateDisguiseEntity(ICaster<?> source) { protected void checkAndCreateDisguiseEntity(ICaster<?> source) {
if (entity == null && entityNbt != null) { if (entity == null && entityNbt != null) {
if ("player".equals(entityId)) {
NBTTagCompound nbt = entityNbt; NBTTagCompound nbt = entityNbt;
entityNbt = null; entityNbt = null;
if ("player".equals(entityId)) {
createPlayer(nbt, new GameProfile( createPlayer(nbt, new GameProfile(
nbt.getUniqueId("playerId"), nbt.getUniqueId("playerId"),
nbt.getString("playerName") nbt.getString("playerName")
@ -144,15 +141,114 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
nbt.getString("playerName") nbt.getString("playerName")
)), source)).start(); )), source)).start();
} else { } else {
entity = EntityList.createEntityFromNBT(entityNbt, source.getWorld()); entity = EntityList.createEntityFromNBT(nbt, source.getWorld());
} }
if (entity != null && source.getWorld().isRemote) { onEntityLoaded(source);
}
}
protected void onEntityLoaded(ICaster<?> source) {
if (entity == null) {
return;
}
if (source.getWorld().isRemote) {
source.getWorld().spawnEntity(entity); source.getWorld().spawnEntity(entity);
} }
entityNbt = null;
} }
protected void copyBaseAttributes(EntityLivingBase from, Entity to) {
// Set first because position calculations rely on it
to.onGround = from.onGround;
if (isAttachedEntity(entity)) {
to.posX = Math.floor(from.posX) + 0.5;
to.posY = Math.floor(from.posY);
to.posZ = Math.floor(from.posZ) + 0.5;
to.lastTickPosX = to.posX;
to.lastTickPosY = to.posY;
to.lastTickPosZ = to.posZ;
to.prevPosX = to.posX;
to.prevPosY = to.posY;
to.prevPosZ = to.posZ;
to.setPosition(to.posX, to.posY, to.posZ);
} else {
to.copyLocationAndAnglesFrom(from);
to.lastTickPosX = from.lastTickPosX;
to.lastTickPosY = from.lastTickPosY;
to.lastTickPosZ = from.lastTickPosZ;
to.prevPosX = from.prevPosX;
to.prevPosY = from.prevPosY;
to.prevPosZ = from.prevPosZ;
}
if (to instanceof EntityPlayer) {
EntityPlayer l = (EntityPlayer)to;
l.chasingPosX = l.posX;
l.chasingPosY = l.posY;
l.chasingPosZ = l.posZ;
}
to.motionX = from.motionX;
to.motionY = from.motionY;
to.motionZ = from.motionZ;
to.prevRotationPitch = from.prevRotationPitch;
to.prevRotationYaw = from.prevRotationYaw;
to.distanceWalkedOnStepModified = from.distanceWalkedOnStepModified;
to.distanceWalkedModified = from.distanceWalkedModified;
to.prevDistanceWalkedModified = from.prevDistanceWalkedModified;
if (to instanceof EntityLivingBase) {
EntityLivingBase l = (EntityLivingBase)to;
l.rotationYawHead = from.rotationYawHead;
l.prevRotationYawHead = from.prevRotationYawHead;
l.renderYawOffset = from.renderYawOffset;
l.prevRenderYawOffset = from.prevRenderYawOffset;
l.limbSwing = from.limbSwing;
l.limbSwingAmount = from.limbSwingAmount;
l.prevLimbSwingAmount = from.prevLimbSwingAmount;
l.swingingHand = from.swingingHand;
l.swingProgress = from.swingProgress;
l.swingProgressInt = from.swingProgressInt;
l.isSwingInProgress = from.isSwingInProgress;
l.hurtTime = from.hurtTime;
l.deathTime = from.deathTime;
l.setHealth(from.getHealth());
for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) {
ItemStack neu = from.getItemStackFromSlot(i);
ItemStack old = l.getItemStackFromSlot(i);
if (old != neu) {
l.setItemStackToSlot(i, neu);
}
}
}
if (to instanceof EntityTameable) {
((EntityTameable)to).setSitting(from.isSneaking());
}
if (from.isBurning()) {
to.setFire(1);
} else {
to.extinguish();
}
to.setSneaking(from.isSneaking());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -166,93 +262,40 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
return true; return true;
} }
if (entity != null) { if (entity == null) {
entity.onGround = owner.onGround; if (source instanceof IPlayer) {
owner.setInvisible(false);
if (!(entity instanceof EntityFallingBlock || entity instanceof EntityPlayer)) { ((IPlayer) source).setInvisible(false);
entity.onUpdate();
} }
entity.copyLocationAndAnglesFrom(owner); return false;
}
entity.setNoGravity(true); entity.noClip = true;
entity.updateBlocked = true;
entity.getEntityData().setBoolean("disguise", true); entity.getEntityData().setBoolean("disguise", true);
entity.lastTickPosX = owner.lastTickPosX; if (entity instanceof EntityLiving) {
entity.lastTickPosY = owner.lastTickPosY; ((EntityLiving)entity).setNoAI(true);
entity.lastTickPosZ = owner.lastTickPosZ;
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;
l.renderYawOffset = owner.renderYawOffset;
l.prevRenderYawOffset = owner.prevRenderYawOffset;
l.limbSwing = owner.limbSwing;
l.limbSwingAmount = owner.limbSwingAmount;
l.prevLimbSwingAmount = owner.prevLimbSwingAmount;
l.swingingHand = owner.swingingHand;
l.swingProgress = owner.swingProgress;
l.swingProgressInt = owner.swingProgressInt;
l.isSwingInProgress = owner.isSwingInProgress;
l.hurtTime = owner.hurtTime;
l.deathTime = owner.deathTime;
l.setHealth(owner.getHealth());
for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) {
ItemStack neu = owner.getItemStackFromSlot(i);
ItemStack old = l.getItemStackFromSlot(i);
if (old != neu) {
l.setItemStackToSlot(i, neu);
}
} }
if (l instanceof EntityShulker) { entity.setInvisible(false);
l.rotationYaw = 0; entity.setNoGravity(true);
l.renderYawOffset = 0; copyBaseAttributes(owner, entity);
l.prevRenderYawOffset = 0;
}
}
if (isAttachedEntity(entity)) { if (!skipsUpdate(entity)) {
entity.onUpdate();
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;
entity.lastTickPosZ = entity.posZ;
entity.prevPosX = entity.posX;
entity.prevPosY = entity.posY;
entity.prevPosZ = entity.posZ;
} }
if (entity instanceof EntityShulker) { if (entity instanceof EntityShulker) {
EntityShulker shulker = ((EntityShulker)entity); EntityShulker shulker = ((EntityShulker)entity);
shulker.rotationYaw = 0;
shulker.renderYawOffset = 0;
shulker.prevRenderYawOffset = 0;
shulker.setAttachmentPos(null); shulker.setAttachmentPos(null);
if (source.getWorld().isRemote && source instanceof IPlayer) { if (source.getWorld().isRemote && source instanceof IPlayer) {
@ -264,10 +307,7 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
if (!owner.isSneaking()) { if (!owner.isSneaking()) {
float speed = (float)Math.sqrt(Math.pow(owner.motionX, 2) + Math.pow(owner.motionZ, 2)); float speed = (float)Math.sqrt(Math.pow(owner.motionX, 2) + Math.pow(owner.motionZ, 2));
peekAmount = speed * 30; peekAmount = MathHelper.clamp(speed * 30, 0, 1);
if (peekAmount > 1) {
peekAmount = 1;
}
} }
peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5); peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);
@ -276,85 +316,34 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
} }
} }
if (entity instanceof EntityLiving) {
EntityLiving l = (EntityLiving)entity;
l.setNoAI(true);
}
if (entity instanceof EntityMinecart) { if (entity instanceof EntityMinecart) {
entity.rotationYaw += 90; entity.rotationYaw += 90;
entity.rotationPitch = 0; entity.rotationPitch = 0;
} }
if (entity instanceof EntityPlayer) {
EntityPlayer l = (EntityPlayer)entity;
l.chasingPosX = l.posX;
l.chasingPosY = l.posY;
l.chasingPosZ = l.posZ;
}
if (owner.isBurning()) {
entity.setFire(1);
} else {
entity.extinguish();
}
entity.noClip = true;
entity.updateBlocked = true;
entity.setSneaking(owner.isSneaking());
entity.setInvisible(false);
if (source instanceof IPlayer) { if (source instanceof IPlayer) {
((IPlayer) source).setInvisible(true); IPlayer player = (IPlayer)source;
}
owner.setInvisible(true); player.setInvisible(true);
source.getOwner().setInvisible(true);
if (entity instanceof EntityTameable) {
((EntityTameable)entity).setSitting(owner.isSneaking());
}
if (owner instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)owner;
if (entity instanceof IOwned) { if (entity instanceof IOwned) {
IOwned.cast(entity).setOwner(player); IOwned.cast(entity).setOwner(player.getOwner());
} }
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
entity.getDataManager().set(MixinEntity.Player.getModelFlag(), owner.getDataManager().get(MixinEntity.Player.getModelFlag())); entity.getDataManager().set(MixinEntity.Player.getModelFlag(), owner.getDataManager().get(MixinEntity.Player.getModelFlag()));
} }
if (UClient.instance().isClientPlayer(player)) { if (player.isClientPlayer() && UClient.instance().getViewMode() == 0) {
entity.setAlwaysRenderNameTag(false);
entity.setCustomNameTag("");
if (UClient.instance().getViewMode() == 0) {
entity.setInvisible(true); entity.setInvisible(true);
entity.posY = -Integer.MIN_VALUE; entity.posY = -Integer.MIN_VALUE;
} }
} else {
entity.setAlwaysRenderNameTag(true); return player.getPlayerSpecies() == Race.CHANGELING;
entity.setCustomNameTag(player.getName());
}
} }
if (!(source instanceof IPlayer) || ((IPlayer) source).getPlayerSpecies() == Race.CHANGELING) { return !source.getOwner().isDead;
return true;
}
}
owner.setInvisible(false);
if (source instanceof IPlayer) {
((IPlayer) source).setInvisible(false);
}
return false;
} }
@Override @Override
@ -448,6 +437,11 @@ public class SpellDisguise extends AbstractSpell implements IFlyingPredicate, IP
return -1; return -1;
} }
public static boolean skipsUpdate(Entity entity) {
return entity instanceof EntityFallingBlock
|| entity instanceof EntityPlayer;
}
public static boolean isAttachedEntity(Entity entity) { public static boolean isAttachedEntity(Entity entity) {
return entity instanceof EntityShulker return entity instanceof EntityShulker
|| entity instanceof EntityFallingBlock; || entity instanceof EntityFallingBlock;