From 12dab5d109ac81034fd0a8fe18317024a996af61 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 24 Dec 2018 03:59:59 +0000 Subject: + Added a config option to adjust the Turbine Rotor removal cut-off point. + Added some new Bags/Packs for various things. An Automatic Lunchbox, a Tool Box and a Magicians Satchel. + Added full compound of Eglin Steel to ABS. Closes #392. - Removed all Multi-Tools. $ Rewrote and Fixed the recipe system. All recipes are queued regardless of when called, then created during the end of the POST_INIT load phase. Fixes too many bugs to list. (Few more to do before tomorrow) $ Fixed COFH Hard requirement. Closes #398. % Adjusted the internal map type of the AutoMap. Should improve performance, if only in single digit cpu cycles. > To-Do) Fix Recipes pertaining to compound materials made from using fluids. State may be detected wrong after recipe system changes. --- src/Java/gtPlusPlus/GTplusplus.java | 5 + .../gtPlusPlus/api/objects/GregtechException.java | 28 + src/Java/gtPlusPlus/api/objects/data/AutoMap.java | 5 +- .../core/block/base/BlockBaseModular.java | 67 ++- src/Java/gtPlusPlus/core/config/ConfigHandler.java | 1 + .../core/container/box/LunchBoxContainer.java | 13 + .../core/container/box/MagicBagContainer.java | 13 + .../core/container/box/ToolBoxContainer.java | 15 + .../gtPlusPlus/core/gui/item/box/GuiBaseBox.java | 116 ++++ .../gtPlusPlus/core/gui/item/box/LunchBoxGui.java | 11 + .../gtPlusPlus/core/gui/item/box/MagicBagGui.java | 11 + .../gtPlusPlus/core/gui/item/box/ToolBoxGui.java | 11 + src/Java/gtPlusPlus/core/handler/GuiHandler.java | 40 +- .../core/inventories/box/LunchBoxInventory.java | 15 + .../core/inventories/box/MagicBagInventory.java | 15 + .../core/inventories/box/ToolBoxInventory.java | 16 + src/Java/gtPlusPlus/core/item/ModItems.java | 37 +- .../core/item/base/BaseItemComponent.java | 1 + .../core/item/base/dusts/BaseItemDustUnique.java | 31 +- .../core/item/base/ore/BaseOreComponent.java | 52 +- .../core/item/base/rods/BaseItemRod.java | 2 + .../core/item/base/rods/BaseItemRodLong.java | 15 +- .../core/item/tool/misc/box/AutoLunchBox.java | 11 + .../core/item/tool/misc/box/BaseBoxItem.java | 59 ++ .../core/item/tool/misc/box/ContainerBoxBase.java | 328 +++++++++++ .../item/tool/misc/box/CustomBoxInventory.java | 243 ++++++++ .../core/item/tool/misc/box/MagicToolBag.java | 11 + .../core/item/tool/misc/box/UniversalToolBox.java | 13 + src/Java/gtPlusPlus/core/lib/CORE.java | 1 + src/Java/gtPlusPlus/core/material/ELEMENT.java | 2 +- src/Java/gtPlusPlus/core/material/Material.java | 52 +- .../core/material/MaterialGenerator.java | 13 +- .../gtPlusPlus/core/recipe/RECIPES_GREGTECH.java | 54 +- .../gtPlusPlus/core/recipe/RECIPES_General.java | 130 +++++ .../gtPlusPlus/core/recipe/RECIPES_Machines.java | 4 +- src/Java/gtPlusPlus/core/slots/SlotLunchBox.java | 30 + .../gtPlusPlus/core/slots/SlotMagicToolBag.java | 29 + src/Java/gtPlusPlus/core/slots/SlotToolBox.java | 113 ++++ src/Java/gtPlusPlus/core/util/Utils.java | 42 ++ .../gtPlusPlus/core/util/minecraft/FoodUtils.java | 60 ++ .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 648 +++++++++++---------- .../core/util/minecraft/RecipeUtils.java | 31 + .../ClassTransformer_OB_Sprinkler.java | 594 ------------------- .../forestry/bees/custom/GTPP_Bee_Definition.java | 2 +- src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java | 10 +- .../xmod/gregtech/api/enums/GregtechItemList.java | 5 +- .../gregtech/loaders/RecipeGen_AlloySmelter.java | 9 +- .../xmod/gregtech/loaders/RecipeGen_Assembler.java | 2 + .../gregtech/loaders/RecipeGen_DustGeneration.java | 126 ++-- .../xmod/gregtech/loaders/RecipeGen_Extruder.java | 63 +- .../xmod/gregtech/loaders/RecipeGen_Fluids.java | 31 +- .../xmod/gregtech/loaders/RecipeGen_Ore.java | 16 +- .../xmod/gregtech/loaders/RecipeGen_Plates.java | 7 + .../xmod/gregtech/loaders/RecipeGen_Recycling.java | 10 +- .../gregtech/loaders/RecipeGen_ShapedCrafting.java | 174 +++--- .../registration/gregtech/GregtechConduits.java | 12 +- .../gregtech/GregtechCustomHatches.java | 51 -- .../gregtech/GregtechPollutionDevices.java | 8 +- 58 files changed, 2257 insertions(+), 1257 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/objects/GregtechException.java create mode 100644 src/Java/gtPlusPlus/core/container/box/LunchBoxContainer.java create mode 100644 src/Java/gtPlusPlus/core/container/box/MagicBagContainer.java create mode 100644 src/Java/gtPlusPlus/core/container/box/ToolBoxContainer.java create mode 100644 src/Java/gtPlusPlus/core/gui/item/box/GuiBaseBox.java create mode 100644 src/Java/gtPlusPlus/core/gui/item/box/LunchBoxGui.java create mode 100644 src/Java/gtPlusPlus/core/gui/item/box/MagicBagGui.java create mode 100644 src/Java/gtPlusPlus/core/gui/item/box/ToolBoxGui.java create mode 100644 src/Java/gtPlusPlus/core/inventories/box/LunchBoxInventory.java create mode 100644 src/Java/gtPlusPlus/core/inventories/box/MagicBagInventory.java create mode 100644 src/Java/gtPlusPlus/core/inventories/box/ToolBoxInventory.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/AutoLunchBox.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/BaseBoxItem.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/ContainerBoxBase.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/CustomBoxInventory.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/MagicToolBag.java create mode 100644 src/Java/gtPlusPlus/core/item/tool/misc/box/UniversalToolBox.java create mode 100644 src/Java/gtPlusPlus/core/slots/SlotLunchBox.java create mode 100644 src/Java/gtPlusPlus/core/slots/SlotMagicToolBag.java create mode 100644 src/Java/gtPlusPlus/core/slots/SlotToolBox.java create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/FoodUtils.java delete mode 100644 src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_OB_Sprinkler.java (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 92c7a9a049..077efe102a 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -77,9 +77,14 @@ public class GTplusplus implements ActionListener { mPrev.setPhaseActive(false); } mIsPhaseActive = aIsPhaseActive; + if (CURRENT_LOAD_PHASE != this) { + CURRENT_LOAD_PHASE = this; + } } } + public static INIT_PHASE CURRENT_LOAD_PHASE = INIT_PHASE.SUPER; + //Mod Instance @Mod.Instance(CORE.MODID) public static GTplusplus instance; diff --git a/src/Java/gtPlusPlus/api/objects/GregtechException.java b/src/Java/gtPlusPlus/api/objects/GregtechException.java new file mode 100644 index 0000000000..916dbc4aaf --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/GregtechException.java @@ -0,0 +1,28 @@ +package gtPlusPlus.api.objects; + +public class GregtechException extends Throwable { + + private static final long serialVersionUID = 3601884582161841486L; + + public GregtechException(String aError) { + this(aError, true); + } + + public GregtechException(String aError, boolean aIsVerbose) { + Logger.ERROR("Throwing GT++ Exception!"); + Logger.ERROR("[EXCEPTION] "+aError); + if (aIsVerbose) { + Logger.INFO("Throwing GT++ Exception!"); + Logger.INFO("[EXCEPTION] "+aError); + printStackTrace(); + } + } + + @Override + public void printStackTrace() { + super.printStackTrace(); + } + + + +} diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java index 45cce2eee5..ca231dbd63 100644 --- a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java +++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java @@ -19,12 +19,12 @@ public class AutoMap implements Iterable, Cloneable, Serializable { public AutoMap() { - this(new HashMap()); + this(new LinkedHashMap()); } public AutoMap(Map defaultMapType) { mInternalMap = defaultMapType; - mInternalNameMap = new HashMap(); + mInternalNameMap = new LinkedHashMap(); } @Override @@ -86,6 +86,7 @@ public class AutoMap implements Iterable, Cloneable, Serializable { public synchronized boolean clear(){ this.mInternalID = 0; this.mInternalMap.clear(); + this.mInternalNameMap.clear(); return true; } diff --git a/src/Java/gtPlusPlus/core/block/base/BlockBaseModular.java b/src/Java/gtPlusPlus/core/block/base/BlockBaseModular.java index b089688193..8310fa3c23 100644 --- a/src/Java/gtPlusPlus/core/block/base/BlockBaseModular.java +++ b/src/Java/gtPlusPlus/core/block/base/BlockBaseModular.java @@ -1,14 +1,19 @@ package gtPlusPlus.core.block.base; +import java.util.HashMap; +import java.util.Map; + import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; import net.minecraft.world.IBlockAccess; +import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TextureSet; import gregtech.api.util.GT_OreDictUnificator; - +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.base.itemblock.ItemBlockGtBlock; import gtPlusPlus.core.item.base.itemblock.ItemBlockGtFrameBox; import gtPlusPlus.core.lib.CORE; @@ -34,6 +39,7 @@ public class BlockBaseModular extends BasicBlock { this(material.getUnlocalizedName(), material.getLocalizedName(), net.minecraft.block.material.Material.iron, blockType, colour, Math.min(Math.max(material.vTier, 1), 6)); blockMaterial = material; + registerComponent(); } protected BlockBaseModular(final String unlocalizedName, final String blockMaterial, @@ -47,8 +53,8 @@ public class BlockBaseModular extends BasicBlock { this.thisBlockMaterial = blockMaterial; this.thisBlockType = blockType.name().toUpperCase(); this.setBlockName(this.GetProperName()); - - if (this.thisBlockType.equals(BlockTypes.STANDARD.name().toUpperCase())) { + int fx = getBlockTypeMeta(); + if (fx == 0) { GameRegistry.registerBlock(this, ItemBlockGtBlock.class, Utils.sanitizeString(blockType.getTexture() + unlocalizedName)); GT_OreDictUnificator.registerOre( @@ -56,7 +62,7 @@ public class BlockBaseModular extends BasicBlock { .replace("Of", "").replace("Block", "").replace("-", "").replace("_", "").replace(" ", ""), ItemUtils.getSimpleStack(this)); } - else if (this.thisBlockType.equals(BlockTypes.FRAME.name().toUpperCase())) { + else if (fx == 1) { GameRegistry.registerBlock(this, ItemBlockGtBlock.class, Utils.sanitizeString(blockType.getTexture() + unlocalizedName)); GT_OreDictUnificator.registerOre( @@ -64,7 +70,7 @@ public class BlockBaseModular extends BasicBlock { .replace("-", "").replace("_", "").replace(" ", "").replace("FrameBox", ""), ItemUtils.getSimpleStack(this)); } - else if (this.thisBlockType.equals(BlockTypes.ORE.name().toUpperCase())) { + else if (fx == 2) { GameRegistry.registerBlock(this, ItemBlockGtBlock.class, Utils.sanitizeString(blockType.getTexture() + unlocalizedName)); GT_OreDictUnificator.registerOre( @@ -72,7 +78,47 @@ public class BlockBaseModular extends BasicBlock { .replace("Of", "").replace("Block", "").replace("-", "").replace("_", "").replace(" ", ""), ItemUtils.getSimpleStack(this)); } - + } + + public boolean registerComponent() { + Logger.MATERIALS("Attempting to register "+this.getUnlocalizedName()+"."); + if (this.blockMaterial == null) { + Logger.MATERIALS("Tried to register "+this.getUnlocalizedName()+" but the material was null."); + return false; + } + String aName = blockMaterial.getUnlocalizedName(); + //Register Component + Map aMap = Material.mComponentMap.get(aName); + if (aMap == null) { + aMap = new HashMap(); + } + int fx = getBlockTypeMeta(); + String aKey = (fx == 0 ? OrePrefixes.block.name() : ( fx == 1 ? OrePrefixes.frameGt.name() : OrePrefixes.ore.name())); + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS("Registering a material component. Item: ["+aName+"] Map: ["+aKey+"]"); + Material.mComponentMap.put(aName, aMap); + return true; + } + else { + //Bad + Logger.MATERIALS("Tried to double register a material component."); + return false; + } + } + + public int getBlockTypeMeta() { + if (this.thisBlockType.equals(BlockTypes.STANDARD.name().toUpperCase())) { + return 0; + } + else if (this.thisBlockType.equals(BlockTypes.FRAME.name().toUpperCase())) { + return 1; + } + else if (this.thisBlockType.equals(BlockTypes.ORE.name().toUpperCase())) { + return 2; + } + return 0; } /** @@ -153,4 +199,13 @@ public class BlockBaseModular extends BasicBlock { return this.blockColour; } + @Override + public int getBlockColor() { + if (this.blockColour == 0) { + return MathUtils.generateSingularRandomHexValue(); + } + + return this.blockColour; + } + } diff --git a/src/Java/gtPlusPlus/core/config/ConfigHandler.java b/src/Java/gtPlusPlus/core/config/ConfigHandler.java index 4c992ed8f4..d5a43ab883 100644 --- a/src/Java/gtPlusPlus/core/config/ConfigHandler.java +++ b/src/Java/gtPlusPlus/core/config/ConfigHandler.java @@ -66,6 +66,7 @@ public class ConfigHandler { "Adds GT6 recipes for Sulfuric Acid. Should remove all pre-existing recipes."); enableAnimatedTurbines = config.getBoolean("enableAnimatedTurbines", "gregtech", true, "Gives GT Gas/Steam turbines animated textures while running."); + turbineCutoffBase = config.getInt("turbineCutoffBase", "gregtech", 75000, 0, Integer.MAX_VALUE, "Rotors below this durability will be removed, prevents NEI clutter. Minimum Durability is N * x, where N is the new value set and x is the turbine size, where 1 is Tiny and 4 is Huge. Set to 0 to disable."); // Pipes & Cables enableCustom_Pipes = config.getBoolean("enableCustom_Pipes", "gregtech", true, diff --git a/src/Java/gtPlusPlus/core/container/box/LunchBoxContainer.java b/src/Java/gtPlusPlus/core/container/box/LunchBoxContainer.java new file mode 100644 index 0000000000..8e56c661f2 --- /dev/null +++ b/src/Java/gtPlusPlus/core/container/box/LunchBoxContainer.java @@ -0,0 +1,13 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotLunchBox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class LunchBoxContainer extends ContainerBoxBase { + public LunchBoxContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotLunchBox.class, gtPlusPlus.core.item.tool.misc.box.AutoLunchBox.SLOTS); + } +} diff --git a/src/Java/gtPlusPlus/core/container/box/MagicBagContainer.java b/src/Java/gtPlusPlus/core/container/box/MagicBagContainer.java new file mode 100644 index 0000000000..7820d56814 --- /dev/null +++ b/src/Java/gtPlusPlus/core/container/box/MagicBagContainer.java @@ -0,0 +1,13 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotMagicToolBag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class MagicBagContainer extends ContainerBoxBase { + public MagicBagContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotMagicToolBag.class, gtPlusPlus.core.item.tool.misc.box.MagicToolBag.SLOTS); + } +} diff --git a/src/Java/gtPlusPlus/core/container/box/ToolBoxContainer.java b/src/Java/gtPlusPlus/core/container/box/ToolBoxContainer.java new file mode 100644 index 0000000000..49719aa9ba --- /dev/null +++ b/src/Java/gtPlusPlus/core/container/box/ToolBoxContainer.java @@ -0,0 +1,15 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.item.tool.misc.box.UniversalToolBox; +import gtPlusPlus.core.slots.SlotToolBox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class ToolBoxContainer extends ContainerBoxBase { + public ToolBoxContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, + CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotToolBox.class, UniversalToolBox.SLOTS); + } +} diff --git a/src/Java/gtPlusPlus/core/gui/item/box/GuiBaseBox.java b/src/Java/gtPlusPlus/core/gui/item/box/GuiBaseBox.java new file mode 100644 index 0000000000..97ec58bfa4 --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/item/box/GuiBaseBox.java @@ -0,0 +1,116 @@ +package gtPlusPlus.core.gui.item.box; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; + +public class GuiBaseBox extends GuiContainer { + /** + * x and y size of the inventory window in pixels. Defined as float, passed as + * int These are used for drawing the player model. + */ + private float xSize_lo; + private float ySize_lo; + + /** + * ResourceLocation takes 2 parameters: ModId, path to texture at the location: + * "src/minecraft/assets/modid/" + * + * I have provided a sample texture file that works with this tutorial. Download + * it from Forge_Tutorials/textures/gui/ + */ + private final ResourceLocation iconLocation; + + /** The inventory to render on screen */ + private final CustomBoxInventory inventory; + + public GuiBaseBox(ContainerBoxBase containerItem, ResourceLocation aGuiTexture) { + super(containerItem); + this.inventory = containerItem.getInventoryObject(); + this.iconLocation = aGuiTexture; + } + + /** + * Draws the screen and all the components in it. + */ + public void drawScreen(int par1, int par2, float par3) { + super.drawScreen(par1, par2, par3); + this.xSize_lo = (float) par1; + this.ySize_lo = (float) par2; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the + * items) + */ + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + String s = this.inventory.hasCustomInventoryName() ? this.inventory.getInventoryName() + : I18n.format(this.inventory.getInventoryName()); + this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 0, 4210752); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 26, this.ySize - 96 + 4, 4210752); + } + + /** + * Draw the background layer for the GuiContainer (everything behind the items) + */ + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(iconLocation); + int k = (this.width - this.xSize) / 2; + int l = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); + int i1; + drawPlayerModel(k + 51, l + 75, 30, (float) (k + 51) - this.xSize_lo, (float) (l + 75 - 50) - this.ySize_lo, + this.mc.thePlayer); + } + + /** + * This renders the player model in standard inventory position (in later + * versions of Minecraft / Forge, you can simply call + * GuiInventory.drawEntityOnScreen directly instead of copying this code) + */ + public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) { + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, 50.0F); + GL11.glScalef(-scale, scale, scale); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + float f2 = entity.renderYawOffset; + float f3 = entity.rotationYaw; + float f4 = entity.rotationPitch; + float f5 = entity.prevRotationYawHead; + float f6 = entity.rotationYawHead; + GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F); + entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F; + entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F; + entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F; + entity.rotationYawHead = entity.rotationYaw; + entity.prevRotationYawHead = entity.rotationYaw; + GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); + RenderManager.instance.playerViewY = 180.0F; + RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + entity.renderYawOffset = f2; + entity.rotationYaw = f3; + entity.rotationPitch = f4; + entity.prevRotationYawHead = f5; + entity.rotationYawHead = f6; + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/gui/item/box/LunchBoxGui.java b/src/Java/gtPlusPlus/core/gui/item/box/LunchBoxGui.java new file mode 100644 index 0000000000..28e3913ac8 --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/item/box/LunchBoxGui.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.gui.item.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.util.ResourceLocation; + +public class LunchBoxGui extends GuiBaseBox { + public LunchBoxGui(ContainerBoxBase containerItem) { + super(containerItem, new ResourceLocation(CORE.MODID, "textures/gui/schematic_rocket_GS1.png")); + } +} diff --git a/src/Java/gtPlusPlus/core/gui/item/box/MagicBagGui.java b/src/Java/gtPlusPlus/core/gui/item/box/MagicBagGui.java new file mode 100644 index 0000000000..958cdd3c70 --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/item/box/MagicBagGui.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.gui.item.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.util.ResourceLocation; + +public class MagicBagGui extends GuiBaseBox { + public MagicBagGui(ContainerBoxBase containerItem) { + super(containerItem, new ResourceLocation(CORE.MODID, "textures/gui/schematic_rocket_GS1.png")); + } +} diff --git a/src/Java/gtPlusPlus/core/gui/item/box/ToolBoxGui.java b/src/Java/gtPlusPlus/core/gui/item/box/ToolBoxGui.java new file mode 100644 index 0000000000..c440c017e9 --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/item/box/ToolBoxGui.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.gui.item.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.util.ResourceLocation; + +public class ToolBoxGui extends GuiBaseBox { + public ToolBoxGui(ContainerBoxBase containerItem) { + super(containerItem, new ResourceLocation(CORE.MODID, "textures/gui/schematic_rocket_GS1.png")); + } +} diff --git a/src/Java/gtPlusPlus/core/handler/GuiHandler.java b/src/Java/gtPlusPlus/core/handler/GuiHandler.java index 816b35ea4b..c02425afbf 100644 --- a/src/Java/gtPlusPlus/core/handler/GuiHandler.java +++ b/src/Java/gtPlusPlus/core/handler/GuiHandler.java @@ -11,14 +11,25 @@ import net.minecraft.world.World; import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.container.*; +import gtPlusPlus.core.container.box.LunchBoxContainer; +import gtPlusPlus.core.container.box.MagicBagContainer; +import gtPlusPlus.core.container.box.ToolBoxContainer; import gtPlusPlus.core.gui.beta.Gui_ID_Registry; import gtPlusPlus.core.gui.beta.MU_GuiId; import gtPlusPlus.core.gui.item.GuiBaseBackpack; import gtPlusPlus.core.gui.item.GuiBaseGrindle; +import gtPlusPlus.core.gui.item.box.LunchBoxGui; +import gtPlusPlus.core.gui.item.box.MagicBagGui; +import gtPlusPlus.core.gui.item.box.ToolBoxGui; import gtPlusPlus.core.gui.machine.*; import gtPlusPlus.core.interfaces.IGuiManager; import gtPlusPlus.core.inventories.BaseInventoryBackpack; import gtPlusPlus.core.inventories.BaseInventoryGrindle; +import gtPlusPlus.core.inventories.box.LunchBoxInventory; +import gtPlusPlus.core.inventories.box.MagicBagInventory; +import gtPlusPlus.core.inventories.box.ToolBoxInventory; +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; import gtPlusPlus.core.tileentities.base.TileEntityBase; import gtPlusPlus.core.tileentities.general.TileEntityCircuitProgrammer; import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; @@ -35,6 +46,9 @@ public class GuiHandler implements IGuiHandler { public static final int GUI7 = 6; // Trade table public static final int GUI8 = 7; // Circuit Programmer public static final int GUI9 = 8; // Grindle + public static final int GUI10 = 9; // Universal Toolbox + public static final int GUI11 = 10; // Auto Lunchbox + public static final int GUI12 = 11; // Bag for Magic Tools public static void init() { @@ -83,6 +97,16 @@ public class GuiHandler implements IGuiHandler { if (ID == GUI9) { return new Container_Grindle(player, player.inventory, new BaseInventoryGrindle(player.getHeldItem())); } + //Tool, lunch, magic + if (ID == GUI10) { + return new ToolBoxContainer(player, player.inventory, new ToolBoxInventory(player.getHeldItem())); + } + if (ID == GUI11) { + return new LunchBoxContainer(player, player.inventory, new LunchBoxInventory(player.getHeldItem())); + } + if (ID == GUI12) { + return new MagicBagContainer(player, player.inventory, new MagicBagInventory(player.getHeldItem())); + } return null; } @@ -125,9 +149,21 @@ public class GuiHandler implements IGuiHandler { } if (ID == GUI9) { - return new GuiBaseGrindle( - new Container_Grindle(player, player.inventory, new BaseInventoryGrindle(player.getHeldItem()))); + return new GuiBaseGrindle(new Container_Grindle(player, player.inventory, new BaseInventoryGrindle(player.getHeldItem()))); + } + + + //Tool, lunch, magic + if (ID == GUI10) { + return new ToolBoxGui(new ToolBoxContainer(player, player.inventory, new ToolBoxInventory(player.getHeldItem()))); + } + if (ID == GUI11) { + return new LunchBoxGui(new LunchBoxContainer(player, player.inventory, new LunchBoxInventory(player.getHeldItem()))); + } + if (ID == GUI12) { + return new MagicBagGui(new MagicBagContainer(player, player.inventory, new MagicBagInventory(player.getHeldItem()))); } + return null; } diff --git a/src/Java/gtPlusPlus/core/inventories/box/LunchBoxInventory.java b/src/Java/gtPlusPlus/core/inventories/box/LunchBoxInventory.java new file mode 100644 index 0000000000..03350a3c18 --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/box/LunchBoxInventory.java @@ -0,0 +1,15 @@ +package gtPlusPlus.core.inventories.box; + +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotLunchBox; +import net.minecraft.item.ItemStack; + +public class LunchBoxInventory extends CustomBoxInventory { + public LunchBoxInventory(ItemStack stack) { + super(stack, "Lunch Box", gtPlusPlus.core.item.tool.misc.box.AutoLunchBox.SLOTS); + } + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) { + return SlotLunchBox.isItemValid_STATIC(itemstack); + } +} diff --git a/src/Java/gtPlusPlus/core/inventories/box/MagicBagInventory.java b/src/Java/gtPlusPlus/core/inventories/box/MagicBagInventory.java new file mode 100644 index 0000000000..56b1835113 --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/box/MagicBagInventory.java @@ -0,0 +1,15 @@ +package gtPlusPlus.core.inventories.box; + +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotMagicToolBag; +import net.minecraft.item.ItemStack; + +public class MagicBagInventory extends CustomBoxInventory { + public MagicBagInventory(ItemStack stack) { + super(stack, "Mystic Bag", gtPlusPlus.core.item.tool.misc.box.MagicToolBag.SLOTS); + } + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) { + return SlotMagicToolBag.isItemValid_STATIC(itemstack); + } +} diff --git a/src/Java/gtPlusPlus/core/inventories/box/ToolBoxInventory.java b/src/Java/gtPlusPlus/core/inventories/box/ToolBoxInventory.java new file mode 100644 index 0000000000..30893aeb4b --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/box/ToolBoxInventory.java @@ -0,0 +1,16 @@ +package gtPlusPlus.core.inventories.box; + +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.item.tool.misc.box.UniversalToolBox; +import gtPlusPlus.core.slots.SlotToolBox; +import net.minecraft.item.ItemStack; + +public class ToolBoxInventory extends CustomBoxInventory { + public ToolBoxInventory(ItemStack stack) { + super(stack, "Tool Box", UniversalToolBox.SLOTS); + } + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) { + return SlotToolBox.isItemValid_STATIC(itemstack); + } +} diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index c86c10bb53..cc0b4325f3 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -49,6 +49,9 @@ import gtPlusPlus.core.item.init.ItemsFoods; import gtPlusPlus.core.item.init.ItemsMultiTools; import gtPlusPlus.core.item.materials.DustDecayable; import gtPlusPlus.core.item.tool.misc.SandstoneHammer; +import gtPlusPlus.core.item.tool.misc.box.AutoLunchBox; +import gtPlusPlus.core.item.tool.misc.box.MagicToolBag; +import gtPlusPlus.core.item.tool.misc.box.UniversalToolBox; import gtPlusPlus.core.item.tool.misc.GregtechPump; import gtPlusPlus.core.item.tool.staballoy.*; import gtPlusPlus.core.item.wearable.WearableLoader; @@ -282,6 +285,10 @@ public final class ModItems { public static Fluid fluidZrF4; + public static Item boxTools; + public static Item boxFood; + public static Item boxMagic; + static { Logger.INFO("Items!"); //Default item used when recipes fail, handy for debugging. Let's make sure they exist when this class is called upon. @@ -348,6 +355,12 @@ public final class ModItems { backpack_Gray = new BaseItemBackpack("backpackGray", Utils.rgbtoHexValue(128, 128, 128)); backpack_Black = new BaseItemBackpack("backpackBlack", Utils.rgbtoHexValue(20, 20, 20)); backpack_White = new BaseItemBackpack("backpackWhite", Utils.rgbtoHexValue(240, 240, 240)); + + + //Load Custom Box/bags + boxTools = new UniversalToolBox("Tool Box"); + boxFood = new AutoLunchBox("Eatotron-9000"); + boxMagic = new MagicToolBag("Mystic Bag"); itemBlueprintBase = new ItemBlueprint("itemBlueprint"); @@ -365,19 +378,19 @@ public final class ModItems { * Try generate dusts for missing rare earth materials if they don't exist */ - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGadolinium", 1) == null){ + if (ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGadolinium", 1))){ ItemUtils.generateSpecialUseDusts("Gadolinium", "Gadolinium", Materials.Gadolinium.mElement.name(), Utils.rgbtoHexValue(226, 172, 9)); } - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustYtterbium", 1) == null){ + if (ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustYtterbium", 1))){ ItemUtils.generateSpecialUseDusts("Ytterbium", "Ytterbium", Materials.Ytterbium.mElement.name(), Utils.rgbtoHexValue(Materials.Yttrium.mRGBa[0]-60, Materials.Yttrium.mRGBa[1]-60, Materials.Yttrium.mRGBa[2]-60)); } - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustSamarium", 1) == null){ + if (ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustSamarium", 1))){ ItemUtils.generateSpecialUseDusts("Samarium", "Samarium", Materials.Samarium.mElement.name(), Utils.rgbtoHexValue(161, 168, 114)); } - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustLanthanum", 1) == null){ + if (ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustLanthanum", 1))){ ItemUtils.generateSpecialUseDusts("Lanthanum", "Lanthanum", Materials.Lanthanum.mElement.name(), Utils.rgbtoHexValue(106, 127, 163)); } - if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGermanium", 1) == null){ + if (ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGermanium", 1))){ ItemUtils.generateSpecialUseDusts("Germanium", "Germanium", "Ge", ELEMENT.getInstance().GERMANIUM.getRgbAsHex()); } @@ -621,8 +634,10 @@ public final class ModItems { dustZrCl4 = ItemUtils.generateSpecialUseDusts("ZrCl4", "ZrCl4", "ZrCl4", Utils.rgbtoHexValue(180, 180, 180))[0]; //http://www.iaea.org/inis/collection/NCLCollectionStore/_Public/39/036/39036750.pdf dustCookedZrCl4 = ItemUtils.generateSpecialUseDusts("CookedZrCl4", "Cooked ZrCl4", "ZrCl4", Utils.rgbtoHexValue(180, 180, 180))[0]; //http://www.iaea.org/inis/collection/NCLCollectionStore/_Public/39/036/39036750.pdf //Zirconium Tetrafluoride - GT_OreDictUnificator.registerOre("cellZrF4", ItemUtils.getItemStackOfAmountFromOreDict("cellZirconiumTetrafluoride", 1)); - GT_OreDictUnificator.registerOre("dustZrF4", ItemUtils.getItemStackOfAmountFromOreDict("dustZirconiumTetrafluoride", 1)); + /*GT_OreDictUnificator.registerOre("cellZrF4", ItemUtils.getItemStackOfAmountFromOreDict("cellZirconiumTetrafluoride", 1)); + GT_OreDictUnificator.registerOre("dustZrF4", ItemUtils.getItemStackOfAmountFromOreDict("dustZirconiumTetrafluoride", 1));*/ + //GT_OreDictUnificator.registerOre("cellZrF4", ItemUtils.getItemStackOfAmountFromOreDict("cellZirconiumTetrafluoride", 1)); + //GT_OreDictUnificator.registerOre("dustZrF4", ItemUtils.getItemStackOfAmountFromOreDict("dustZirconiumTetrafluoride", 1)); fluidZrF4 = FluidUtils.generateFluidNoPrefix("ZirconiumTetrafluoride", "Zirconium Tetrafluoride", 500, new short[]{170, 170, 140, 100}); //https://en.wikipedia.org/wiki/Zirconium_tetrafluoride //Coolant Salt @@ -684,7 +699,7 @@ public final class ModItems { toolGregtechPump.registerPumpType(3, "Ultimate Hand Pump", 512000, 3); //Create Multi-tools - ItemsMultiTools.load(); + //ItemsMultiTools.load(); //Xp Fluids - Dev if (!FluidRegistry.isFluidRegistered("mobessence")){ @@ -731,7 +746,6 @@ public final class ModItems { // A plate of Meat. if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateMeatRaw", 1) == null){ itemPlateRawMeat = new BaseItemPlate(meatRaw); - RecipeUtils.generateMortarRecipe(ItemUtils.getSimpleStack(itemPlateRawMeat), ItemUtils.getItemStackOfAmountFromOreDict("dustMeatRaw", 1)); ItemUtils.registerFuel(ItemUtils.getSimpleStack(itemPlateRawMeat), 100); } // A Block of Meat. @@ -896,7 +910,10 @@ public final class ModItems { //IC2 Exp if (LoadedMods.IndustrialCraft2|| LOAD_ALL_CONTENT){ Logger.INFO("IndustrialCraft2 Found - Loading Resources."); - RfEuBattery = new RF2EU_Battery(); + + if (LoadedMods.CoFHCore) { + RfEuBattery = new RF2EU_Battery(); + } //Baubles Mod Test try { diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java index b07815fa60..ec0b490f63 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java @@ -105,6 +105,7 @@ public class BaseItemComponent extends Item{ ItemStack x = aMap.get(aKey); if (x == null) { aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS("Registering a material component. Item: ["+componentMaterial.getUnlocalizedName()+"] Map: ["+aKey+"]"); Material.mComponentMap.put(componentMaterial.getUnlocalizedName(), aMap); return true; } diff --git a/src/Java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java b/src/Java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java index df46dd2052..273995e181 100644 --- a/src/Java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java +++ b/src/Java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java @@ -2,18 +2,21 @@ package gtPlusPlus.core.item.base.dusts; import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc; +import java.util.HashMap; import java.util.List; +import java.util.Map; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; - +import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_OreDictUnificator; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.data.StringUtils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; @@ -80,6 +83,32 @@ public class BaseItemDustUnique extends Item{ if ((temp != null) && !temp.equals("")){ GT_OreDictUnificator.registerOre(temp, ItemUtils.getSimpleStack(this)); } + registerComponent(); + } + + public boolean registerComponent() { + if (this.materialName == null) { + return false; + } + String aName = materialName; + //Register Component + Map aMap = Material.mComponentMap.get(aName); + if (aMap == null) { + aMap = new HashMap(); + } + String aKey = OrePrefixes.dust.name(); + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS("Registering a material component. Item: ["+aName+"] Map: ["+aKey+"]"); + Material.mComponentMap.put(aName, aMap); + return true; + } + else { + //Bad + Logger.MATERIALS("Tried to double register a material component. "); + return false; + } } @Override diff --git a/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java b/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java index 08517776ec..2b3f477c56 100644 --- a/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java +++ b/src/Java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -1,6 +1,8 @@ package gtPlusPlus.core.item.base.ore; +import java.util.HashMap; import java.util.List; +import java.util.Map; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; @@ -13,9 +15,9 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; - +import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_OreDictUnificator; - +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; @@ -52,6 +54,7 @@ public class BaseOreComponent extends Item{ //this.setTextureName(this.getCorrectTextures()); this.componentColour = material.getRgbAsHex(); GameRegistry.registerItem(this, this.unlocalName); + registerComponent(); GT_OreDictUnificator.registerOre(componentType.getComponent()+material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); if (LoadedMods.Thaumcraft) { ThaumcraftUtils.addAspectToItem(ItemUtils.getSimpleStack(this), GTPP_Aspects.METALLUM, 2); @@ -61,6 +64,51 @@ public class BaseOreComponent extends Item{ } } + + public boolean registerComponent() { + Logger.MATERIALS("Attempting to register "+this.getUnlocalizedName()+"."); + if (this.componentMaterial == null) { + Logger.MATERIALS("Tried to register "+this.getUnlocalizedName()+" but the material was null."); + return false; + } + //Register Component + Map aMap = Material.mComponentMap.get(componentMaterial.getUnlocalizedName()); + if (aMap == null) { + aMap = new HashMap(); + } + String aKey = "Invalid"; + if (componentType == ComponentTypes.CRUSHED) { + aKey = OrePrefixes.crushed.name(); + } + else if (componentType == ComponentTypes.CRUSHEDCENTRIFUGED) { + aKey = OrePrefixes.crushedCentrifuged.name(); + } + else if (componentType == ComponentTypes.CRUSHEDPURIFIED) { + aKey = OrePrefixes.crushedPurified.name(); + } + else if (componentType == ComponentTypes.DUST) { + aKey = OrePrefixes.dust.name(); + } + else if (componentType == ComponentTypes.DUSTIMPURE) { + aKey = OrePrefixes.dustImpure.name(); + } + else if (componentType == ComponentTypes.DUSTPURE) { + aKey = OrePrefixes.dustPure.name(); + } + + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS("Registering a material component. Item: ["+componentMaterial.getUnlocalizedName()+"] Map: ["+aKey+"]"); + Material.mComponentMap.put(componentMaterial.getUnlocalizedName(), aMap); + return true; + } + else { + //Bad + Logger.MATERIALS("Tried to double register a material component. "); + return false; + } + } public String getCorrectTextures(){ if (!CORE.ConfigSwitches.useGregtechTextures){ diff --git a/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRod.java b/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRod.java index f0a0f9f4ea..b6a5dff2ac 100644 --- a/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRod.java +++ b/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRod.java @@ -7,6 +7,7 @@ import gregtech.api.enums.GT_Values; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.base.BaseItemComponent; import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.minecraft.ItemUtils; public class BaseItemRod extends BaseItemComponent{ @@ -22,6 +23,7 @@ public class BaseItemRod extends BaseItemComponent{ final ItemStack stackStick = this.componentMaterial.getRod(1); final ItemStack stackBolt = this.componentMaterial.getBolt(4); + if (ItemUtils.checkForInvalidItems(new ItemStack[] {stackStick, stackBolt})) GT_Values.RA.addCutterRecipe( stackStick, stackBolt, diff --git a/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java b/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java index 0870683c46..9b232f95c5 100644 --- a/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java +++ b/src/Java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java @@ -24,23 +24,20 @@ public class BaseItemRodLong extends BaseItemComponent{ private void addExtruderRecipe(){ Logger.WARNING("Adding recipe for Long "+this.materialName+" Rods"); - final String tempStick = this.unlocalName.replace("itemRodLong", "stick"); - final String tempStickLong = this.unlocalName.replace("itemRodLong", "stickLong"); - final ItemStack stackStick = ItemUtils.getItemStackOfAmountFromOreDict(tempStick, 1); - final ItemStack stackLong = ItemUtils.getItemStackOfAmountFromOreDict(tempStickLong, 1); - - final ItemStack temp = stackStick; - temp.stackSize = 2; + final ItemStack stackStick = this.componentMaterial.getRod(2); + final ItemStack stackLong = this.componentMaterial.getLongRod(1); + if (ItemUtils.checkForInvalidItems(new ItemStack[] {stackStick, stackLong})) GT_Values.RA.addForgeHammerRecipe( - temp, + stackStick, stackLong, (int) Math.max(this.componentMaterial.getMass(), 1L), 16); + if (ItemUtils.checkForInvalidItems(new ItemStack[] {stackStick, stackLong})) GT_Values.RA.addCutterRecipe( stackLong, - temp, + stackStick, null, (int) Math.max(this.componentMaterial.getMass(), 1L), 4); diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/box/AutoLunchBox.java b/src/Java/gtPlusPlus/core/item/tool/misc/box/AutoLunchBox.java new file mode 100644 index 0000000000..baed16db03 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/box/AutoLunchBox.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.tool.misc.box; + +public class AutoLunchBox extends BaseBoxItem { + + public final static int SLOTS = 9; + + public AutoLunchBox(String displayName) { + super(displayName, new String[] {"Stores 9 pieces of food", "Food will automatically be eaten from slot 1, through to "+gtPlusPlus.core.item.tool.misc.box.AutoLunchBox.SLOTS}, gtPlusPlus.core.item.tool.misc.box.AutoLunchBox.SLOTS); + } + +} diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/box/BaseBoxItem.java b/src/Java/gtPlusPlus/core/item/tool/misc/box/BaseBoxItem.java new file mode 100644 index 0000000000..10a3ae5804 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/box/BaseBoxItem.java @@ -0,0 +1,59 @@ +package gtPlusPlus.core.item.tool.misc.box; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class BaseBoxItem extends CoreItem { + + private final int GUI; + + public BaseBoxItem(String displayName, String[] description, int GUI_ID) { + super("item." + Utils.sanitizeString(displayName), displayName, AddToCreativeTab.tabTools, 1, 0, + modifyDescriptionStringArray(description), EnumRarity.uncommon, EnumChatFormatting.GRAY, false, null); + GUI = GUI_ID; + } + + private static String[] modifyDescriptionStringArray(String[] array) { + String[] a = new String[array.length + 1]; + for (int b = 0; b < array.length; b++) { + a[b] = array[b]; + } + a[a.length - 1] = "Right Click to open"; + return a; + } + + // Without this method, your inventory will NOT work!!! + @Override + public int getMaxItemUseDuration(ItemStack stack) { + return 1; // return any value greater than zero + } + + @Override + public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) { + if (!world.isRemote) { + // If player not sneaking, open the inventory gui + if (!player.isSneaking()) { + player.openGui(GTplusplus.instance, GUI, world, (int) player.posX, (int) player.posY, + (int) player.posZ); + } + } + return itemstack; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + this.itemIcon = iconRegister.registerIcon(CORE.MODID + ":" + this.getUnlocalizedName().substring(5)); + } +} diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/box/ContainerBoxBase.java b/src/Java/gtPlusPlus/core/item/tool/misc/box/ContainerBoxBase.java new file mode 100644 index 0000000000..035859c388 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/box/ContainerBoxBase.java @@ -0,0 +1,328 @@ +package gtPlusPlus.core.item.tool.misc.box; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import gregtech.api.enums.Materials; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerBoxBase extends Container { + + /* + * Finally, in your Container class, you will need to check if the currently + * opened inventory's uniqueID is equal to the itemstack's uniqueID in the + * method 'transferStackInSlot' as well as check if the itemstack is the + * currently equipped item in the method 'slotClick'. In both cases, you'll need + * to prevent the itemstack from being moved or it will cause bad things to + * happen. + */ + + /** + * Step 3: Create a custom Container for your Inventory + */ + + /* + * There's a LOT of code in this one, but read through all of the comments + * carefully and it should become clear what everything does. As a bonus, one of + * my previous tutorials is included within! + * "How to Properly Override Shift-Clicking" is here and better than ever! At + * least in my opinion. If you're like me, and you find no end of frustration + * trying to figure out which f-ing index you should use for which slots in your + * container when overriding transferStackInSlot, or if your following the + * original tutorial, then read on. + */ + + /** + * The Item Inventory for this Container, only needed if you want to reference + * isUseableByPlayer + */ + private final CustomBoxInventory inventory; + /** + * Using these will make transferStackInSlot easier to understand and implement + * INV_START is the index of the first slot in the Player's Inventory, so our + * CustomBoxInventory's number of slots (e.g. 5 slots is array indices 0-4, so + * start at 5) Notice how we don't have to remember how many slots we made? We + * can just use CustomBoxInventory.INV_SIZE and if we ever change it, the + * Container updates automatically. + */ + private final int INV_START, INV_END, HOTBAR_START, HOTBAR_END; + + // If you're planning to add armor slots, put those first like this: + // ARMOR_START = CustomBoxInventory.INV_SIZE, ARMOR_END = ARMOR_START+3, + // INV_START = ARMOR_END+1, and then carry on like above. + + private Slot generateSlot(final Constructor aClazz, final IInventory base, final int id, final int x, + final int y) { + Slot aSlot; + try { + aSlot = (Slot) aClazz.newInstance(base, id, x, y); + if (aSlot != null) { + return aSlot; + } + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + e.printStackTrace(); + } + return null; + } + + public ContainerBoxBase(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, + CustomBoxInventory CustomBoxInventory, Class aClazz, int aSlotCount) { + + INV_START = aSlotCount; + INV_END = INV_START + 26; + HOTBAR_START = INV_END + 1; + HOTBAR_END = HOTBAR_START + 8; + + this.inventory = CustomBoxInventory; + try { + + Constructor constructor; + constructor = aClazz.getConstructor(IInventory.class, int.class, int.class, int.class); + + int i; + + // ITEM INVENTORY - you'll need to adjust the slot locations to match your + // texture file + // I have them set vertically in columns of 4 to the right of the player model + for (i = 0; i < CustomBoxInventory.INV_SIZE; ++i) { + // You can make a custom Slot if you need different behavior, + // such as only certain item types can be put into this slot + // We made a custom slot to prevent our inventory-storing item + // from being stored within itself, but if you want to allow that and + // you followed my advice at the end of the above step, then you + // could get away with using the vanilla Slot class + this.addSlotToContainer(generateSlot(constructor, this.getInventoryObject(), i, + 80 + (18 * (int) (i / 4)), 8 + (18 * (i % 4)))); + } + + // If you want, you can add ARMOR SLOTS here as well, but you need to + // make a public version of SlotArmor. I won't be doing that in this tutorial. + /* + * for (i = 0; i < 4; ++i) { // These are the standard positions for survival + * inventory layout this.addSlotToContainer(new SlotArmor(this.player, + * inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18, + * i)); } + */ + + // PLAYER INVENTORY - uses default locations for standard inventory texture file + for (i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + // PLAYER ACTION BAR - uses default locations for standard action bar texture + // file + for (i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); + } + + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } + + @Override + public boolean canInteractWith(EntityPlayer entityplayer) { + // be sure to return the inventory's isUseableByPlayer method + // if you defined special behavior there: + return getInventoryObject().isUseableByPlayer(entityplayer); + } + + /** + * Called when a player shift-clicks on a slot. You must override this or you + * will crash when someone does that. + */ + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index) { + ItemStack itemstack = null; + Slot slot = (Slot) this.inventorySlots.get(index); + + if (slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + // If item is in our custom Inventory or armor slot + if (index < INV_START) { + // try to place in player inventory / action bar + if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)) { + return null; + } + + slot.onSlotChange(itemstack1, itemstack); + } + // Item is in inventory / hotbar, try to place in custom inventory or armor + // slots + else { + /* + * If your inventory only stores certain instances of Items, you can implement + * shift-clicking to your inventory like this: + * + * // Check that the item is the right type if (itemstack1.getItem() instanceof + * ItemCustom) { // Try to merge into your custom inventory slots // We use + * 'CustomBoxInventory.INV_SIZE' instead of INV_START just in case // you also + * add armor or other custom slots if (!this.mergeItemStack(itemstack1, 0, + * CustomBoxInventory.INV_SIZE, false)) { return null; } } // If you added armor + * slots, check them here as well: // Item being shift-clicked is armor - try to + * put in armor slot if (itemstack1.getItem() instanceof ItemArmor) { int type = + * ((ItemArmor) itemstack1.getItem()).armorType; if + * (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, + * false)) { return null; } } Otherwise, you have basically 2 choices: 1. + * shift-clicking between player inventory and custom inventory 2. + * shift-clicking between action bar and inventory + * + * Be sure to choose only ONE of the following implementations!!! + */ + /** + * Implementation number 1: Shift-click into your custom inventory + */ + if (index >= INV_START) { + // place in custom inventory + if (!this.mergeItemStack(itemstack1, 0, INV_START, false)) { + return null; + } + } + + /** + * Implementation number 2: Shift-click items between action bar and inventory + */ + // item is in player's inventory, but not in action bar + if (index >= INV_START && index < HOTBAR_START) { + // place in action bar + if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END + 1, false)) { + return null; + } + } + // item in action bar - place in player inventory + else if (index >= HOTBAR_START && index < HOTBAR_END + 1) { + if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)) { + return null; + } + } + } + + if (itemstack1.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) { + return null; + } + + slot.onPickupFromSlot(par1EntityPlayer, itemstack1); + } + + return itemstack; + } + + /** + * You should override this method to prevent the player from moving the stack + * that opened the inventory, otherwise if the player moves it, the inventory + * will not be able to save properly + */ + @Override + public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { + // this will prevent the player from interacting with the item that opened the + // inventory: + if (slot >= 0 && getSlot(slot) != null && getSlot(slot).getStack() == player.getHeldItem()) { + return null; + } + return super.slotClick(slot, button, flag, player); + } + + /* + * Special note: If your custom inventory's stack limit is 1 and you allow + * shift-clicking itemstacks into it, you will need to override mergeStackInSlot + * to avoid losing all the items but one in a stack when you shift-click. + */ + /** + * Vanilla mergeItemStack method doesn't correctly handle inventories whose max + * stack size is 1 when you shift-click into the inventory. This is a modified + * method I wrote to handle such cases. Note you only need it if your slot / + * inventory's max stack size is 1 + */ + @Override + protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards) { + boolean flag1 = false; + int k = (backwards ? end - 1 : start); + Slot slot; + ItemStack itemstack1; + + if (stack.isStackable()) { + while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start)) { + slot = (Slot) inventorySlots.get(k); + itemstack1 = slot.getStack(); + + if (!slot.isItemValid(stack)) { + k += (backwards ? -1 : 1); + continue; + } + + if (itemstack1 != null && itemstack1.getItem() == stack.getItem() + && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) + && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { + int l = itemstack1.stackSize + stack.stackSize; + + if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) { + stack.stackSize = 0; + itemstack1.stackSize = l; + getInventoryObject().markDirty(); + flag1 = true; + } else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) { + stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize; + itemstack1.stackSize = stack.getMaxStackSize(); + getInventoryObject().markDirty(); + flag1 = true; + } + } + + k += (backwards ? -1 : 1); + } + } + if (stack.stackSize > 0) { + k = (backwards ? end - 1 : start); + while (!backwards && k < end || backwards && k >= start) { + slot = (Slot) inventorySlots.get(k); + itemstack1 = slot.getStack(); + + if (!slot.isItemValid(stack)) { + k += (backwards ? -1 : 1); + continue; + } + + if (itemstack1 == null) { + int l = stack.stackSize; + if (l <= slot.getSlotStackLimit()) { + slot.putStack(stack.copy()); + stack.stackSize = 0; + getInventoryObject().markDirty(); + flag1 = true; + break; + } else { + putStackInSlot(k, + new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); + stack.stackSize -= slot.getSlotStackLimit(); + getInventoryObject().markDirty(); + flag1 = true; + } + } + + k += (backwards ? -1 : 1); + } + } + + return flag1; + } + + public CustomBoxInventory getInventoryObject() { + return inventory; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/box/CustomBoxInventory.java b/src/Java/gtPlusPlus/core/item/tool/misc/box/CustomBoxInventory.java new file mode 100644 index 0000000000..0737e463d8 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/box/CustomBoxInventory.java @@ -0,0 +1,243 @@ +package gtPlusPlus.core.item.tool.misc.box; + +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.util.Constants; + +public abstract class CustomBoxInventory implements IInventory { + + private final String name; + protected String uniqueID; + + /** Provides NBT Tag Compound to reference */ + private final ItemStack invItem; + + /** Defining your inventory size this way is handy */ + public final int INV_SIZE; + + /** Inventory's size must be same as number of slots you add to the Container class */ + private ItemStack[] inventory; + + /** + * @param itemstack - the ItemStack to which this inventory belongs + */ + public CustomBoxInventory(ItemStack stack, String name2){ + this(stack, name2, 8); + } + + /** + * @param itemstack - the ItemStack to which this inventory belongs + */ + public CustomBoxInventory(ItemStack stack, String name2, int slots) + { + invItem = stack; + name = name2; + INV_SIZE = slots; + inventory = new ItemStack[INV_SIZE]; + + /** initialize variable within the constructor: */ + uniqueID = ""; + + if (!stack.hasTagCompound()) + { + stack.setTagCompound(new NBTTagCompound()); + // no tag compound means the itemstack does not yet have a UUID, so assign one: + uniqueID = UUID.randomUUID().toString(); + } + + /** When reading from NBT: */ + if ("".equals(uniqueID)) + { + // try to read unique ID from NBT + uniqueID = stack.getTagCompound().getString("uniqueID"); + // if it's still "", assign a new one: + if ("".equals(uniqueID)) + { + uniqueID = UUID.randomUUID().toString(); + } + } + + /** Writing to NBT: */ + // just add this line: + stack.getTagCompound().setString("uniqueID", this.uniqueID); + + // note that it's okay to use stack instead of invItem right there + // both reference the same memory location, so whatever you change using + // either reference will change in the other + + // Read the inventory contents from NBT + readFromNBT(stack.getTagCompound()); + } + + @Override + public int getSizeInventory() + { + return inventory.length; + } + + @Override + public ItemStack getStackInSlot(int slot) + { + return inventory[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) + { + ItemStack stack = getStackInSlot(slot); + if(stack != null) + { + if(stack.stackSize > amount) + { + stack = stack.splitStack(amount); + // Don't forget this line or your inventory will not be saved! + markDirty(); + } + else + { + // this method also calls onInventoryChanged, so we don't need to call it again + setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; + + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + markDirty(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return name; + } + + // 1.7.2+ renamed to hasCustomInventoryName + @Override + public boolean hasCustomInventoryName() + { + return name.length() > 0; + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + /** + * This is the method that will handle saving the inventory contents, as it is called (or should be called!) + * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also + * let you change things in your inventory without ever opening a Gui, if you want. + */ + // 1.7.2+ renamed to markDirty + @Override + public void markDirty() + { + for (int i = 0; i < getSizeInventory(); ++i) + { + if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { + inventory[i] = null; + } + } + + // This line here does the work: + writeToNBT(invItem.getTagCompound()); + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; + } + + // 1.7.2+ renamed to openInventory(EntityPlayer player) + @Override + public void openInventory() {} + + // 1.7.2+ renamed to closeInventory(Ent