summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-06-24 22:07:45 +0100
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-06-24 22:07:45 +0100
commitb65c980fffb286feb2853245411f5bafb73daf15 (patch)
treef415d4991eb8be9d329435a88b03d2660ad4f432 /src/main/java/darkknight
parent883aa7a2bbc3a23fb18fbb881e9890c066666ed9 (diff)
Added an option to disable hearts from despawning
Diffstat (limited to 'src/main/java/darkknight')
-rw-r--r--src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java5
-rw-r--r--src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java284
2 files changed, 146 insertions, 143 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java b/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java
index 1a281bc..115f3b1 100644
--- a/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java
+++ b/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java
@@ -21,7 +21,6 @@ public class ConfigHandler
public static boolean GENERATE_VILLAGE_NETHERSTAR;
public static boolean CAN_FURNACE_GENERATE_INGOTS;
- public static boolean CRYSTAL_GLOW;
public static int MAX_VILLAGE_JEWELERS;
public static int JEWELER_WEIGHT;
public static int INGOT_CHEST_MIN;
@@ -31,6 +30,9 @@ public class ConfigHandler
public static int GEM_CHEST_MAX;
public static int FURNACE_MIN_INGOT_STACK;
public static int FURNACE_MAX_INGOT_STACK;
+
+ public static boolean CRYSTAL_GLOW;
+ public static boolean HEARTS_DESPAWN;
public static boolean CURSES_ENABLED = true;
public static boolean CURSE_ROTTEN_HEART = true;
@@ -82,6 +84,7 @@ public class ConfigHandler
FURNACE_MAX_INGOT_STACK = config.getInt("Ingot Furnace Max", categories[1], 5, 0, Integer.MAX_VALUE, "Determines the maximum number of ingots that can generate in a furnace.");
CRYSTAL_GLOW = config.getBoolean("Crystal Glow", categories[2], false, "If true, then crystal will slowly glow (can cause lag)");
+ HEARTS_DESPAWN = config.getBoolean("Hearts Despawn", categories[2], true, "If false, then Hearts and Half-hearts will no longer despawn");
ENABLE_WORLD_GEN = config.getBoolean("World Generation", categories[3], true, "If false, nothing will generate (this includes ore)");
ORE_GEN = config.getBoolean("Ore Generation", categories[3], true, "If false, ores won't generate");
diff --git a/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java b/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java
index 75c0015..6612c52 100644
--- a/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java
+++ b/src/main/java/darkknight/jewelrycraft/entities/EntityHeart.java
@@ -1,142 +1,142 @@
-/**
- *
- */
-package darkknight.jewelrycraft.entities;
-
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityLiving;
-import net.minecraft.entity.EnumCreatureAttribute;
-import net.minecraft.entity.SharedMonsterAttributes;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.nbt.NBTTagCompound;
-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
- */
-public class EntityHeart extends EntityLiving
-{
- public EntityHeart(World world)
- {
- super(world);
- this.setSize(0.4F, 0.4F);
- }
-
- protected void applyEntityAttributes()
- {
- super.applyEntityAttributes();
- this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(getQuantity());
- }
-
- @Override
- public void updateEntityActionState()
- {
- ++this.entityAge;
- }
-
- public void onLivingUpdate()
- {
- 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
- 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)
- 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.
- */
- public void readEntityFromNBT(NBTTagCompound nbt)
- {
- 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 JewelrycraftUtil.HEART;
- }
-}
+/**
+ *
+ */
+package darkknight.jewelrycraft.entities;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.EnumCreatureAttribute;
+import net.minecraft.entity.SharedMonsterAttributes;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.nbt.NBTTagCompound;
+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
+ */
+public class EntityHeart extends EntityLiving
+{
+ public EntityHeart(World world)
+ {
+ super(world);
+ this.setSize(0.4F, 0.4F);
+ }
+
+ protected void applyEntityAttributes()
+ {
+ super.applyEntityAttributes();
+ this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(getQuantity());
+ }
+
+ @Override
+ public void updateEntityActionState()
+ {
+ if(ConfigHandler.HEARTS_DESPAWN) ++this.entityAge;
+ }
+
+ public void onLivingUpdate()
+ {
+ super.onLivingUpdate();
+ if (ConfigHandler.HEARTS_DESPAWN && 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
+ 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)
+ 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.
+ */
+ public void readEntityFromNBT(NBTTagCompound nbt)
+ {
+ 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 JewelrycraftUtil.HEART;
+ }
+}