aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/items
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common/items')
-rw-r--r--src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java156
-rw-r--r--src/main/java/gregtech/common/items/GT_VolumetricFlask.java26
2 files changed, 151 insertions, 31 deletions
diff --git a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java
index 4b7d294a25..9ae287c610 100644
--- a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java
+++ b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java
@@ -1,30 +1,50 @@
package gregtech.common.items;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
+import gregtech.api.enums.ToolDictNames;
+import gregtech.api.gui.GT_GUIDialogSelectItem;
+import gregtech.api.interfaces.INetworkUpdatableItem;
import gregtech.api.items.GT_Generic_Item;
+import gregtech.api.net.GT_Packet_UpdateItem;
+import gregtech.api.objects.XSTR;
import gregtech.api.util.GT_Config;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_ModHandler;
+import gregtech.api.util.GT_Utility;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
+import net.minecraft.util.StatCollector;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.Constants;
+import net.minecraftforge.common.util.FakePlayer;
+import net.minecraftforge.oredict.OreDictionary;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import static gregtech.GT_Mod.GT_FML_LOGGER;
import static gregtech.api.enums.GT_Values.RES_PATH_ITEM;
-public class GT_IntegratedCircuit_Item extends GT_Generic_Item {
+public class GT_IntegratedCircuit_Item extends GT_Generic_Item implements INetworkUpdatableItem {
private static final String aTextEmptyRow = " ";
+ private static final List<ItemStack> ALL_VARIANTS = new ArrayList<>();
protected IIcon[] mIconDamage = new IIcon[25];
public GT_IntegratedCircuit_Item() {
super("integrated_circuit", "Programmed Circuit", "");
@@ -33,37 +53,40 @@ public class GT_IntegratedCircuit_Item extends GT_Generic_Item {
ItemList.Circuit_Integrated.set(this);
+ ALL_VARIANTS.add(new ItemStack(this, 0, 0));
for (int i = 1; i <= 24; i++) {
- GregTech_API.registerConfigurationCircuit(new ItemStack(this, 0, i));
+ ItemStack aStack = new ItemStack(this, 0, i);
+ GregTech_API.registerConfigurationCircuit(aStack);
+ ALL_VARIANTS.add(aStack);
}
- GT_ModHandler.addShapelessCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 0L, new Object[0]), GT_ModHandler.RecipeBits.NOT_REMOVABLE, new Object[]{OrePrefixes.circuit.get(Materials.Basic)});
+ GT_ModHandler.addShapelessCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 0L), GT_ModHandler.RecipeBits.NOT_REMOVABLE, new Object[]{OrePrefixes.circuit.get(Materials.Basic)});
long bits = GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.NOT_REMOVABLE;
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 1L, new Object[0]), bits, new Object[]{"d ", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 2L, new Object[0]), bits, new Object[]{" d ", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 3L, new Object[0]), bits, new Object[]{" d", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 4L, new Object[0]), bits, new Object[]{aTextEmptyRow, " Pd", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 5L, new Object[0]), bits, new Object[]{aTextEmptyRow, " P ", " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 6L, new Object[0]), bits, new Object[]{aTextEmptyRow, " P ", " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 7L, new Object[0]), bits, new Object[]{aTextEmptyRow, " P ", "d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 8L, new Object[0]), bits, new Object[]{aTextEmptyRow, "dP ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
-
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 9L, new Object[0]), bits, new Object[]{"P d", aTextEmptyRow, aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 10L, new Object[0]), bits, new Object[]{"P ", " d", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 11L, new Object[0]), bits, new Object[]{"P ", aTextEmptyRow, " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 12L, new Object[0]), bits, new Object[]{"P ", aTextEmptyRow, " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 13L, new Object[0]), bits, new Object[]{" P", aTextEmptyRow, " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 14L, new Object[0]), bits, new Object[]{" P", aTextEmptyRow, " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 15L, new Object[0]), bits, new Object[]{" P", aTextEmptyRow, "d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 16L, new Object[0]), bits, new Object[]{" P", "d ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 17L, new Object[0]), bits, new Object[]{aTextEmptyRow, aTextEmptyRow, "d P", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 18L, new Object[0]), bits, new Object[]{aTextEmptyRow, "d ", " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 19L, new Object[0]), bits, new Object[]{"d ", aTextEmptyRow, " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 20L, new Object[0]), bits, new Object[]{" d ", aTextEmptyRow, " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 21L, new Object[0]), bits, new Object[]{"d ", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 22L, new Object[0]), bits, new Object[]{" d ", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 23L, new Object[0]), bits, new Object[]{" d", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
- GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 24L, new Object[0]), bits, new Object[]{aTextEmptyRow, " d", "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L, new Object[0])});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 1L), bits, new Object[]{"d ", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 2L), bits, new Object[]{" d ", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 3L), bits, new Object[]{" d", " P ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 4L), bits, new Object[]{aTextEmptyRow, " Pd", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 5L), bits, new Object[]{aTextEmptyRow, " P ", " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 6L), bits, new Object[]{aTextEmptyRow, " P ", " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 7L), bits, new Object[]{aTextEmptyRow, " P ", "d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 8L), bits, new Object[]{aTextEmptyRow, "dP ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 9L), bits, new Object[]{"P d", aTextEmptyRow, aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 10L), bits, new Object[]{"P ", " d", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 11L), bits, new Object[]{"P ", aTextEmptyRow, " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 12L), bits, new Object[]{"P ", aTextEmptyRow, " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 13L), bits, new Object[]{" P", aTextEmptyRow, " d", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 14L), bits, new Object[]{" P", aTextEmptyRow, " d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 15L), bits, new Object[]{" P", aTextEmptyRow, "d ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 16L), bits, new Object[]{" P", "d ", aTextEmptyRow, 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 17L), bits, new Object[]{aTextEmptyRow, aTextEmptyRow, "d P", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 18L), bits, new Object[]{aTextEmptyRow, "d ", " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 19L), bits, new Object[]{"d ", aTextEmptyRow, " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 20L), bits, new Object[]{" d ", aTextEmptyRow, " P", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 21L), bits, new Object[]{"d ", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 22L), bits, new Object[]{" d ", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 23L), bits, new Object[]{" d", aTextEmptyRow, "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
+ GT_ModHandler.addCraftingRecipe(ItemList.Circuit_Integrated.getWithDamage(1L, 24L), bits, new Object[]{aTextEmptyRow, " d", "P ", 'P', ItemList.Circuit_Integrated.getWildcard(1L)});
}
private static String getModeString(int aMetaData) {
@@ -129,4 +152,81 @@ public class GT_IntegratedCircuit_Item extends GT_Generic_Item {
byte circuitMode = ((byte) (damage & 0xFF)); // Mask out the MSB Comparison Mode Bits. See: getModeString
return mIconDamage[circuitMode < mIconDamage.length ? circuitMode : 0];
}
+
+ @Override
+ public boolean receive(ItemStack stack, EntityPlayerMP player, NBTTagCompound tag) {
+ int meta = tag.hasKey("meta", Constants.NBT.TAG_BYTE) ? tag.getByte("meta") : -1;
+ if (meta < 0 || meta > 24)
+ return true;
+
+ if (!player.capabilities.isCreativeMode) {
+ int toolIndex = findConfiguratorInInv(player);
+ if (toolIndex < 0) return true;
+
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ ItemStack oldToolStack = mainInventory[toolIndex];
+ mainInventory[toolIndex] = oldToolStack.getItem().getContainerItem(oldToolStack);
+ }
+ stack.setItemDamage(meta);
+
+ return true;
+ }
+
+ @Override
+ public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
+ // nothing on server side or fake player
+ if (player instanceof FakePlayer || !world.isRemote) return false;
+ // check if any screwdriver
+ ItemStack configuratorStack;
+ if (player.capabilities.isCreativeMode) {
+ configuratorStack = null;
+ } else {
+ int configurator = findConfiguratorInInv(player);
+ if (configurator < 0) {
+ int count;
+ try {
+ count = Integer.parseInt(StatCollector.translateToLocal("GT5U.item.programmed_circuit.no_screwdriver.count"));
+ } catch (NumberFormatException e) {
+ player.addChatComponentMessage(new ChatComponentText("Error in translation GT5U.item.programmed_circuit.no_screwdriver.count: " + e.getMessage()));
+ count = 1;
+ }
+ player.addChatComponentMessage(new ChatComponentTranslation("GT5U.item.programmed_circuit.no_screwdriver." + XSTR.XSTR_INSTANCE.nextInt(count)));
+ return false;
+ }
+ configuratorStack = player.inventory.mainInventory[configurator];
+ }
+ openSelectorGui(player, configuratorStack, stack.getItemDamage());
+ return true;
+ }
+
+ private void openSelectorGui(EntityPlayer player, ItemStack configurator, int meta) {
+ FMLCommonHandler.instance().showGuiScreen(new GT_GUIDialogSelectItem(
+ StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"),
+ configurator,
+ null,
+ GT_IntegratedCircuit_Item::onConfigured,
+ ALL_VARIANTS,
+ meta,
+ true
+ ));
+ }
+
+ private static void onConfigured(ItemStack stack) {
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setByte("meta", (byte) stack.getItemDamage());
+ GT_Values.NW.sendToServer(new GT_Packet_UpdateItem(tag));
+ }
+
+ private static int findConfiguratorInInv(EntityPlayer player) {
+ int screwdriverOreId = OreDictionary.getOreID(ToolDictNames.craftingToolScrewdriver.name());
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ for (int j = 0, mainInventoryLength = mainInventory.length; j < mainInventoryLength; j++) {
+ ItemStack toolStack = mainInventory[j];
+ boolean accepted = GT_Utility.isStackInList(toolStack, GregTech_API.sCircuitProgrammerList) ||
+ Arrays.stream(OreDictionary.getOreIDs(toolStack)).anyMatch(i -> i == screwdriverOreId);
+ if (accepted)
+ return j;
+ }
+ return -1;
+ }
}
diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java
index c0dcb45943..055b0bf036 100644
--- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java
+++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java
@@ -4,12 +4,14 @@ package gregtech.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.enums.GT_Values;
+import gregtech.api.interfaces.INetworkUpdatableItem;
import gregtech.api.items.GT_Generic_Item;
import ic2.core.util.LiquidUtil;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -21,15 +23,22 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ForgeDirection;
-import net.minecraftforge.fluids.*;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidBlock;
+import net.minecraftforge.fluids.IFluidContainerItem;
+import net.minecraftforge.fluids.IFluidHandler;
import java.util.List;
import static gregtech.api.enums.GT_Values.RES_PATH_ITEM;
-import static ic2.core.util.LiquidUtil.*;
+import static ic2.core.util.LiquidUtil.drainContainerStack;
+import static ic2.core.util.LiquidUtil.fillContainerStack;
+import static ic2.core.util.LiquidUtil.placeFluid;
-public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem {
+public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem, INetworkUpdatableItem {
private final int maxCapacity;
private final String unlocalFlaskName;
@SideOnly(Side.CLIENT)
@@ -287,4 +296,15 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain
}
return false;
}
+
+ @Override
+ public boolean receive(ItemStack stack, EntityPlayerMP player, NBTTagCompound tag) {
+ if (stack != null && stack.stackSize > 0) {
+ Item item = stack.getItem();
+ if (item == this)
+ setCapacity(stack, tag.getInteger("cap"));
+ return true;
+ }
+ return false;
+ }
}