aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/item/general
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2021-05-20 23:07:24 +0000
committerAlkalus <draknyte1@hotmail.com>2021-05-20 23:07:24 +0000
commit7881c840421c191e8c4249fc303e184fa1cbf9a8 (patch)
tree0e1f8d8d19ca14e14dfb16c1ed49750935612dfa /src/Java/gtPlusPlus/core/item/general
parentde40c882cb16535deae1c29b22f1a535747db536 (diff)
parent5316a0ffcbc403e17a06d4c9e28d57e202f0aafe (diff)
downloadGT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.gz
GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.bz2
GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.zip
Merged in MultiFixes (pull request #11)
MultiFixes
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java147
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java351
-rw-r--r--src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java8
-rw-r--r--src/Java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java285
4 files changed, 640 insertions, 151 deletions
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java b/src/Java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java
new file mode 100644
index 0000000000..bd8159eb01
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java
@@ -0,0 +1,147 @@
+package gtPlusPlus.core.item.general;
+import java.util.List;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IIcon;
+
+import gtPlusPlus.core.creative.AddToCreativeTab;
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.Utils;
+
+public class ItemBasicScrubberTurbine extends Item {
+
+ public IIcon[] icons = new IIcon[1];
+
+ public ItemBasicScrubberTurbine() {
+ super();
+ this.setHasSubtypes(true);
+ String unlocalizedName = "itemBasicTurbine";
+ this.setUnlocalizedName(unlocalizedName);
+ this.setCreativeTab(AddToCreativeTab.tabMisc);
+ this.setMaxStackSize(1);
+ GameRegistry.registerItem(this, unlocalizedName);
+ }
+
+ @Override
+ public void registerIcons(IIconRegister reg) {
+ this.icons[0] = reg.registerIcon(CORE.MODID + ":" + "itemBasicTurbine");
+ }
+
+ @Override
+ public IIcon getIconFromDamage(int meta) {
+ return this.icons[0];
+ }
+
+ @Override
+ public void getSubItems(Item item, CreativeTabs tab, List list) {
+ for (int i = 0; i < 2; i ++) {
+ list.add(new ItemStack(item, 1, i));
+ }
+ }
+
+ @Override
+ public String getUnlocalizedName(ItemStack stack) {
+ return this.getUnlocalizedName() + "_" + stack.getItemDamage();
+ }
+
+ @Override
+ public String getItemStackDisplayName(final ItemStack tItem) {
+ if (tItem == null) {
+ return "Basic Turbine";
+ }
+ return super.getItemStackDisplayName(tItem);
+ }
+
+ @Override
+ public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) {
+ int meta = stack.getItemDamage();
+ if (meta == 0){
+ HEX_OxFFFFFF = Utils.rgbtoHexValue(200,200,200);
+ }
+ if (meta == 1){
+ HEX_OxFFFFFF = Utils.rgbtoHexValue(255,128,0);
+ }
+ return HEX_OxFFFFFF;
+ }
+
+ private static boolean createNBT(ItemStack rStack){
+ final NBTTagCompound tagMain = new NBTTagCompound();
+ final NBTTagCompound tagNBT = new NBTTagCompound();
+ tagNBT.setLong("Damage", 0);
+ tagMain.setTag("BasicTurbine", tagNBT);
+ rStack.setTagCompound(tagMain);
+ return true;
+ }
+
+ public static final long getFilterDamage(final ItemStack aStack) {
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ if (aNBT != null) {
+ aNBT = aNBT.getCompoundTag("BasicTurbine");
+ if (aNBT != null) {
+ return aNBT.getLong("Damage");
+ }
+ }
+ else {
+ createNBT(aStack);
+ }
+ return 0L;
+ }
+
+ public static final boolean setFilterDamage(final ItemStack aStack, final long aDamage) {
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ if (aNBT != null) {
+ aNBT = aNBT.getCompoundTag("BasicTurbine");
+ if (aNBT != null) {
+ aNBT.setLong("Damage", aDamage);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int getMaxDurability(ItemStack aStack) {
+ if (aStack != null) {
+ int aMeta = aStack.getItemDamage();
+ if (aMeta == 0) {
+ return 2500;
+ }
+ if (aMeta == 1) {
+ return 5000;
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public double getDurabilityForDisplay(ItemStack stack) {
+ if (stack.getTagCompound() == null){
+ createNBT(stack);
+ }
+ double currentDamage = getFilterDamage(stack);
+ double meta = getMaxDurability(stack);
+ double durabilitypercent = currentDamage / meta;
+ return durabilitypercent;
+ }
+
+ @Override
+ public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
+ list.add(EnumChatFormatting.GRAY+"An early tier Turbine for Atmospheric Reconditioning.");
+ int maxDamage = getMaxDurability(stack);
+ list.add(EnumChatFormatting.GRAY+""+(maxDamage-getFilterDamage(stack))+"/"+maxDamage+" uses left.");
+ super.addInformation(stack, player, list, bool);
+ }
+
+ @Override
+ public boolean showDurabilityBar(ItemStack stack) {
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
index d98b27d163..b3338bb681 100644
--- a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
+++ b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
@@ -4,188 +4,232 @@ import static gtPlusPlus.core.lib.CORE.RANDOM;
import java.util.List;
-import gregtech.api.enums.ItemList;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.entity.item.ItemEntityGiantEgg;
-import gtPlusPlus.core.item.base.BaseItemBurnable;
+import gtPlusPlus.core.item.base.BaseItemTickable;
+import gtPlusPlus.core.item.general.spawn.ItemCustomSpawnEgg;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.NBTUtils;
-import net.minecraft.creativetab.CreativeTabs;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.client.renderer.texture.IIconRegister;
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.nbt.NBTTagCompound;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
-import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
-public class ItemGiantEgg extends BaseItemBurnable {
+public class ItemGiantEgg extends BaseItemTickable {
- public ItemGiantEgg(String unlocalizedName, String displayName, CreativeTabs creativeTab, int stackSize, int maxDmg,
- String description, String oredictName, int burnTime, int meta) {
- super(unlocalizedName, displayName, creativeTab, stackSize, maxDmg, description, oredictName, burnTime, meta);
- this.setMaxStackSize(1);
- }
+ private static ItemStack turnsIntoItem;
+ private static ItemStack mCorrectEgg;
+ private static ItemStack mCorrectStemCells;
- @Override
- public String getItemStackDisplayName(ItemStack aStack) {
- String localName = super.getItemStackDisplayName(aStack);
- nbtWork(aStack);
- int size = 1;
- if (NBTUtils.hasKey(aStack, "size")){
- size = NBTUtils.getInteger(aStack, "size");
- return ""+size+" "+localName;
- }
- return "?? "+localName;
+ public void registerFuel(int burn){
+ CORE.burnables.add(new Pair<Integer, ItemStack>(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<Byte.MAX_VALUE;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;
+ return mCorrectEgg;
}
}
- }
+ }
+ }*/
+ ItemStack aTempEgg = ItemCustomSpawnEgg.getSpawnEggForEntityname("bigChickenFriendly", 1);
+ if (aTempEgg != null) {
+ mCorrectEgg = aTempEgg;
+ }
+ }
+ return mCorrectEgg;
+ }
- 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")+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<mSize;u++) {
+ eggYolks[u] = ItemUtils.getSimpleStack(aStemCells, MathUtils.randInt(1, 4));
}
- if (player && !NBTUtils.hasKey(aStack, "mEggAge") && NBTUtils.hasKey(aStack, "size")) {
- NBTUtils.setInteger(aStack, "mEggAge", ((MathUtils.randInt(8000, 16000)*NBTUtils.getInteger(aStack, "size"))/2));
+ int mexpected = 0;
+ for (ItemStack e : eggYolks) {
+ if (e != null) {
+ mexpected += e.stackSize;
+ }
}
+ if (mexpected > 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<mSize;u++) {
- eggYolks[u] = ItemUtils.getSimpleStack(mCorrectStemCells, MathUtils.randInt(1, 4));
- }
+ @Override
+ public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, final boolean p_77663_5_) {
+ if (world == null || iStack == null) {
+ return;
+ }
+ if (world.isRemote) {
+ return;
+ }
+ if (iStack.getTagCompound() == null || !iStack.getTagCompound().hasKey("size")) {
+ this.createNBT(world, iStack);
+ Logger.INFO("Egg has no NBT, creating (onUpdate)");
+ }
+ boolean a1, a2;
+ a1 = this.isTicking(world, iStack);
+ a2 = a1 ? tickItemTag(world, iStack) : false;
- int mexpected = 0;
- for (ItemStack e : eggYolks) {
- if (e != null) {
- mexpected += e.stackSize;
+ //Logger.INFO("Is Ticking? "+a1);
+ //Logger.INFO("Did Tick? "+a2);
+ if (!a1 && !a2) {
+ if (entityHolding instanceof EntityPlayer){
+ if (MathUtils.randInt(0, 1000) >= 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<u;l++){
+ ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this);
+ }
+ }
+ else {
+ tempTransform.stackSize=1;
+ ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform));
+ ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this);
+ }
}
}
- if (mexpected > 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;
}
@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/books/ItemBaseBook.java b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java
index 2f49ac1287..9ac09b92e4 100644
--- a/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java
+++ b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java
@@ -26,6 +26,7 @@ import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.handler.BookHandler;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.NBTUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
@@ -54,9 +55,6 @@ public class ItemBaseBook extends ItemWritableBook{
mBookMap.get(i).mPages);*/
NBTUtils.createIntegerTagCompound(bookstack, "stats", "mMeta", i);
-
- GT_OreDictUnificator.registerOre("bookWritten", bookstack);
- GT_OreDictUnificator.registerOre("craftingBook", bookstack);
list.add(bookstack);
}
}
@@ -106,7 +104,9 @@ public class ItemBaseBook extends ItemWritableBook{
public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
//player.displayGUIBook(item);
int i = item.getItemDamage();
- ItemStack bookstack = GT_Utility.getWrittenBook(
+ ItemStack bookstack = Utils.getWrittenBook(
+ null,
+ mBookMap.get(i).mMeta,
mBookMap.get(i).mMapping,
mBookMap.get(i).mTitle,
mBookMap.get(i).mAuthor,
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<Integer, IIcon> mIconMap = new HashMap<Integer, IIcon>();
+ private static int mTotalMetaItems = 0;
+
+ private static final HashMap<Integer, Integer> mMaxStackSizeMap = new HashMap<Integer, Integer>();
+ private static final HashMap<Integer, EnumRarity> mRarityMap = new HashMap<Integer, EnumRarity>();
+ private static final HashMap<Integer, ArrayList<String>> mOreDictNames = new HashMap<Integer, ArrayList<String>>();
+
+ private static final HashMap<Integer, Integer> mColourBaseMap = new HashMap<Integer, Integer>();
+ private static final HashMap<Integer, Integer> mColourSpotsMap = new HashMap<Integer, Integer>();
+ private static final HashMap<Integer, String> mEntityNameMap = new HashMap<Integer, String>();
+ private static final HashMap<Integer, String> mEntityFullNameMap = new HashMap<Integer, String>();
+
+ private static final HashMap<String, Integer> mReverseEntityMap = new HashMap<String, Integer>();
+
+ 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<String>());
+ }
+
+ public static void registerEntityForSpawnEgg(final int aMetaID, String parEntityToSpawnName, int aPrimaryColor, int aSecondaryColor, EnumRarity aRarity, final ArrayList<String> 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<String> 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);
+ }
+}