diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-05-27 14:01:51 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-05-27 14:01:51 +1000 |
commit | a6e9f62a360ecb43eb771e4d0952a0e728cd748d (patch) | |
tree | 185a923a40c30207a74cedb6ab7c533187c1d537 /src/Java | |
parent | 9285a2ffdc9729f7b3c6917e44fdc68fc2d253c9 (diff) | |
download | GT5-Unofficial-a6e9f62a360ecb43eb771e4d0952a0e728cd748d.tar.gz GT5-Unofficial-a6e9f62a360ecb43eb771e4d0952a0e728cd748d.tar.bz2 GT5-Unofficial-a6e9f62a360ecb43eb771e4d0952a0e728cd748d.zip |
$ Fixed Locale issue.
% Made Large Eggs turn into Spawn eggs for large chickens.
Diffstat (limited to 'src/Java')
3 files changed, 145 insertions, 47 deletions
diff --git a/src/Java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java b/src/Java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java index c6ba9ff224..e6129317c6 100644 --- a/src/Java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java +++ b/src/Java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java @@ -32,48 +32,16 @@ public class ItemEntityGiantEgg extends EntityItem { super(aWorld, aX, aY, aZ, aStack); } - - //Large eggs don't despawn, because they will try hatch first. - @Override - public void onUpdate() { - if (this.lifespan != Integer.MAX_VALUE) { - this.lifespan = Integer.MAX_VALUE; - } - - if (this.getEntityItem() != null) { - ItemStack g = this.getEntityItem(); - NBTUtils.setInteger(g, "mTicksExisted", this.age); - this.setEntityItemStack(g); - Logger.INFO("Writing age to NBT of stored stack item."); - } - else { - ItemStack g = ItemUtils.getSimpleStack(ModItems.itemBigEgg); - NBTUtils.setInteger(g, "mTicksExisted", this.age); - this.setEntityItemStack(g); - Logger.INFO("Writing age to NBT of new stack item."); - - } - - if (this.age >= 1000) { - //Cache the value for efficiency - if (mEggSize == -1) - mEggSize = (this.getEntityItem() != null ? (this.getEntityItem().hasTagCompound() ? (this.getEntityItem().getTagCompound().hasKey("size") ? this.getEntityItem().getTagCompound().getInteger("size") : 1) : 1) : 1); - if (MathUtils.randInt(100*mEggSize, 1000) >= MathUtils.randInt(950, 1000)) { - //Spawn Chicken - spawnGiantChicken(); - } - } - super.onUpdate(); - } - - private void spawnGiantChicken() { + private boolean spawnGiantChicken() { try { EntityGiantChickenBase entitychicken = new EntityGiantChickenBase(this.worldObj); - entitychicken.setGrowingAge(-24000); + entitychicken.setGrowingAge(-MathUtils.randInt(20000, 40000)); entitychicken.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F); - this.worldObj.spawnEntityInWorld(entitychicken); + return this.worldObj.spawnEntityInWorld(entitychicken); + } + catch (Throwable t) { + return false; } - catch (Throwable t) {} } //These eggs also do not combine. @@ -105,5 +73,43 @@ public class ItemEntityGiantEgg extends EntityItem { return false; } + @Override + public void onEntityUpdate() { + super.onEntityUpdate(); + Logger.INFO("1"); + //Large eggs don't despawn, because they will try hatch first. + if (this.lifespan != Integer.MAX_VALUE-1) { + this.lifespan = Integer.MAX_VALUE-1; + } + + if (this.getEntityItem() != null) { + ItemStack g = this.getEntityItem(); + NBTUtils.setInteger(g, "mTicksExisted", this.age); + NBTUtils.setInteger(g, "lifespan", this.lifespan); + this.setEntityItemStack(g); + Logger.INFO("Writing age to NBT of stored stack item."); + } + else { + ItemStack g = ItemUtils.getSimpleStack(ModItems.itemBigEgg); + NBTUtils.setInteger(g, "mTicksExisted", this.age); + NBTUtils.setInteger(g, "lifespan", this.lifespan); + this.setEntityItemStack(g); + Logger.INFO("Writing age to NBT of new stack item."); + + } + + if (this.age >= 1000) { + //Cache the value for efficiency + if (mEggSize == -1) + mEggSize = (this.getEntityItem() != null ? (this.getEntityItem().hasTagCompound() ? (this.getEntityItem().getTagCompound().hasKey("size") ? this.getEntityItem().getTagCompound().getInteger("size") : 1) : 1) : 1); + if (MathUtils.randInt(100*mEggSize, 1000) >= MathUtils.randInt(950, 1000)) { + //Spawn Chicken + if (spawnGiantChicken()) { + this.kill(); + } + } + } + } + } diff --git a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java index 2b3d718538..6c22169f50 100644 --- a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java +++ b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java @@ -2,16 +2,22 @@ package gtPlusPlus.core.item.general; import static gtPlusPlus.core.lib.CORE.RANDOM; +import java.util.List; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import gtPlusPlus.core.entity.item.ItemEntityGiantEgg; import gtPlusPlus.core.item.base.BaseItemBurnable; import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.NBTUtils; public class ItemGiantEgg extends BaseItemBurnable { @@ -27,27 +33,79 @@ public class ItemGiantEgg extends BaseItemBurnable { String localName = super.getItemStackDisplayName(aStack); nbtWork(aStack); int size = 1; - int age = 0; if (NBTUtils.hasKey(aStack, "size")){ - size = NBTUtils.getInteger(aStack, "size"); - if (NBTUtils.hasKey(aStack, "mTicksExisted")){ - age = NBTUtils.getInteger(aStack, "mTicksExisted"); - return ""+size+" "+localName+" ["+age+"]"; - } + size = NBTUtils.getInteger(aStack, "size"); return ""+size+" "+localName; } return "?? "+localName; } + private static ItemStack mCorrectEgg; + @Override public void onUpdate(ItemStack aStack, World world, Entity entityHolding, int p_77663_4_, boolean p_77663_5_) { - if (entityHolding != null && entityHolding instanceof EntityPlayer) { + + if (world.isRemote) { + super.onUpdate(aStack, world, entityHolding, p_77663_4_, p_77663_5_); + return; + } + + boolean player = (entityHolding != null && entityHolding instanceof EntityPlayer); + + if (player) { NBTUtils.setBoolean(aStack, "playerHeld", true); } else { NBTUtils.setBoolean(aStack, "playerHeld", false); } + nbtWork(aStack); + + int age = NBTUtils.hasKey(aStack, "mAge") ? NBTUtils.getInteger(aStack, "mAge") : 0; + if (player) { + NBTUtils.setInteger(aStack, "mAge", age+1); + + //Set the correct egg for future hatches + if (mCorrectEgg == null) { + if (NBTUtils.hasKey(aStack, "mAge") && NBTUtils.hasKey(aStack, "mEggAge")) { + if (NBTUtils.getInteger(aStack, "mAge") >= NBTUtils.getInteger(aStack, "mEggAge")) { + for (int g=0;g<128;g++) { + ItemStack mSpawn = ItemUtils.simpleMetaStack(Items.spawn_egg, g, 1); + if (mSpawn != null) { + String s = ("" + StatCollector.translateToLocal(mSpawn.getUnlocalizedName() + ".name")).trim(); + String s1 = EntityList.getStringFromID(mSpawn.getItemDamage()); + if (s1 != null){ + s = s + " " + StatCollector.translateToLocal("entity." + s1 + ".name"); + if (s1.equalsIgnoreCase("bigChickenFriendly")) { + mCorrectEgg = mSpawn; + break; + } + } + } + } + } + } + } + + if (mCorrectEgg != null) { + if (NBTUtils.hasKey(aStack, "mAge") && NBTUtils.hasKey(aStack, "mEggAge")) { + if (NBTUtils.getInteger(aStack, "mAge") >= NBTUtils.getInteger(aStack, "mEggAge")) { + if (MathUtils.randInt(0, 1000) >= 990) { + if (NBTUtils.hasKey(aStack, "size")) { + if (NBTUtils.getInteger(aStack, "size") >= MathUtils.randInt(0, 9)) { + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((mCorrectEgg)); + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + else { + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + } + } + } + } + } + } + super.onUpdate(aStack, world, entityHolding, p_77663_4_, p_77663_5_); } @@ -58,9 +116,13 @@ public class ItemGiantEgg extends BaseItemBurnable { public void nbtWork(ItemStack aStack) { if (NBTUtils.hasKey(aStack, "playerHeld")) { - if (NBTUtils.getBoolean(aStack, "playerHeld") && !NBTUtils.hasKey(aStack, "size")) { + boolean player = NBTUtils.getBoolean(aStack, "playerHeld"); + if (player && !NBTUtils.hasKey(aStack, "size")) { NBTUtils.setInteger(aStack, "size", MathUtils.randInt(1, 8)); } + if (player && !NBTUtils.hasKey(aStack, "mEggAge") && NBTUtils.hasKey(aStack, "size")) { + NBTUtils.setInteger(aStack, "mEggAge", (MathUtils.randInt(8000, 16000)*NBTUtils.getInteger(aStack, "size"))); + } } } @@ -104,4 +166,24 @@ public class ItemGiantEgg extends BaseItemBurnable { return null; } + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + int size = 0; + if (NBTUtils.hasKey(stack, "size")){ + size = NBTUtils.getInteger(stack, "size"); + } + int age = 0; + if (NBTUtils.hasKey(stack, "mAge")){ + age = NBTUtils.getInteger(stack, "mAge"); + } + int life = 0; + if (NBTUtils.hasKey(stack, "mEggAge")){ + life = NBTUtils.getInteger(stack, "mEggAge"); + } + list.add("Egg Size: "+size+" ounces"); + list.add("Age: "+(age/20)+"s"+" / "+(life/20)+"s"); + list.add("Larger eggs take longer to hatch, but have a better chance of hatching."); + super.addInformation(stack, aPlayer, list, bool); + } + } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 43fc6d3cc4..9682c673b6 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -755,6 +755,13 @@ public class ItemUtils { } String mCacheKey = block.getUnlocalizedName()+":"+meta; if (mLocaleCache.containsKey(mCacheKey)) { + //Recache the key if it's invalid. + if (mLocaleCache.get(mCacheKey).toLowerCase().contains(".name")) { + mLocaleCache.remove(mCacheKey); + String mNew = ItemUtils.simpleMetaStack(block, meta, 1).getDisplayName(); + Logger.INFO("Re-caching "+mNew+" into locale cache."); + mLocaleCache.put(mCacheKey, mNew); + } return mLocaleCache.get(mCacheKey); } else { @@ -763,7 +770,10 @@ public class ItemUtils { return "Bad Item"; } String unlocalizedName = item.getUnlocalizedName(new ItemStack(block, 1, meta)); - String blockName = StatCollector.translateToLocal(unlocalizedName + ".name"); + String blockName = StatCollector.translateToLocal(unlocalizedName + ".name"); + if (blockName.toLowerCase().contains(".name")) { + blockName = ItemUtils.simpleMetaStack(block, meta, 1).getDisplayName(); + } mLocaleCache.put(mCacheKey, blockName); return blockName; } |