mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Now let's optimise this a bit. Fixes particle trails on shulker bullets
This commit is contained in:
parent
64edc23f2e
commit
0ab3867b9d
2 changed files with 170 additions and 171 deletions
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
NBTTagCompound nbt = entityNbt;
|
||||||
|
entityNbt = null;
|
||||||
|
|
||||||
if ("player".equals(entityId)) {
|
if ("player".equals(entityId)) {
|
||||||
|
|
||||||
NBTTagCompound nbt = entityNbt;
|
|
||||||
entityNbt = null;
|
|
||||||
|
|
||||||
createPlayer(nbt, new GameProfile(
|
createPlayer(nbt, new GameProfile(
|
||||||
nbt.getUniqueId("playerId"),
|
nbt.getUniqueId("playerId"),
|
||||||
nbt.getString("playerName")
|
nbt.getString("playerName")
|
||||||
|
@ -144,17 +141,116 @@ 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);
|
||||||
source.getWorld().spawnEntity(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
entityNbt = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onEntityLoaded(ICaster<?> source) {
|
||||||
|
if (entity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.getWorld().isRemote) {
|
||||||
|
source.getWorld().spawnEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
@Override
|
@Override
|
||||||
public boolean update(ICaster<?> source) {
|
public boolean update(ICaster<?> source) {
|
||||||
|
@ -166,195 +262,88 @@ 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.setInvisible(false);
|
||||||
entity.prevPosY = owner.prevPosY;
|
entity.setNoGravity(true);
|
||||||
entity.prevPosZ = owner.prevPosZ;
|
|
||||||
|
|
||||||
entity.motionX = owner.motionX;
|
copyBaseAttributes(owner, entity);
|
||||||
entity.motionY = owner.motionY;
|
|
||||||
entity.motionZ = owner.motionZ;
|
|
||||||
|
|
||||||
entity.prevRotationPitch = owner.prevRotationPitch;
|
if (!skipsUpdate(entity)) {
|
||||||
entity.prevRotationYaw = owner.prevRotationYaw;
|
entity.onUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
entity.distanceWalkedOnStepModified = owner.distanceWalkedOnStepModified;
|
if (entity instanceof EntityShulker) {
|
||||||
entity.distanceWalkedModified = owner.distanceWalkedModified;
|
EntityShulker shulker = ((EntityShulker)entity);
|
||||||
entity.prevDistanceWalkedModified = owner.prevDistanceWalkedModified;
|
|
||||||
|
|
||||||
if (entity instanceof EntityLivingBase) {
|
shulker.rotationYaw = 0;
|
||||||
EntityLivingBase l = (EntityLivingBase)entity;
|
shulker.renderYawOffset = 0;
|
||||||
|
shulker.prevRenderYawOffset = 0;
|
||||||
|
|
||||||
l.rotationYawHead = owner.rotationYawHead;
|
shulker.setAttachmentPos(null);
|
||||||
l.prevRotationYawHead = owner.prevRotationYawHead;
|
|
||||||
l.renderYawOffset = owner.renderYawOffset;
|
|
||||||
l.prevRenderYawOffset = owner.prevRenderYawOffset;
|
|
||||||
|
|
||||||
l.limbSwing = owner.limbSwing;
|
if (source.getWorld().isRemote && source instanceof IPlayer) {
|
||||||
l.limbSwingAmount = owner.limbSwingAmount;
|
IPlayer player = (IPlayer)source;
|
||||||
l.prevLimbSwingAmount = owner.prevLimbSwingAmount;
|
|
||||||
|
|
||||||
l.swingingHand = owner.swingingHand;
|
|
||||||
l.swingProgress = owner.swingProgress;
|
|
||||||
l.swingProgressInt = owner.swingProgressInt;
|
|
||||||
l.isSwingInProgress = owner.isSwingInProgress;
|
|
||||||
|
|
||||||
l.hurtTime = owner.hurtTime;
|
float peekAmount = 0.3F;
|
||||||
l.deathTime = owner.deathTime;
|
|
||||||
l.setHealth(owner.getHealth());
|
|
||||||
|
|
||||||
for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) {
|
if (!owner.isSneaking()) {
|
||||||
ItemStack neu = owner.getItemStackFromSlot(i);
|
float speed = (float)Math.sqrt(Math.pow(owner.motionX, 2) + Math.pow(owner.motionZ, 2));
|
||||||
ItemStack old = l.getItemStackFromSlot(i);
|
|
||||||
if (old != neu) {
|
peekAmount = MathHelper.clamp(speed * 30, 0, 1);
|
||||||
l.setItemStackToSlot(i, neu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l instanceof EntityShulker) {
|
peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);
|
||||||
l.rotationYaw = 0;
|
|
||||||
|
|
||||||
l.renderYawOffset = 0;
|
MixinEntity.Shulker.setPeek(shulker, peekAmount);
|
||||||
l.prevRenderYawOffset = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isAttachedEntity(entity)) {
|
if (entity instanceof EntityMinecart) {
|
||||||
|
entity.rotationYaw += 90;
|
||||||
|
entity.rotationPitch = 0;
|
||||||
|
}
|
||||||
|
|
||||||
entity.posX = Math.floor(owner.posX) + 0.5;
|
if (source instanceof IPlayer) {
|
||||||
entity.posY = Math.floor(owner.posY + 0.2);
|
IPlayer player = (IPlayer)source;
|
||||||
entity.posZ = Math.floor(owner.posZ) + 0.5;
|
|
||||||
|
|
||||||
entity.lastTickPosX = entity.posX;
|
player.setInvisible(true);
|
||||||
entity.lastTickPosY = entity.posY;
|
source.getOwner().setInvisible(true);
|
||||||
entity.lastTickPosZ = entity.posZ;
|
|
||||||
|
|
||||||
entity.prevPosX = entity.posX;
|
if (entity instanceof IOwned) {
|
||||||
entity.prevPosY = entity.posY;
|
IOwned.cast(entity).setOwner(player.getOwner());
|
||||||
entity.prevPosZ = entity.posZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof EntityShulker) {
|
|
||||||
EntityShulker shulker = ((EntityShulker)entity);
|
|
||||||
|
|
||||||
shulker.setAttachmentPos(null);
|
|
||||||
|
|
||||||
if (source.getWorld().isRemote && source instanceof IPlayer) {
|
|
||||||
IPlayer player = (IPlayer)source;
|
|
||||||
|
|
||||||
|
|
||||||
float peekAmount = 0.3F;
|
|
||||||
|
|
||||||
if (!owner.isSneaking()) {
|
|
||||||
float speed = (float)Math.sqrt(Math.pow(owner.motionX, 2) + Math.pow(owner.motionZ, 2));
|
|
||||||
|
|
||||||
peekAmount = speed * 30;
|
|
||||||
if (peekAmount > 1) {
|
|
||||||
peekAmount = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);
|
|
||||||
|
|
||||||
MixinEntity.Shulker.setPeek(shulker, peekAmount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof EntityLiving) {
|
|
||||||
EntityLiving l = (EntityLiving)entity;
|
|
||||||
|
|
||||||
l.setNoAI(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof EntityMinecart) {
|
|
||||||
entity.rotationYaw += 90;
|
|
||||||
entity.rotationPitch = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof EntityPlayer) {
|
if (entity instanceof EntityPlayer) {
|
||||||
EntityPlayer l = (EntityPlayer)entity;
|
entity.getDataManager().set(MixinEntity.Player.getModelFlag(), owner.getDataManager().get(MixinEntity.Player.getModelFlag()));
|
||||||
|
|
||||||
l.chasingPosX = l.posX;
|
|
||||||
l.chasingPosY = l.posY;
|
|
||||||
l.chasingPosZ = l.posZ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner.isBurning()) {
|
if (player.isClientPlayer() && UClient.instance().getViewMode() == 0) {
|
||||||
entity.setFire(1);
|
entity.setInvisible(true);
|
||||||
} else {
|
entity.posY = -Integer.MIN_VALUE;
|
||||||
entity.extinguish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.noClip = true;
|
return player.getPlayerSpecies() == Race.CHANGELING;
|
||||||
entity.updateBlocked = true;
|
|
||||||
|
|
||||||
entity.setSneaking(owner.isSneaking());
|
|
||||||
entity.setInvisible(false);
|
|
||||||
|
|
||||||
if (source instanceof IPlayer) {
|
|
||||||
((IPlayer) source).setInvisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
owner.setInvisible(true);
|
|
||||||
|
|
||||||
if (entity instanceof EntityTameable) {
|
|
||||||
((EntityTameable)entity).setSitting(owner.isSneaking());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (owner instanceof EntityPlayer) {
|
|
||||||
EntityPlayer player = (EntityPlayer)owner;
|
|
||||||
|
|
||||||
if (entity instanceof IOwned) {
|
|
||||||
IOwned.cast(entity).setOwner(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof EntityPlayer) {
|
|
||||||
entity.getDataManager().set(MixinEntity.Player.getModelFlag(), owner.getDataManager().get(MixinEntity.Player.getModelFlag()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UClient.instance().isClientPlayer(player)) {
|
|
||||||
entity.setAlwaysRenderNameTag(false);
|
|
||||||
entity.setCustomNameTag("");
|
|
||||||
|
|
||||||
if (UClient.instance().getViewMode() == 0) {
|
|
||||||
entity.setInvisible(true);
|
|
||||||
entity.posY = -Integer.MIN_VALUE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entity.setAlwaysRenderNameTag(true);
|
|
||||||
entity.setCustomNameTag(player.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(source instanceof IPlayer) || ((IPlayer) source).getPlayerSpecies() == Race.CHANGELING) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
owner.setInvisible(false);
|
return !source.getOwner().isDead;
|
||||||
|
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue