From 4395f3aa10e167ec535810dbf7fef1730ad528a3 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Tue, 7 Jan 2014 23:39:39 -0500 Subject: [PATCH] You can now place balloons on entities. Still a bit buggy, and they don't float or anything, but it works. --- .../client/render/entity/RenderBalloon.java | 9 ++++++- .../mekanism/common/entity/EntityBalloon.java | 27 ++++++++++++------- common/mekanism/common/item/ItemBalloon.java | 5 ++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/common/mekanism/client/render/entity/RenderBalloon.java b/common/mekanism/client/render/entity/RenderBalloon.java index a31ab1bc9..c60c32b22 100644 --- a/common/mekanism/client/render/entity/RenderBalloon.java +++ b/common/mekanism/client/render/entity/RenderBalloon.java @@ -7,6 +7,7 @@ import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; @@ -36,8 +37,14 @@ public class RenderBalloon extends Render if(balloon.isLatchedToEntity()) { x = (balloon.latchedEntity.lastTickPosX + (balloon.latchedEntity.posX - balloon.latchedEntity.lastTickPosX)*partialTick); - y = (balloon.latchedEntity.lastTickPosY + (balloon.latchedEntity.posY - balloon.latchedEntity.lastTickPosY)*partialTick) + (balloon.latchedEntity.ySize/2); + y = (balloon.latchedEntity.lastTickPosY + (balloon.latchedEntity.posY - balloon.latchedEntity.lastTickPosY)*partialTick); z = (balloon.latchedEntity.lastTickPosZ + (balloon.latchedEntity.posZ - balloon.latchedEntity.lastTickPosZ)*partialTick); + + x -= RenderManager.renderPosX; + y -= RenderManager.renderPosY; + z -= RenderManager.renderPosZ; + + y += 3; } render(((EntityBalloon)entity).color, x, y, z); diff --git a/common/mekanism/common/entity/EntityBalloon.java b/common/mekanism/common/entity/EntityBalloon.java index 6241beb42..a5af7c27f 100644 --- a/common/mekanism/common/entity/EntityBalloon.java +++ b/common/mekanism/common/entity/EntityBalloon.java @@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityReddustFX; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Vec3; import net.minecraft.world.World; @@ -23,7 +24,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData public EnumColor color = EnumColor.DARK_BLUE; public Coord4D latched; - public Entity latchedEntity; + public EntityLivingBase latchedEntity; /* server-only */ public boolean hasCachedEntity; @@ -61,12 +62,12 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData color = c; } - public EntityBalloon(Entity entity, EnumColor c) + public EntityBalloon(EntityLivingBase entity, EnumColor c) { this(entity.worldObj); latchedEntity = entity; - setPosition(latchedEntity.posX, (latchedEntity.ySize/2), latchedEntity.posZ); + setPosition(latchedEntity.posX, latchedEntity.posY + 3F, latchedEntity.posZ); prevPosX = posX; prevPosY = posY; @@ -123,6 +124,14 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData else { latched = null; } + + if(dataWatcher.getWatchableObjectByte(2) == 2) + { + latchedEntity = (EntityLivingBase)worldObj.getEntityByID(dataWatcher.getWatchableObjectInt(6)); + } + else { + latchedEntity = null; + } } else { if(hasCachedEntity) @@ -151,7 +160,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData dataWatcher.updateObject(2, (byte)0); /* Is latched */ } - if(latchedEntity != null && (latchedEntity.isDead || !worldObj.loadedEntityList.contains(latchedEntity))) + if(latchedEntity != null && (latchedEntity.getHealth() <= 0 || latchedEntity.isDead || !worldObj.loadedEntityList.contains(latchedEntity))) { latchedEntity = null; @@ -185,10 +194,10 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData motionY = 0; motionZ = 0; } - else if(latchedEntity != null) + else if(latchedEntity != null && latchedEntity.getHealth() > 0) { posX = latchedEntity.posX; - posY = latchedEntity.posY + (latchedEntity.ySize/2); + posY = latchedEntity.posY + 3F; posZ = latchedEntity.posZ; } } @@ -197,9 +206,9 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData { for(Object obj : worldObj.loadedEntityList) { - if(obj instanceof Entity) + if(obj instanceof EntityLivingBase) { - Entity entity = (Entity)obj; + EntityLivingBase entity = (EntityLivingBase)obj; if(entity.getUniqueID().equals(cachedEntityUUID)) { @@ -336,7 +345,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData } else if(type == 2) { - latchedEntity = worldObj.getEntityByID(data.readInt()); + latchedEntity = (EntityLivingBase)worldObj.getEntityByID(data.readInt()); } else { latched = null; diff --git a/common/mekanism/common/item/ItemBalloon.java b/common/mekanism/common/item/ItemBalloon.java index 741209abf..7811d11e9 100644 --- a/common/mekanism/common/item/ItemBalloon.java +++ b/common/mekanism/common/item/ItemBalloon.java @@ -121,7 +121,7 @@ public class ItemBalloon extends ItemMekanism @Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity) { - /*if(player.isSneaking()) + if(player.isSneaking()) { if(!player.worldObj.isRemote) { @@ -136,12 +136,13 @@ public class ItemBalloon extends ItemMekanism return true; } } + player.worldObj.spawnEntityInWorld(new EntityBalloon(entity, getColor(stack))); stack.stackSize--; } return true; - }*/ + } return false; }