diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-05-08 18:12:00 +0100 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-05-08 18:12:00 +0100 |
| commit | 9d08d6c58a0622d31494d612d5b401a1fed186df (patch) | |
| tree | 4365f5aef42a61a9279271dd0bf0e6b65ca9640d /src/main/java/darkknight/jewelrycraft/entities | |
| parent | 2342897a409d08e2431b66191c4a7c4491e5222d (diff) | |
Fixed a few things as well as working towards having the ability to translate everything
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/entities')
3 files changed, 109 insertions, 56 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/entities/EntityHalfHeart.java b/src/main/java/darkknight/jewelrycraft/entities/EntityHalfHeart.java index 4fad309..c538f86 100644 --- a/src/main/java/darkknight/jewelrycraft/entities/EntityHalfHeart.java +++ b/src/main/java/darkknight/jewelrycraft/entities/EntityHalfHeart.java @@ -24,23 +24,15 @@ public class EntityHalfHeart extends EntityHeart super(world); } + protected void entityInit() + { + super.entityInit(); + this.dataWatcher.updateObject(17, 1f); + } + @Override public void onCollideWithPlayer(EntityPlayer player) { - if (!player.worldObj.isRemote){ - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (getType().equals("Red") && player.getHealth() < player.getMaxHealth()){ - player.heal(1f); - this.setDead(); - }else if (getType().equals("White") && playerInfo.getFloat("WhiteHeart") > 0.1F){ - playerInfo.setFloat(getType() + "Heart", 0F); - player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(player.getMaxHealth() + 2f); - this.setDead(); - }else if (!getType().equals("Red")){ - playerInfo.setFloat(getType() + "Heart", playerInfo.getFloat(getType() + "Heart") + 1.0F); - this.setDead(); - } - } - else JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + super.onCollideWithPlayer(player); } } diff --git a/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java b/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java index 899c075..75c0015 100644 --- a/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java +++ b/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java @@ -3,24 +3,21 @@ */ package darkknight.jewelrycraft.entities; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.network.PacketRequestPlayerInfo; -import darkknight.jewelrycraft.util.PlayerUtils; -import darkknight.jewelrycraft.util.Variables; -import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.util.DamageSource; import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.network.PacketRequestPlayerInfo; +import darkknight.jewelrycraft.util.JewelrycraftUtil; +import darkknight.jewelrycraft.util.PlayerUtils; +import darkknight.jewelrycraft.util.Variables; /** * @author Sorin @@ -33,54 +30,81 @@ public class EntityHeart extends EntityLiving this.setSize(0.4F, 0.4F); } - public boolean isEntityInvulnerable() + protected void applyEntityAttributes() { - return true; + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(getQuantity()); } - protected boolean canDespawn() + @Override + public void updateEntityActionState() { - return false; + ++this.entityAge; } - @Override - public void onCollideWithPlayer(EntityPlayer player) + public void onLivingUpdate() { - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (getType() == "Red" && player.getHealth() < player.getMaxHealth()){ - player.heal(2f); - this.setDead(); - } - else if (getType() != "Red"){ - playerInfo.setFloat(getType() + "Heart", playerInfo.getFloat(getType() + "Heart") + 2.0F); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - this.setDead(); + super.onLivingUpdate(); + if (this.entityAge > ConfigHandler.HEART_DESPAWN_TIME) this.setDead(); + } + + protected void collideWithEntity(Entity entity) + { + super.collideWithEntity(entity); + if (!this.worldObj.isRemote && entity instanceof EntityHeart && getType().equals(((EntityHeart)entity).getType())){ + setQuantity(getQuantity() + ((EntityHeart)entity).getQuantity()); + getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(getQuantity() + ((EntityHeart)entity).getQuantity()); + this.heal(getQuantity()); + entity.setDead(); } } @Override - protected void updateEntityActionState() + public void onCollideWithPlayer(EntityPlayer player) { + if (!this.worldObj.isRemote){ + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + if (getType() == "Red" && player.getHealth() < player.getMaxHealth()){ + float healAmount = player.getMaxHealth() - player.getHealth(); + if (getQuantity() > healAmount){ + player.heal(healAmount); + this.setQuantity(getQuantity() - healAmount); + }else{ + player.heal(getQuantity()); + this.setDead(); + } + }else if (getType().equals("White") && playerInfo.getFloat("WhiteHeart") > 0.1F){ + playerInfo.setFloat(getType() + "Heart", 0F); + player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(player.getMaxHealth() + playerInfo.getFloat("WhiteHeart")); + this.setDead(); + }else if (getType() != "Red"){ + playerInfo.setFloat(getType() + "Heart", playerInfo.getFloat(getType() + "Heart") + getQuantity()); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + this.setDead(); + } + } } - @SideOnly(Side.CLIENT) + @SideOnly (Side.CLIENT) public boolean canRenderOnFire() { return false; } - + protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(16, "Red"); + this.dataWatcher.addObject(17, 2f); } public void writeEntityToNBT(NBTTagCompound nbt) { super.writeEntityToNBT(nbt); nbt.setString("Type", getType()); + nbt.setFloat("Quantity", getQuantity()); } - + /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @@ -88,21 +112,31 @@ public class EntityHeart extends EntityLiving { super.readEntityFromNBT(nbt); setType(nbt.getString("Type")); + setQuantity(nbt.getFloat("Quantity")); } - + public String getType() { return this.dataWatcher.getWatchableObjectString(16); } - + public void setType(String type) { this.dataWatcher.updateObject(16, type); } + public Float getQuantity() + { + return this.dataWatcher.getWatchableObjectFloat(17); + } + + public void setQuantity(Float qty) + { + this.dataWatcher.updateObject(17, qty); + } + public EnumCreatureAttribute getCreatureAttribute() { - return EnumCreatureAttribute.UNDEAD; + return JewelrycraftUtil.HEART; } - } diff --git a/src/main/java/darkknight/jewelrycraft/entities/renders/HeartRender.java b/src/main/java/darkknight/jewelrycraft/entities/renders/HeartRender.java index f9da0da..d951340 100644 --- a/src/main/java/darkknight/jewelrycraft/entities/renders/HeartRender.java +++ b/src/main/java/darkknight/jewelrycraft/entities/renders/HeartRender.java @@ -1,9 +1,12 @@ package darkknight.jewelrycraft.entities.renders; +import java.util.Random; import org.lwjgl.opengl.GL11; +import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; import darkknight.jewelrycraft.entities.EntityHeart; @@ -15,27 +18,51 @@ import darkknight.jewelrycraft.util.Variables; public class HeartRender extends RenderLiving { protected ResourceLocation texture; - + Random rnd = new Random(); + public HeartRender(ModelBase modelBase, float shadowSize) { super(modelBase, shadowSize); } - + + protected void renderModel(EntityLivingBase entity, float x, float y, float z, float rot1, float rot2, float rot3) + { + super.renderModel(entity, x, y, z, rot1, rot2, rot3); + rnd.setSeed(1542372345); + if (((EntityHeart)entity).getQuantity() > 2f){ + for(int i = 0; i < ((EntityHeart)entity).getQuantity() / 10f; i++){ + float posX = rnd.nextFloat() * 0.2f * (rnd.nextBoolean()?1:-1); + float posY = rnd.nextFloat() * 0.2f * (rnd.nextBoolean()?1:-1); + float posZ = rnd.nextFloat() * 0.2f * (rnd.nextBoolean()?1:-1); + float rotX = rnd.nextFloat() * 35f * (rnd.nextBoolean()?1:-1); + float rotY = rnd.nextFloat() * 35f * (rnd.nextBoolean()?1:-1); + float rotZ = rnd.nextFloat() * 35f * (rnd.nextBoolean()?1:-1); + GL11.glTranslatef(-0.15F, 0.0F, 0.0F); + GL11.glTranslatef(posX, posY, 0F); + GL11.glRotatef(rotY, 0F, 1F, 0F); + GL11.glRotatef(rotZ, 0F, 0F, 1F); + GL11.glPushMatrix(); + this.mainModel.render(entity, x, y, z, rot1, rot2, rot3); + GL11.glPopMatrix(); + } + } + } + @Override protected void preRenderCallback(EntityLivingBase entity, float f) { - preRenderCallbackHeart((EntityHeart) entity, f); + preRenderCallbackHeart((EntityHeart)entity, f); } - + protected void preRenderCallbackHeart(EntityHeart entity, float f) { GL11.glScalef(0.4F, 0.4F, 0.4F); GL11.glRotatef(55F, 1F, 0F, 0F); String type = entity.getType(); - if(type == "" || type == null) type = "Red"; - texture = new ResourceLocation(Variables.MODID, "textures/entities/"+type+"Heart.png"); + if (type == "" || type == null) type = "Red"; + texture = new ResourceLocation(Variables.MODID, "textures/entities/" + type + "Heart.png"); } - + @Override protected ResourceLocation getEntityTexture(Entity par1Entity) { |
