You can now place balloons on entities. Still a bit buggy, and they don't float or anything, but it works.

This commit is contained in:
Aidan C. Brady 2014-01-07 23:39:39 -05:00
parent ca207eb502
commit 4395f3aa10
3 changed files with 29 additions and 12 deletions

View file

@ -7,6 +7,7 @@ import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -36,8 +37,14 @@ public class RenderBalloon extends Render
if(balloon.isLatchedToEntity()) if(balloon.isLatchedToEntity())
{ {
x = (balloon.latchedEntity.lastTickPosX + (balloon.latchedEntity.posX - balloon.latchedEntity.lastTickPosX)*partialTick); 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); 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); render(((EntityBalloon)entity).color, x, y, z);

View file

@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.particle.EntityReddustFX; import net.minecraft.client.particle.EntityReddustFX;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -23,7 +24,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
public EnumColor color = EnumColor.DARK_BLUE; public EnumColor color = EnumColor.DARK_BLUE;
public Coord4D latched; public Coord4D latched;
public Entity latchedEntity; public EntityLivingBase latchedEntity;
/* server-only */ /* server-only */
public boolean hasCachedEntity; public boolean hasCachedEntity;
@ -61,12 +62,12 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
color = c; color = c;
} }
public EntityBalloon(Entity entity, EnumColor c) public EntityBalloon(EntityLivingBase entity, EnumColor c)
{ {
this(entity.worldObj); this(entity.worldObj);
latchedEntity = entity; latchedEntity = entity;
setPosition(latchedEntity.posX, (latchedEntity.ySize/2), latchedEntity.posZ); setPosition(latchedEntity.posX, latchedEntity.posY + 3F, latchedEntity.posZ);
prevPosX = posX; prevPosX = posX;
prevPosY = posY; prevPosY = posY;
@ -123,6 +124,14 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
else { else {
latched = null; latched = null;
} }
if(dataWatcher.getWatchableObjectByte(2) == 2)
{
latchedEntity = (EntityLivingBase)worldObj.getEntityByID(dataWatcher.getWatchableObjectInt(6));
}
else {
latchedEntity = null;
}
} }
else { else {
if(hasCachedEntity) if(hasCachedEntity)
@ -151,7 +160,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
dataWatcher.updateObject(2, (byte)0); /* Is latched */ 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; latchedEntity = null;
@ -185,10 +194,10 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
motionY = 0; motionY = 0;
motionZ = 0; motionZ = 0;
} }
else if(latchedEntity != null) else if(latchedEntity != null && latchedEntity.getHealth() > 0)
{ {
posX = latchedEntity.posX; posX = latchedEntity.posX;
posY = latchedEntity.posY + (latchedEntity.ySize/2); posY = latchedEntity.posY + 3F;
posZ = latchedEntity.posZ; posZ = latchedEntity.posZ;
} }
} }
@ -197,9 +206,9 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
{ {
for(Object obj : worldObj.loadedEntityList) 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)) if(entity.getUniqueID().equals(cachedEntityUUID))
{ {
@ -336,7 +345,7 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData
} }
else if(type == 2) else if(type == 2)
{ {
latchedEntity = worldObj.getEntityByID(data.readInt()); latchedEntity = (EntityLivingBase)worldObj.getEntityByID(data.readInt());
} }
else { else {
latched = null; latched = null;

View file

@ -121,7 +121,7 @@ public class ItemBalloon extends ItemMekanism
@Override @Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity) public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity)
{ {
/*if(player.isSneaking()) if(player.isSneaking())
{ {
if(!player.worldObj.isRemote) if(!player.worldObj.isRemote)
{ {
@ -136,12 +136,13 @@ public class ItemBalloon extends ItemMekanism
return true; return true;
} }
} }
player.worldObj.spawnEntityInWorld(new EntityBalloon(entity, getColor(stack))); player.worldObj.spawnEntityInWorld(new EntityBalloon(entity, getColor(stack)));
stack.stackSize--; stack.stackSize--;
} }
return true; return true;
}*/ }
return false; return false;
} }