Skip to content

Commit 21cc7ae

Browse files
committed
fix isItemChargable
1 parent a5ccc60 commit 21cc7ae

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

src/main/java/gregtech/api/util/GTUtility.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import gregtech.api.unification.stack.ItemAndMetadata;
2424
import gregtech.api.util.function.impl.TimedProgressSupplier;
2525

26+
import gregtech.common.ConfigHolder;
27+
2628
import net.minecraft.block.BlockRedstoneWire;
2729
import net.minecraft.block.BlockSnow;
2830
import net.minecraft.block.material.MapColor;
@@ -1035,39 +1037,26 @@ public static int combineRGB(@Range(from = 0, to = 255) int a, @Range(from = 0,
10351037
return map.get(key.toWildcard());
10361038
}
10371039

1038-
/**
1039-
* Check if an {@link ItemStack} is chargeable.
1040-
*
1041-
* @param stack the stack to check
1042-
* @param tier if the item is a GT energy item, the minimum tier it has to be
1043-
* @param checkCharge whether to check if it is fully charged or not
1044-
* @return if the stack is electric and meets the supplied conditions
1045-
*/
1046-
public static boolean isItemChargeable(@NotNull ItemStack stack, int tier, boolean checkCharge) {
1040+
public static boolean isItemChargableWithEU(@NotNull ItemStack stack, int tier) {
10471041
IElectricItem euItem = stack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
10481042
if (euItem != null) {
10491043
return euItem.chargeable() && euItem.getCharge() < euItem.getMaxCharge() && euItem.getTier() <= tier;
10501044
}
10511045

1052-
IEnergyStorage rfItem = stack.getCapability(CapabilityEnergy.ENERGY, null);
1053-
if (rfItem != null) {
1054-
return rfItem.canReceive() && rfItem.getEnergyStored() < rfItem.getMaxEnergyStored();
1046+
if (ConfigHolder.compat.energy.nativeEUToFE) {
1047+
IEnergyStorage rfItem = stack.getCapability(CapabilityEnergy.ENERGY, null);
1048+
if (rfItem != null) {
1049+
return rfItem.canReceive() && rfItem.getEnergyStored() < rfItem.getMaxEnergyStored();
1050+
}
10551051
}
10561052

10571053
return false;
10581054
}
10591055

10601056
/**
1061-
* See {@link #isItemChargeable(ItemStack, int, boolean)}
1062-
*/
1063-
public static boolean isItemChargeable(@NotNull ItemStack stack) {
1064-
return isItemChargeable(stack, GTValues.MAX_TRUE, true);
1065-
}
1066-
1067-
/**
1068-
* Get the level of charge from 0 to 1 of an item
1057+
* Get the level of charge from 0 to 1 of an item.
10691058
*
1070-
* @return 0 if the supplied item is not electric
1059+
* @return -1 if the supplied item is not electric
10711060
*/
10721061
public static float itemChargeLevel(@NotNull ItemStack stack) {
10731062
if (stack.isEmpty()) return 0.0f;
@@ -1082,7 +1071,7 @@ public static float itemChargeLevel(@NotNull ItemStack stack) {
10821071
return (float) rfItem.getEnergyStored() / rfItem.getMaxEnergyStored();
10831072
}
10841073

1085-
return 0.0f;
1074+
return -1.0f;
10861075
}
10871076

10881077
/**

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityCharger.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ protected void onContentsChanged(int slot) {
6565
@NotNull
6666
@Override
6767
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
68-
return GTUtility.isItemChargeable(stack, getTier(), true) ? super.insertItem(slot, stack, simulate) :
69-
stack;
68+
if (GTUtility.isItemChargableWithEU(stack, getTier())) {
69+
return super.insertItem(slot, stack, simulate);
70+
}
71+
72+
return stack;
7073
}
7174

7275
@Override

0 commit comments

Comments
 (0)