aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Robertz <dream-master@gmx.net>2021-12-06 10:27:15 +0100
committerGitHub <noreply@github.com>2021-12-06 10:27:15 +0100
commitbfd2128fddf9d6a0412ae4dc34244c9f2ef4c3de (patch)
treee3465b97f969751adbcba134ab8f5f6ac14d81bc
parentf95f2826a61950d28835e4e5ee3f954c546b61de (diff)
parentcc485b474423976aefe395ae4c30679700b0e63c (diff)
downloadGT5-Unofficial-bfd2128fddf9d6a0412ae4dc34244c9f2ef4c3de.tar.gz
GT5-Unofficial-bfd2128fddf9d6a0412ae4dc34244c9f2ef4c3de.tar.bz2
GT5-Unofficial-bfd2128fddf9d6a0412ae4dc34244c9f2ef4c3de.zip
Merge pull request #59 from GTNewHorizons/gui-select-circuit
copy over gui-select-circuit in gregtech
-rw-r--r--src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java109
-rw-r--r--src/Java/gtPlusPlus/plugin/agrichem/item/algae/ItemBioChip.java108
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java14
3 files changed, 222 insertions, 9 deletions
diff --git a/src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java b/src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java
index c375c32952..17321a0c45 100644
--- a/src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java
+++ b/src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java
@@ -1,22 +1,38 @@
package gtPlusPlus.core.item.circuit;
-import java.util.List;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.GT_GUIDialogSelectItem;
+import gregtech.api.interfaces.INetworkUpdatableItem;
+import gregtech.api.net.GT_Packet_UpdateItem;
+import gregtech.api.objects.XSTR;
+import gregtech.api.util.GT_LanguageManager;
+import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraft.util.IIcon;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.*;
import net.minecraft.world.World;
+import net.minecraftforge.common.util.Constants;
+import net.minecraftforge.common.util.FakePlayer;
+import org.apache.commons.lang3.tuple.Pair;
-public class ItemAdvancedChip extends Item {
-
+public class ItemAdvancedChip extends Item implements INetworkUpdatableItem {
+ private static final List<ItemStack> ALL_VARIANTS = new ArrayList<>();
protected IIcon base;
public ItemAdvancedChip() {
@@ -26,6 +42,11 @@ public class ItemAdvancedChip extends Item {
this.setMaxDamage(0);
this.setUnlocalizedName("T3RecipeSelector");
GameRegistry.registerItem(this, this.getUnlocalizedName());
+ ALL_VARIANTS.add(new ItemStack(this, 0, 0));
+ for (int i = 1; i <= 24; i++) {
+ ItemStack aStack = new ItemStack(this, 0, i);
+ ALL_VARIANTS.add(aStack);
+ }
}
@Override
@@ -52,6 +73,8 @@ public class ItemAdvancedChip extends Item {
public void addInformation(ItemStack aStack, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) {
try {
aList.add("Configuration == "+aStack.getItemDamage());
+ aList.add(GT_LanguageManager.addStringLocalization(new StringBuilder().append(getUnlocalizedName()).append(".tooltip.0").toString(), "Right click to reconfigure"));
+ aList.add(GT_LanguageManager.addStringLocalization(new StringBuilder().append(getUnlocalizedName()).append(".tooltip.1").toString(), "Needs a screwdriver or circuit programming tool"));
}
catch (Throwable t) {
t.printStackTrace();
@@ -133,6 +156,82 @@ public class ItemAdvancedChip extends Item {
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName();
}
-
+ @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) {
+ Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> toolIndex = findConfiguratorInInv(player);
+ if (toolIndex == null) return true;
+
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ mainInventory[toolIndex.getKey()] = toolIndex.getValue().apply(mainInventory[toolIndex.getKey()], player);
+ }
+ 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 {
+ Pair<Integer, ?> configurator = findConfiguratorInInv(player);
+ if (configurator == null) {
+ 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.getKey()];
+ }
+ openSelectorGui(configuratorStack, stack.getItemDamage());
+ return true;
+ }
+
+ private void openSelectorGui(ItemStack configurator, int meta) {
+ FMLCommonHandler.instance().showGuiScreen(new GT_GUIDialogSelectItem(
+ StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"),
+ configurator,
+ null,
+ ItemAdvancedChip::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 Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> findConfiguratorInInv(EntityPlayer player) {
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ for (int j = 0, mainInventoryLength = mainInventory.length; j < mainInventoryLength; j++) {
+ ItemStack toolStack = mainInventory[j];
+
+ if (!GT_Utility.isStackValid(toolStack))
+ continue;
+
+ for (Map.Entry<Predicate<ItemStack>, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> p : GregTech_API.sCircuitProgrammerList.entrySet())
+ if (p.getKey().test(toolStack))
+ return Pair.of(j, p.getValue());
+ }
+ return null;
+ }
}
diff --git a/src/Java/gtPlusPlus/plugin/agrichem/item/algae/ItemBioChip.java b/src/Java/gtPlusPlus/plugin/agrichem/item/algae/ItemBioChip.java
index 5ecfbbabe9..f876839f5f 100644
--- a/src/Java/gtPlusPlus/plugin/agrichem/item/algae/ItemBioChip.java
+++ b/src/Java/gtPlusPlus/plugin/agrichem/item/algae/ItemBioChip.java
@@ -1,21 +1,38 @@
package gtPlusPlus.plugin.agrichem.item.algae;
-import java.util.List;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.GT_GUIDialogSelectItem;
+import gregtech.api.interfaces.INetworkUpdatableItem;
+import gregtech.api.net.GT_Packet_UpdateItem;
+import gregtech.api.objects.XSTR;
+import gregtech.api.util.GT_LanguageManager;
+import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraft.util.IIcon;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.*;
import net.minecraft.world.World;
+import net.minecraftforge.common.util.Constants;
+import net.minecraftforge.common.util.FakePlayer;
+import org.apache.commons.lang3.tuple.Pair;
-public class ItemBioChip extends Item {
+public class ItemBioChip extends Item implements INetworkUpdatableItem {
+ private static final List<ItemStack> ALL_VARIANTS = new ArrayList<>();
protected IIcon base;
@@ -26,6 +43,11 @@ public class ItemBioChip extends Item {
this.setMaxDamage(0);
this.setUnlocalizedName("BioRecipeSelector");
GameRegistry.registerItem(this, this.getUnlocalizedName());
+ ALL_VARIANTS.add(new ItemStack(this, 0, 0));
+ for (int i = 1; i <= 24; i++) {
+ ItemStack aStack = new ItemStack(this, 0, i);
+ ALL_VARIANTS.add(aStack);
+ }
}
@Override
@@ -52,6 +74,8 @@ public class ItemBioChip extends Item {
public void addInformation(ItemStack aStack, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) {
try {
aList.add("Configuration == "+aStack.getItemDamage());
+ aList.add(GT_LanguageManager.addStringLocalization(new StringBuilder().append(getUnlocalizedName()).append(".tooltip.0").toString(), "Right click to reconfigure"));
+ aList.add(GT_LanguageManager.addStringLocalization(new StringBuilder().append(getUnlocalizedName()).append(".tooltip.1").toString(), "Needs a screwdriver or circuit programming tool"));
}
catch (Throwable t) {
t.printStackTrace();
@@ -133,6 +157,82 @@ public class ItemBioChip extends Item {
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName();
}
-
+ @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) {
+ Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> toolIndex = findConfiguratorInInv(player);
+ if (toolIndex == null) return true;
+
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ mainInventory[toolIndex.getKey()] = toolIndex.getValue().apply(mainInventory[toolIndex.getKey()], player);
+ }
+ 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 {
+ Pair<Integer, ?> configurator = findConfiguratorInInv(player);
+ if (configurator == null) {
+ 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.getKey()];
+ }
+ openSelectorGui(configuratorStack, stack.getItemDamage());
+ return true;
+ }
+
+ private void openSelectorGui(ItemStack configurator, int meta) {
+ FMLCommonHandler.instance().showGuiScreen(new GT_GUIDialogSelectItem(
+ StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"),
+ configurator,
+ null,
+ ItemBioChip::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 Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> findConfiguratorInInv(EntityPlayer player) {
+ ItemStack[] mainInventory = player.inventory.mainInventory;
+ for (int j = 0, mainInventoryLength = mainInventory.length; j < mainInventoryLength; j++) {
+ ItemStack toolStack = mainInventory[j];
+
+ if (!GT_Utility.isStackValid(toolStack))
+ continue;
+
+ for (Map.Entry<Predicate<ItemStack>, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> p : GregTech_API.sCircuitProgrammerList.entrySet())
+ if (p.getKey().test(toolStack))
+ return Pair.of(j, p.getValue());
+ }
+ return null;
+ }
}
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java b/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java
index f623fe7405..a375f77cda 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java
@@ -8,6 +8,7 @@ import java.util.Collection;
import java.util.List;
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
+import gregtech.api.GregTech_API;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
@@ -40,6 +41,7 @@ import gtPlusPlus.core.util.reflect.AddGregtechRecipe;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.everglades.gen.gt.WorldGen_GT;
import gtPlusPlus.xmod.gregtech.api.enums.CustomOrePrefix;
+import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
import gtPlusPlus.xmod.gregtech.api.util.GTPP_Config;
import gtPlusPlus.xmod.gregtech.api.world.GTPP_Worldgen;
@@ -141,6 +143,18 @@ public class HANDLER_GT {
//Register some custom recipe maps for any enabled multiblocks.
//MultiblockRecipeMapHandler.run();
+
+ if (GregtechItemList.Circuit_BioRecipeSelector.hasBeenSet()) {
+ for (int i = 1; i <= 24; i++) {
+ GregTech_API.registerConfigurationCircuit(CI.getNumberedBioCircuit(i), 0);
+ }
+ }
+
+ if (GregtechItemList.Circuit_T3RecipeSelector.hasBeenSet()) {
+ for (int i = 1; i <= 24; i++) {
+ GregTech_API.registerConfigurationCircuit(CI.getNumberedAdvancedCircuit(i), 3);
+ }
+ }
}
public static void onLoadComplete(FMLLoadCompleteEvent event) {