From ed9bd19c9bc02a702b397791f59927a2f0ebc664 Mon Sep 17 00:00:00 2001 From: Tom Dickson Date: Wed, 24 Nov 2021 10:30:11 -0600 Subject: another one --- .../gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java index ed17f8547a..b9784f607a 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -177,7 +177,7 @@ public class ItemGenericChemBase extends Item { createCatalystNBT(aStack); } double currentDamage = getCatalystDamage(aStack); - double durabilitypercent = currentDamage / 100; + double durabilitypercent = currentDamage / getCatalystMaxDamage(aStack); return durabilitypercent; } else { -- cgit From 84cc741a3b243d46caccfd0b512a612d4e86a59f Mon Sep 17 00:00:00 2001 From: Tom Dickson Date: Wed, 24 Nov 2021 10:32:21 -0600 Subject: similar for milling ball (what is a milling ball?) --- .../gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java index b9784f607a..c00267c880 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -169,7 +169,7 @@ public class ItemGenericChemBase extends Item { createMillingBallNBT(aStack); } double currentDamage = getMillingBallDamage(aStack); - double durabilitypercent = currentDamage / 100; + double durabilitypercent = currentDamage / getMillingBallMaxDamage(aStack); return durabilitypercent; } else if (ItemUtils.isCatalyst(aStack)) { -- cgit From b95f305b846186e1c52698a061365c595370dfbb Mon Sep 17 00:00:00 2001 From: Tom Dickson Date: Wed, 24 Nov 2021 10:34:02 -0600 Subject: this is more appropriate I think --- .../gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java index c00267c880..a3e1917d0d 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -169,7 +169,7 @@ public class ItemGenericChemBase extends Item { createMillingBallNBT(aStack); } double currentDamage = getMillingBallDamage(aStack); - double durabilitypercent = currentDamage / getMillingBallMaxDamage(aStack); + double durabilitypercent = currentDamage / getMaxBallDurability(aStack); return durabilitypercent; } else if (ItemUtils.isCatalyst(aStack)) { -- cgit From 147049b97edef96990c94d997dd9c934b06eb68f Mon Sep 17 00:00:00 2001 From: Tom Dickson Date: Wed, 24 Nov 2021 10:38:26 -0600 Subject: minor refactor --- .../core/item/chemistry/general/ItemGenericChemBase.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java index a3e1917d0d..83dc1550cc 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -159,8 +159,6 @@ public class ItemGenericChemBase extends Item { public String getUnlocalizedName(ItemStack stack) { return super.getUnlocalizedName() + "." + stack.getItemDamage(); } - - @Override public double getDurabilityForDisplay(ItemStack aStack) { @@ -169,16 +167,14 @@ public class ItemGenericChemBase extends Item { createMillingBallNBT(aStack); } double currentDamage = getMillingBallDamage(aStack); - double durabilitypercent = currentDamage / getMaxBallDurability(aStack); - return durabilitypercent; + return currentDamage / getMaxBallDurability(aStack); } else if (ItemUtils.isCatalyst(aStack)) { if (aStack.getTagCompound() == null || aStack.getTagCompound().hasNoTags()){ createCatalystNBT(aStack); } double currentDamage = getCatalystDamage(aStack); - double durabilitypercent = currentDamage / getCatalystMaxDamage(aStack); - return durabilitypercent; + return currentDamage / getCatalystMaxDamage(aStack); } else { return 1D; -- cgit From c4d3b0592818da6c15b658733314056947cd0996 Mon Sep 17 00:00:00 2001 From: Tom Dickson Date: Wed, 24 Nov 2021 10:50:39 -0600 Subject: display red at 0 shouldn't be possible to get to zero but .... --- .../core/item/chemistry/general/ItemGenericChemBase.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/Java/gtPlusPlus/core/item') diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java index 83dc1550cc..9a00b49342 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -204,10 +204,7 @@ public class ItemGenericChemBase extends Item { aHasSpecialTooltips = true; } if (aHasSpecialTooltips) { - if (aDam > aDamageSegment * 4){ - durability = EnumChatFormatting.GRAY; - } - else if (aDam > aDamageSegment * 3){ + if (aDam > aDamageSegment * 3){ durability = EnumChatFormatting.GREEN; } else if (aDam > aDamageSegment * 2){ @@ -216,7 +213,7 @@ public class ItemGenericChemBase extends Item { else if (aDam > aDamageSegment){ durability = EnumChatFormatting.GOLD; } - else if (aDam > 0){ + else if (aDam >= 0){ durability = EnumChatFormatting.RED; } list.add(durability+""+(aDam)+EnumChatFormatting.GRAY+" / "+aMaxDamage); @@ -318,6 +315,4 @@ public class ItemGenericChemBase extends Item { public static int getMaxCatalystDurability(ItemStack aStack) { return 50; } - - } -- cgit From cc485b474423976aefe395ae4c30679700b0e63c Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 6 Dec 2021 10:28:23 +0800 Subject: copy over gui-select-circuit in gregtech --- .../core/item/circuit/ItemAdvancedChip.java | 109 ++++++++++++++++++++- 1 file changed, 104 insertions(+), 5 deletions(-) (limited to 'src/Java/gtPlusPlus/core/item') 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 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> 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 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> 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, BiFunction> p : GregTech_API.sCircuitProgrammerList.entrySet()) + if (p.getKey().test(toolStack)) + return Pair.of(j, p.getValue()); + } + return null; + } } -- cgit