From cd2ba914a6b5b980ff56347455fcf43a9e3eea3b Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 26 Nov 2022 01:56:28 +0900 Subject: Rewrite GUIs with ModularUI (#440) * Update GT * NEI migration & cleanup Deprecate GTPP_Recipe_Map_Internal#sMappingsEx and delegate to GT_Recipe_Map#sMappings instead Remove recipe modification check * Boiler * Programmed Circuit & Super Bus * Lower the number of fluid slots for multi mixer NEI * Solar Generator * Crop Manager * Bronze Workbench & Advanced Workbench * Turbine Housing & Rotor Assembly * Iron Plated Blast Furnace * Player Safe * Advanced Muffler Hatch * spotlessApply * Auto Workbench * Breaker, Control Core, RTG Hatch, Steam Bus, some cleanup * Fix crash when removing Breaker * Data Orb Repository * Charging/Discharging Bus * Pollution Scrubber * Storage Crate, Shelf, TieredChest They're just broken in the first place, don't blame me * cleanup * Steam Condenser It's broken in the first place, never blame me! * Catalyst Housing, Ball Housing * Fluid Tank, generators, custom hatches, cleanup * Computer Cube MKII Many things are broken in the first place, I swear * Inventory Manager * Migrate multiblock dehydrator recipemap to ModularUI * Overflow cover * Redstone Circuit Block * Multiblock * cleanup * Update GT --- .../core/item/chemistry/AgriculturalChem.java | 4 +- .../core/item/chemistry/GenericChem.java | 4 +- .../item/circuit/GTPP_IntegratedCircuit_Item.java | 214 +++++++++++++++++ .../core/item/circuit/ItemAdvancedChip.java | 259 --------------------- 4 files changed, 218 insertions(+), 263 deletions(-) create mode 100644 src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java delete mode 100644 src/main/java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java (limited to 'src/main/java/gtPlusPlus/core/item') diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java index 84e02d452f..017b23d02f 100644 --- a/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java +++ b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java @@ -6,6 +6,7 @@ import gtPlusPlus.api.helpers.MaterialHelper; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.item.circuit.GTPP_IntegratedCircuit_Item; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.ELEMENT; @@ -17,7 +18,6 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.plugin.agrichem.BioRecipes; import gtPlusPlus.plugin.agrichem.item.algae.ItemAgrichemBase; import gtPlusPlus.plugin.agrichem.item.algae.ItemAlgaeBase; -import gtPlusPlus.plugin.agrichem.item.algae.ItemBioChip; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import java.lang.reflect.Field; import java.util.ArrayList; @@ -152,7 +152,7 @@ public class AgriculturalChem extends ItemPackage { mAlgae = new ItemAlgaeBase(); mAgrichemItem1 = new ItemAgrichemBase(); - mBioCircuit = new ItemBioChip(); + mBioCircuit = new GTPP_IntegratedCircuit_Item("BioRecipeSelector", "bioscience/BioCircuit"); GregtechItemList.Circuit_BioRecipeSelector.set(mBioCircuit); mAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 0, 1); diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java index d5224f48e4..31e2492259 100644 --- a/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java +++ b/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java @@ -5,7 +5,7 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.minecraft.ItemPackage; import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; -import gtPlusPlus.core.item.circuit.ItemAdvancedChip; +import gtPlusPlus.core.item.circuit.GTPP_IntegratedCircuit_Item; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.*; import gtPlusPlus.core.material.state.MaterialState; @@ -126,7 +126,7 @@ public class GenericChem extends ItemPackage { MaterialGenerator.generate(TEFLON, false); mGenericChemItem1 = new ItemGenericChemBase(); - mAdvancedCircuit = new ItemAdvancedChip(); + mAdvancedCircuit = new GTPP_IntegratedCircuit_Item("T3RecipeSelector", "science/general/AdvancedCircuit"); GregtechItemList.Circuit_T3RecipeSelector.set(mAdvancedCircuit); registerItemStacks(); diff --git a/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java b/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java new file mode 100644 index 0000000000..cbc7be7efc --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java @@ -0,0 +1,214 @@ +package gtPlusPlus.core.item.circuit; + +import com.gtnewhorizons.modularui.api.UIInfos; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +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 gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Predicate; +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.EnumRarity; +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 org.apache.commons.lang3.tuple.Pair; + +public class GTPP_IntegratedCircuit_Item extends Item implements INetworkUpdatableItem { + private final List ALL_VARIANTS = new ArrayList<>(); + + private final String iconLocation; + protected IIcon base; + + public GTPP_IntegratedCircuit_Item(String unlocalizedName, String iconLocation) { + this.setHasSubtypes(true); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + this.setUnlocalizedName(unlocalizedName); + this.iconLocation = iconLocation; + 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 + public boolean isDamageable() { + return false; + } + + @Override + 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(); + } + super.addInformation(aStack, p_77624_2_, aList, p_77624_4_); + } + + @Override + public EnumRarity getRarity(ItemStack p_77613_1_) { + return EnumRarity.common; + } + + @Override + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + aList.add(ItemUtils.simpleMetaStack(aItem, 0, 1)); + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public void registerIcons(final IIconRegister u) { + this.base = u.registerIcon(CORE.MODID + ":" + iconLocation); + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + return this.base; + } + + @Override + public IIcon getIconFromDamage(int damage) { + return this.base; + } + + @Override + public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { + return this.base; + } + + @Override + public IIcon getIcon(ItemStack stack, int pass) { + return this.base; + } + + @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 ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + // nothing on server side or fake player + if (player instanceof FakePlayer || !world.isRemote) return stack; + // 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 stack; + } + configuratorStack = player.inventory.mainInventory[configurator.getKey()]; + } + openSelectorGui(configuratorStack, stack.getItemDamage(), player); + return stack; + } + + private void openSelectorGui(ItemStack configurator, int meta, EntityPlayer player) { + UIInfos.openClientUI(player, buildContext -> new SelectItemUIFactory( + StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"), + configurator, + GTPP_IntegratedCircuit_Item::onConfigured, + ALL_VARIANTS, + meta, + true) + .createWindow(buildContext)); + } + + 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; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java b/src/main/java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java deleted file mode 100644 index d76a71d24e..0000000000 --- a/src/main/java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java +++ /dev/null @@ -1,259 +0,0 @@ -package gtPlusPlus.core.item.circuit; - -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 java.util.*; -import java.util.function.BiFunction; -import java.util.function.Predicate; -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.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 implements INetworkUpdatableItem { - private static final List ALL_VARIANTS = new ArrayList<>(); - protected IIcon base; - - public ItemAdvancedChip() { - this.setHasSubtypes(true); - this.setNoRepair(); - this.setMaxStackSize(64); - 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 - public boolean isDamageable() { - return false; - } - - @Override - public boolean shouldRotateAroundWhenRendering() { - return super.shouldRotateAroundWhenRendering(); - } - - @Override - public void onUpdate( - ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) { - super.onUpdate(p_77663_1_, p_77663_2_, p_77663_3_, p_77663_4_, p_77663_5_); - } - - @Override - public String getItemStackDisplayName(ItemStack aStack) { - return super.getItemStackDisplayName(aStack); - } - - @Override - 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(); - } - super.addInformation(aStack, p_77624_2_, aList, p_77624_4_); - } - - @Override - public EnumRarity getRarity(ItemStack p_77613_1_) { - return EnumRarity.common; - } - - @Override - public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { - aList.add(ItemUtils.simpleMetaStack(aItem, 0, 1)); - } - - @Override - public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { - return false; - } - - @Override - public boolean isRepairable() { - return false; - } - - @Override - public boolean isBookEnchantable(ItemStack stack, ItemStack book) { - return false; - } - - @Override - public int getDisplayDamage(ItemStack stack) { - return stack.getItemDamage(); - } - - @Override - public boolean showDurabilityBar(ItemStack stack) { - return false; - } - - @Override - public int getItemEnchantability() { - return 0; - } - - @Override - public int getItemEnchantability(ItemStack stack) { - return 0; - } - - @Override - public void registerIcons(final IIconRegister u) { - this.base = u.registerIcon(CORE.MODID + ":" + "science/general/AdvancedCircuit"); - } - - @Override - public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { - return this.base; - } - - @Override - public IIcon getIconFromDamage(int damage) { - return this.base; - } - - @Override - public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { - return this.base; - } - - @Override - public IIcon getIcon(ItemStack stack, int pass) { - return this.base; - } - - @Override - 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