aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/item
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2021-12-12 14:29:34 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2021-12-12 14:29:34 +0000
commit8752df0b865c1a4104851da6ca100ad28952408d (patch)
treea9fbd24dffbcc9adcab1d14b52487032b64286f2 /src/Java/gtPlusPlus/core/item
parent210f8cb4730b8472e0e86a53ed99616e7183b6a5 (diff)
parent9cbfc7a1bacdbe908632e0fff9ec5ad7f119e563 (diff)
downloadGT5-Unofficial-8752df0b865c1a4104851da6ca100ad28952408d.tar.gz
GT5-Unofficial-8752df0b865c1a4104851da6ca100ad28952408d.tar.bz2
GT5-Unofficial-8752df0b865c1a4104851da6ca100ad28952408d.zip
Merge branch 'master' of https://github.com/GTNewHorizons/GTplusplus into gtnh-milling
# Conflicts: # build.properties # src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java # src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java # src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java # src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java
Diffstat (limited to 'src/Java/gtPlusPlus/core/item')
-rw-r--r--src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java17
-rw-r--r--src/Java/gtPlusPlus/core/item/circuit/ItemAdvancedChip.java109
2 files changed, 108 insertions, 18 deletions
diff --git a/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/Java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java
index ed17f8547a..9a00b49342 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 / 100;
- 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 / 100;
- return durabilitypercent;
+ return currentDamage / getCatalystMaxDamage(aStack);
}
else {
return 1D;
@@ -208,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){
@@ -220,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);
@@ -322,6 +315,4 @@ public class ItemGenericChemBase extends Item {
public static int getMaxCatalystDurability(ItemStack aStack) {
return 50;
}
-
-
}
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;
+ }
}