From 2b7ae2001ed8f49d2de8f88ef306426af60c279b Mon Sep 17 00:00:00 2001 From: Alkalus Date: Mon, 4 May 2020 01:32:46 +0100 Subject: $ Fixed handling of Giant Eggs. $ Fixed obscure crash caused by Dingos. $ Fixed handling of Spawn Eggs and entities registered to the global list. $ Potentially fixed NEI not working correctly for GT++ recipe maps. --- src/Java/gtPlusPlus/core/item/ModItems.java | 9 +- .../core/item/base/BaseItemTickable.java | 68 ++-- .../item/base/itemblock/ItemBlockBasicTile.java | 5 +- .../gtPlusPlus/core/item/general/ItemGiantEgg.java | 351 ++++++++++++--------- .../item/general/spawn/ItemCustomSpawnEgg.java | 285 +++++++++++++++++ .../core/item/materials/DustDecayable.java | 2 +- 6 files changed, 533 insertions(+), 187 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index fd2b98c7be..1726a22a7b 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -60,6 +60,7 @@ import gtPlusPlus.core.item.general.capture.ItemEntityCatcher; import gtPlusPlus.core.item.general.chassis.ItemBoilerChassis; import gtPlusPlus.core.item.general.chassis.ItemDehydratorCoil; import gtPlusPlus.core.item.general.chassis.ItemDehydratorCoilWire; +import gtPlusPlus.core.item.general.spawn.ItemCustomSpawnEgg; import gtPlusPlus.core.item.general.throwables.ItemHydrofluoricAcidPotion; import gtPlusPlus.core.item.general.throwables.ItemSulfuricAcidPotion; import gtPlusPlus.core.item.general.throwables.ItemThrowableBomb; @@ -111,7 +112,6 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; public final class ModItems { - public static ToolMaterial STABALLOY = EnumHelper.addToolMaterial("Staballoy", 3, 2500, 7, 1.0F, 18); public static Item ZZZ_Empty; @@ -120,7 +120,7 @@ public final class ModItems { public static Item itemAlkalusDisk; public static Item itemDebugShapeSpawner; - public static Item itemBaseSpawnEgg; + public static ItemCustomSpawnEgg itemCustomSpawnEgg; //EnderIO public static Item itemPlateSoularium; @@ -317,7 +317,7 @@ public final class ModItems { public static Item dustDecayedRadium226; public static Item dustRadium226; - public static Item itemBigEgg; + public static ItemGiantEgg itemBigEgg; public static GregtechPump toolGregtechPump; @@ -384,9 +384,10 @@ public final class ModItems { itemDebugScanner = new DebugScanner(); itemAlkalusDisk = new BaseItemDamageable("itemAlkalusDisk", AddToCreativeTab.tabMisc, 1, 0, "Unknown Use", EnumRarity.rare, EnumChatFormatting.AQUA, false, null); - itemBigEgg = new ItemGiantEgg("itemBigEgg", "Ginourmous Chicken Egg", tabMisc, 64, 0, "I had best try disassemble this.. for science!", "fuelLargeChickenEgg", 5000, 0).setTextureName(CORE.MODID + ":itemBigEgg"); + itemBigEgg = new ItemGiantEgg(); itemGenericToken = new ItemGenericToken(); itemDummyResearch = new ItemDummyResearch(); + itemCustomSpawnEgg = new ItemCustomSpawnEgg(); //Debug Loading if (CORE_Preloader.DEBUG_MODE){ diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemTickable.java b/src/Java/gtPlusPlus/core/item/base/BaseItemTickable.java index 54710662d8..79a49f92b7 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemTickable.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemTickable.java @@ -14,10 +14,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.world.World; - +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; public class BaseItemTickable extends CoreItem { @@ -57,7 +58,7 @@ public class BaseItemTickable extends CoreItem { } - boolean active = getIsActive(world, iStack); + boolean active = isTicking(world, iStack); if (active) { tickItemTag(world, iStack); } @@ -113,12 +114,15 @@ public class BaseItemTickable extends CoreItem { } } + protected int getMaxTicks(ItemStack aStack) { + return maxTicks; + } - private boolean createNBT(World world, ItemStack rStack){ + protected boolean createNBT(World world, ItemStack rStack){ final NBTTagCompound tagMain = new NBTTagCompound(); final NBTTagCompound tagNBT = new NBTTagCompound(); tagNBT.setLong("Tick", 0); - tagNBT.setLong("maxTick", this.maxTicks); + tagNBT.setLong("maxTick", getMaxTicks(rStack)); tagNBT.setBoolean("isActive", true); //Try set world time @@ -127,11 +131,12 @@ public class BaseItemTickable extends CoreItem { } tagMain.setTag("TickableItem", tagNBT); - rStack.setTagCompound(tagMain); + rStack.setTagCompound(tagMain); + Logger.INFO("Created Tickable NBT data."); return true; } - public final long getFilterDamage(World world, final ItemStack aStack) { + public final long getTicks(World world, final ItemStack aStack) { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { aNBT = aNBT.getCompoundTag("TickableItem"); @@ -145,7 +150,7 @@ public class BaseItemTickable extends CoreItem { return 0L; } - public final boolean setFilterDamage(World world, final ItemStack aStack, final long aDamage) { + public final boolean setTicks(World world, final ItemStack aStack, final long aDamage) { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { aNBT = aNBT.getCompoundTag("TickableItem"); @@ -160,7 +165,7 @@ public class BaseItemTickable extends CoreItem { return false; } - public final boolean getIsActive(World world, final ItemStack aStack) { + public final boolean isTicking(World world, final ItemStack aStack) { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { aNBT = aNBT.getCompoundTag("TickableItem"); @@ -174,7 +179,7 @@ public class BaseItemTickable extends CoreItem { return true; } - public final boolean setIsActive(World world, final ItemStack aStack, final boolean active) { + public final boolean setTicking(World world, final ItemStack aStack, final boolean active) { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { aNBT = aNBT.getCompoundTag("TickableItem"); @@ -251,26 +256,15 @@ public class BaseItemTickable extends CoreItem { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { if (aNBT.hasKey("TickableItem")) { - aNBT = aNBT.getCompoundTag("TickableItem"); - - /*if (!aNBT.hasKey("CreationDate") && world != null) { - aNBT.setLong("CreationDate", world.getTotalWorldTime()); - }*/ - + aNBT = aNBT.getCompoundTag("TickableItem"); //Done Ticking - if (maxTicks-getFilterDamage(world, aStack) <= 0) { - setIsActive(world, aStack, false); + if (getMaxTicks(aStack)-getTicks(world, aStack) <= 0) { + setTicking(world, aStack, false); return false; } - if (getIsActive(world, aStack)) { + if (isTicking(world, aStack)) { if (aNBT != null) { - - //if ((world.getTotalWorldTime()-)) - - // Just tick once - aNBT.setLong("Tick", getFilterDamage(world, aStack)+1); - - + aNBT.setLong("Tick", getTicks(world, aStack)+1); return true; } else { @@ -288,10 +282,11 @@ public class BaseItemTickable extends CoreItem { @Override public double getDurabilityForDisplay(ItemStack stack) { if (stack.getTagCompound() == null){ - createNBT(null, stack); + //createNBT(null, stack); + return 0; } - double currentDamage = getFilterDamage(null, stack); - double durabilitypercent = currentDamage / maxTicks; + double currentDamage = getTicks(null, stack); + double durabilitypercent = currentDamage / getMaxTicks(stack); return durabilitypercent; } @@ -302,23 +297,28 @@ public class BaseItemTickable extends CoreItem { if (this.descriptionString.length > 0) { list.add(EnumChatFormatting.GRAY+this.descriptionString[0]); } + long maxTicks = getMaxTicks(stack); + long ticks = 0; + if (stack.hasTagCompound()) { + ticks = getTicks(world, stack); + } EnumChatFormatting durability = EnumChatFormatting.GRAY; - if (maxTicks-getFilterDamage(world, stack) > (maxTicks*0.8)){ + if (maxTicks-ticks > (maxTicks*0.8)){ durability = EnumChatFormatting.GRAY; } - else if (maxTicks-getFilterDamage(world, stack) > (maxTicks*0.6)){ + else if (maxTicks-ticks > (maxTicks*0.6)){ durability = EnumChatFormatting.GREEN; } - else if (maxTicks-getFilterDamage(world, stack) > (maxTicks*0.4)){ + else if (maxTicks-ticks > (maxTicks*0.4)){ durability = EnumChatFormatting.YELLOW; } - else if (maxTicks-getFilterDamage(world, stack) > (maxTicks*0.2)){ + else if (maxTicks-ticks > (maxTicks*0.2)){ durability = EnumChatFormatting.GOLD; } - else if (maxTicks-getFilterDamage(world, stack) > 0){ + else if (maxTicks-ticks > 0){ durability = EnumChatFormatting.RED; } - list.add(durability+""+((maxTicks-getFilterDamage(world, stack))/20)+EnumChatFormatting.GRAY+" seconds until decay"); + list.add(durability+""+((maxTicks-ticks)/20)+EnumChatFormatting.GRAY+" seconds until decay"); if (this.descriptionString.length > 1) { for (int h=1;h(burn, ItemUtils.getSimpleStack(this, 1))); } - private static ItemStack mCorrectEgg; - private static ItemStack mCorrectStemCells; + public final void registerOrdictionary(String name){ + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), name); + } - @Override - public void onUpdate(ItemStack aStack, World world, Entity entityHolding, int p_77663_4_, boolean p_77663_5_) { + public ItemGiantEgg() { + this(Utils.rgbtoHexValue(255, 255, 255), Short.MAX_VALUE * Byte.MAX_VALUE, new String[] {"I had best try disassemble this.. for science!"}); + } - if (world.isRemote) { - super.onUpdate(aStack, world, entityHolding, p_77663_4_, p_77663_5_); - return; - } - try { - boolean player = (entityHolding != null && entityHolding instanceof EntityPlayer); + private ItemGiantEgg(int colour, int maxTicks, String[] desc1) { + super(true, false, "itemBigEgg", colour, maxTicks, desc1); + setTextureName(CORE.MODID + ":itemBigEgg"); + this.setMaxStackSize(1); + registerFuel(5000); + registerOrdictionary("fuelLargeChickenEgg"); + } + + public static void postInit(ItemGiantEgg aGiantEggItem) { + ItemGiantEgg.turnsIntoItem = getSpawnEggStack(); + //new DecayableRecipe(aGiantEggItem.maxTicks, getSimpleStack(aGiantEggItem), ItemUtils.getSimpleStack(ItemGiantEgg.turnsIntoItem, 1)); + } - 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; - } - } - } - } + private static ItemStack getSpawnEggStack() { + //Set the correct egg for future hatches + if (mCorrectEgg == null) { + /*for (int g=0;g= NBTUtils.getInteger(aStack, "mEggAge")) { - if (MathUtils.randInt(0, 1000) >= 990) { - if (NBTUtils.hasKey(aStack, "size")) { - if ((NBTUtils.getInteger(aStack, "size")+1) >= MathUtils.randInt(0, 9)) { - ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((mCorrectEgg)); - ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); - } - else { - ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); - } - } - } - } - } + private static ItemStack getStemCellStack() { + if (mCorrectStemCells == null) { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && Utils.getGregtechSubVersion() > 28) { + ItemStack xl = ItemUtils.getValueOfItemList("Circuit_Chip_Stemcell", 1, ItemUtils.getSimpleStack(Items.egg, 2)); + if (xl != null) { + mCorrectStemCells = xl.copy(); } } + else { + mCorrectStemCells = ItemUtils.getSimpleStack(Items.egg, 2); + } } - catch (Throwable t) { - t.printStackTrace(); - } + return mCorrectStemCells; + } - super.onUpdate(aStack, world, entityHolding, p_77663_4_, p_77663_5_); + protected int getMaxTicks(ItemStack aStack) { + if (aStack != null && aStack.hasTagCompound() && aStack.getTagCompound().hasKey("mEggAge")) { + return NBTUtils.getInteger(aStack, "mEggAge"); + } + return maxTicks; } @Override - public void onCreated(ItemStack p_77622_1_, World p_77622_2_, EntityPlayer p_77622_3_) { - super.onCreated(p_77622_1_, p_77622_2_, p_77622_3_); + public void registerIcons(final IIconRegister i) { + this.mIcon[0] = i.registerIcon(CORE.MODID + ":" + "itemBigEgg"); } - public void nbtWork(ItemStack aStack) { - if (NBTUtils.hasKey(aStack, "playerHeld")) { - boolean player = NBTUtils.getBoolean(aStack, "playerHeld"); - if (player && !NBTUtils.hasKey(aStack, "size")) { - NBTUtils.setInteger(aStack, "size", MathUtils.randInt(1, 8)); + + @Override + protected boolean createNBT(World world, ItemStack aStack){ + + if (aStack.getTagCompound() != null && aStack.getTagCompound().hasKey("size")) { + return false; + } + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(1)); + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(2)); + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(3)); + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(4)); + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(5)); + Logger.INFO("Egg: "+ReflectionUtils.getMethodName(6)); + //Logger.INFO("Creating Egg NBT."); + boolean aSuper = super.createNBT(world, aStack); + int size = MathUtils.randInt(1, 8); + NBTUtils.setInteger(aStack, "size", size); + NBTUtils.setInteger(aStack, "mEggAge", ((MathUtils.randInt(8000, 16000)*size))); + ItemStack aStemCells = getStemCellStack(); + if (aStemCells != null) { + int mSize = NBTUtils.getInteger(aStack, "size"); + float mSizeMod = (MathUtils.randInt(-5, 5)/5); + mSize += mSizeMod; + mSize = Math.max(mSize, 1); + ItemStack eggYolks[] = new ItemStack[mSize]; + for (int u=0;u 0) { + NBTUtils.setInteger(aStack, "mExpected", mexpected); + NBTUtils.writeItemsToGtCraftingComponents(aStack, new ItemStack[]{ ItemUtils.getSimpleStack(aStemCells, mexpected)}, true); + } + } + return aSuper; + + } - if (player && NBTUtils.getTagCompound(aStack, "GT.CraftingComponents") == null) { - if (mCorrectStemCells == null) { - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && Utils.getGregtechSubVersion() > 28) { - - ItemList xl = ItemUtils.getValueOfItemList("Circuit_Chip_Stemcell", ItemList.Circuit_Elite); - if (xl != null && xl.hasBeenSet()) { - mCorrectStemCells = xl.get(1); - } - } - else { - mCorrectStemCells = ItemUtils.getSimpleStack(Items.egg, 2); - } - } - if (mCorrectStemCells != null) { - int mSize = NBTUtils.getInteger(aStack, "size"); - float mSizeMod = (MathUtils.randInt(-5, 5)/10); - mSize += mSizeMod; - mSize = Math.max(mSize, 1); - ItemStack eggYolks[] = new ItemStack[mSize]; - for (int u=0;u= 990) { + if (NBTUtils.hasKey(iStack, "size")) { + if ((NBTUtils.getInteger(iStack, "size")+1) >= MathUtils.randInt(0, 9)) { + ItemStack replacement = ItemUtils.getSimpleStack(getHatchResult(), 1); + if (replacement == null) { + + } + //Logger.INFO("Replacing "+iStack.getDisplayName()+" with "+replacement.getDisplayName()+"."); + final ItemStack tempTransform = replacement.copy(); + if (iStack.stackSize > 1){ + int u = iStack.stackSize; + tempTransform.stackSize = u; + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform)); + for (int l=0;l 0) { - NBTUtils.setInteger(aStack, "mExpected", mexpected); - } - - NBTUtils.writeItemsToGtCraftingComponents(aStack, eggYolks, true); } } - if (player && NBTUtils.getTagCompound(aStack, "GT.CraftingComponents") != null) { + } + } - } - } + public ItemStack getHatchResult() { + return turnsIntoItem; } + @Override + public String getItemStackDisplayName(ItemStack aStack) { + String localName = super.getItemStackDisplayName(aStack); + /*if (aStack.getTagCompound() == null){ + createNBT(null, aStack); + Logger.INFO("Egg has no NBT, creating (getDisplayName)"); + }*/ + int size = 1; + if (NBTUtils.hasKey(aStack, "size")){ + size = NBTUtils.getInteger(aStack, "size"); + return ""+size+" "+localName; + } + return "?? "+localName; + } + + @Override public boolean hasCustomEntity(ItemStack stack) { return true; @@ -181,11 +228,8 @@ public class ItemGiantEgg extends BaseItemBurnable { @Override public Entity createEntity(World world, Entity location, ItemStack itemstack) { - if (location instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer) location; - if (itemstack == null) { return null; } @@ -217,27 +261,40 @@ public class ItemGiantEgg extends BaseItemBurnable { @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"); - } + long age = 0; + long life = 0; int expected = 0; - if (NBTUtils.hasKey(stack, "mExpected")){ - expected = NBTUtils.getInteger(stack, "mExpected"); + if (this.descriptionString.length > 0) { + list.add(EnumChatFormatting.GRAY+this.descriptionString[0]); } - list.add("Egg Size: "+size+" ounces"); - list.add("Expected Stem Cells: "+expected); - list.add("Age: "+(age/20)+"s"+" / "+(life/20)+"s"); + if (NBTUtils.hasKey(stack, "size")){ + size = NBTUtils.getInteger(stack, "size"); + if (size > 0 && NBTUtils.hasKey(stack, "TickableItem")){ + NBTTagCompound aNBT = stack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + age = aNBT.getLong("Tick"); + } + } + } + if (NBTUtils.hasKey(stack, "mEggAge")){ + life = NBTUtils.getInteger(stack, "mEggAge"); + } + if (NBTUtils.hasKey(stack, "mExpected")){ + expected = NBTUtils.getInteger(stack, "mExpected"); + } + } + String aSize = size > 0 ? ""+size : "??"; + String aExpected = expected > 0 ? ""+expected : "??"; + String aAge = age > 0 ? ""+(age/20) : "??"; + String aLife = life > 0 ? ""+(life/20) : "??"; + list.add("Egg Size: "+aSize+" ounces"); + list.add("Expected Stem Cells: "+aExpected); + list.add("Age: "+aAge+"s"+" / "+aLife+"s"); list.add("Larger eggs take longer to hatch,"); - list.add("but have a better chance of hatching."); - super.addInformation(stack, aPlayer, list, bool); + list.add("but have a better chance of hatching."); + } } diff --git a/src/Java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java b/src/Java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java new file mode 100644 index 0000000000..727b933fa7 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java @@ -0,0 +1,285 @@ +package gtPlusPlus.core.item.general.spawn; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.*; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.*; +import net.minecraft.util.*; +import net.minecraft.world.World; + +public class ItemCustomSpawnEgg extends ItemMonsterPlacer { + + private static final HashMap mIconMap = new HashMap(); + private static int mTotalMetaItems = 0; + + private static final HashMap mMaxStackSizeMap = new HashMap(); + private static final HashMap mRarityMap = new HashMap(); + private static final HashMap> mOreDictNames = new HashMap>(); + + private static final HashMap mColourBaseMap = new HashMap(); + private static final HashMap mColourSpotsMap = new HashMap(); + private static final HashMap mEntityNameMap = new HashMap(); + private static final HashMap mEntityFullNameMap = new HashMap(); + + private static final HashMap mReverseEntityMap = new HashMap(); + + protected EntityLiving entityToSpawn = null; + + public static ItemStack getSpawnEggForEntityname(String aEntityName, int aSize) { + return ItemUtils.simpleMetaStack(ModItems.itemCustomSpawnEgg, mReverseEntityMap.get(aEntityName), aSize); + } + + public static void registerEntityForSpawnEgg(final int aMetaID, String parEntityToSpawnName, int aPrimaryColor, int aSecondaryColor) { + registerEntityForSpawnEgg(aMetaID, parEntityToSpawnName, aPrimaryColor, aSecondaryColor, EnumRarity.common, new ArrayList()); + } + + public static void registerEntityForSpawnEgg(final int aMetaID, String parEntityToSpawnName, int aPrimaryColor, int aSecondaryColor, EnumRarity aRarity, final ArrayList aOreDictNames) { + mTotalMetaItems++; + mMaxStackSizeMap.put(aMetaID, 64); + mRarityMap.put(aMetaID, aRarity); + mOreDictNames.put(aMetaID, aOreDictNames); + mColourBaseMap.put(aMetaID, aPrimaryColor); + mColourSpotsMap.put(aMetaID, aSecondaryColor); + mReverseEntityMap.put(parEntityToSpawnName, aMetaID); + setEntityToSpawnName(aMetaID, parEntityToSpawnName); + } + + public static void registerEggsToOreDict() { + for (int aMetaID = 0; aMetaID < mTotalMetaItems; aMetaID++) { + ArrayList aOreDictNames = mOreDictNames.get(aMetaID); + if (aOreDictNames != null && !aOreDictNames.isEmpty()) { + ItemStack aFoodStack = ItemUtils.simpleMetaStack(ModItems.itemCustomSpawnEgg, aMetaID, 1 + ); + for (String aOreName : aOreDictNames) { + ItemUtils.addItemToOreDictionary(aFoodStack, aOreName); + } + } + } + } + + public ItemCustomSpawnEgg() { + super(); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + this.setUnlocalizedName("BasicMetaSpawnEgg"); + GameRegistry.registerItem(this, this.getUnlocalizedName()); + } + + /** + * Callback for item usage. If the item does something special on right + * clicking, + * + * he will have one of those. Return True if something happen and false if + * it don't. This is for ITEMS, not BLOCKS + */ + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){ + if (par3World.isRemote) { + return true; + } + else { + Block block = par3World.getBlock(par4, par5, par6); + par4 += Facing.offsetsXForSide[par7]; + par5 += Facing.offsetsYForSide[par7]; + par6 += Facing.offsetsZForSide[par7]; + double d0 = 0.0D; + + if (par7 == 1 && block.getRenderType() == 11) { + d0 = 0.5D; + } + + Entity entity = spawnEntity(par1ItemStack, par3World, par4 + 0.5D, par5 + d0, par6 + 0.5D); + + if (entity != null) { + if (entity instanceof EntityLivingBase + && par1ItemStack.hasDisplayName()) { + ((EntityLiving) entity).setCustomNameTag( + par1ItemStack.getDisplayName() + ); + } + + if (!par2EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + + return true; + } + } + + /** + * Called whenever this item is equipped and the right mouse button is + * pressed. + * + * Args: itemStack, world, entityPlayer + */ + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { + if (par2World.isRemote) { + return par1ItemStack; + } + else { + MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true); + + if (movingobjectposition == null) { + return par1ItemStack; + } + else { + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + + if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) { + return par1ItemStack; + } + + if (!par3EntityPlayer.canPlayerEdit( + i, j, k, movingobjectposition + + .sideHit, par1ItemStack + )) { + return par1ItemStack; + } + + if (par2World.getBlock(i, j, k) instanceof BlockLiquid) { + Entity entity = spawnEntity(par1ItemStack, par2World, i, j, k); + + if (entity != null) { + if (entity instanceof EntityLivingBase + && par1ItemStack + + .hasDisplayName()) { + ((EntityLiving) entity).setCustomNameTag( + par1ItemStack + + .getDisplayName() + ); + } + + if (!par3EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + } + } + + return par1ItemStack; + } + } + } + + /** + * Spawns the creature specified by the egg's type in the location specified + * by + * + * the last three parameters. Parameters: world, entityID, x, y, z. + * @param par1ItemStack + */ + public Entity spawnEntity(ItemStack par1ItemStack, World parWorld, double parX, double parY, double parZ) { + + if (!parWorld.isRemote) // never spawn entity on client side + { + int aDamage = par1ItemStack.getItemDamage(); + String entityToSpawnNameFull = mEntityFullNameMap.get(aDamage); + String entityToSpawnName = mEntityNameMap.get(aDamage); + //entityToSpawnNameFull = WildAnimals.MODID + "." + entityToSpawnName; + if (EntityList.stringToClassMapping.containsKey(entityToSpawnNameFull)) { + entityToSpawn = (EntityLiving) EntityList.createEntityByName(entityToSpawnNameFull, parWorld); + entityToSpawn.setLocationAndAngles(parX, parY, parZ, MathHelper.wrapAngleTo180_float(parWorld.rand.nextFloat() * 360.0F), 0.0F); + parWorld.spawnEntityInWorld(entityToSpawn); + entityToSpawn.onSpawnWithEgg((IEntityLivingData) null); + entityToSpawn.playLivingSound(); + } + else { + // DEBUG + System.out.println("Entity not found " + entityToSpawnName); + } + } + + return entityToSpawn; + } + + /** + * returns a list of items with the same ID, but different meta (eg: dye + * returns 16 items) + */ + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + for (int aMeta : mReverseEntityMap.values()) { + aList.add(ItemUtils.simpleMetaStack(aItem, aMeta, 1)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack par1ItemStack, int parColorType) { + int aID = par1ItemStack.getItemDamage(); + return (parColorType == 0) ? mColourBaseMap.get(aID) : mColourSpotsMap.get(aID); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + // Doing this override means that there is no localization for language + // unless you specifically check for localization here and convert + public String getItemStackDisplayName(ItemStack par1ItemStack) { + return "Spawn " + mEntityNameMap.get(par1ItemStack.getItemDamage()); + } + + + @Override + public void registerIcons(final IIconRegister u) { + mIconMap.put(0, u.registerIcon(CORE.MODID + ":" + "spawn_egg")); + mIconMap.put(1, u.registerIcon(CORE.MODID + ":" + "spawn_egg_overlay")); + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int renderPass) { + return mIconMap.get(renderPass); + } + + @Override + public IIcon getIconFromDamage(int damage) { + return getIconFromDamageForRenderPass(0, 0); + } + + @Override + public IIcon getIcon(ItemStack aStack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { + return getIconFromDamageForRenderPass(0, renderPass); + } + + @Override + public IIcon getIcon(ItemStack aStack, int renderPass) { + return getIconFromDamageForRenderPass(0, renderPass); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return super.getUnlocalizedName() + "." + stack.getItemDamage(); + } + + public static void setEntityToSpawnName(int aMetaID, String parEntityToSpawnName) { + mEntityNameMap.put(aMetaID, parEntityToSpawnName); + mEntityFullNameMap.put(aMetaID, CORE.MODID + "." + parEntityToSpawnName); + } +} diff --git a/src/Java/gtPlusPlus/core/item/materials/DustDecayable.java b/src/Java/gtPlusPlus/core/item/materials/DustDecayable.java index 9994c7d362..d42ac85012 100644 --- a/src/Java/gtPlusPlus/core/item/materials/DustDecayable.java +++ b/src/Java/gtPlusPlus/core/item/materials/DustDecayable.java @@ -64,7 +64,7 @@ public class DustDecayable extends BaseItemTickable { } boolean a1, a2; - a1 = this.getIsActive(world, iStack); + a1 = this.isTicking(world, iStack); a2 = tickItemTag(world, iStack); if (!a1 && !a2) { -- cgit