Skip to content

Commit

Permalink
Make it so that energy tablets can stack (mekanism/Mekanism-Feature-R…
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Mar 1, 2024
1 parent 69787db commit d603edc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/main/java/mekanism/common/item/ItemEnergized.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class ItemEnergized extends Item implements ICustomCreativeTabContents, I
protected final Predicate<@NotNull AutomationType> canInsert;

public ItemEnergized(FloatingLongSupplier chargeRateSupplier, FloatingLongSupplier maxEnergySupplier, Properties properties) {
this(chargeRateSupplier, maxEnergySupplier, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue, properties);
this(chargeRateSupplier, maxEnergySupplier, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue, properties.stacksTo(1));
}

public ItemEnergized(FloatingLongSupplier chargeRateSupplier, FloatingLongSupplier maxEnergySupplier, Predicate<@NotNull AutomationType> canExtract,
Predicate<@NotNull AutomationType> canInsert, Properties properties) {
super(properties.stacksTo(1));
super(properties);
this.chargeRateSupplier = chargeRateSupplier;
this.maxEnergySupplier = maxEnergySupplier;
this.canExtract = canExtract;
Expand All @@ -43,7 +43,8 @@ public ItemEnergized(FloatingLongSupplier chargeRateSupplier, FloatingLongSuppli

@Override
public boolean isBarVisible(@NotNull ItemStack stack) {
return true;
//If we are currently stacked, don't display the bar as it will overlap the stack count
return stack.getCount() == 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ public boolean isBarVisible(@NotNull ItemStack stack) {

@Override
public int getBarWidth(@NotNull ItemStack stack) {
if (stack.getCount() > 1) {
//Note: Technically this is handled by the below check as the capability isn't exposed (so this isn't even visible),
// but we may as well short circuit it here
return 0;
}
return StorageUtils.getBarWidth(stack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ protected void addTypeDetails(@NotNull ItemStack stack, Level world, @NotNull Li

@Override
public boolean isBarVisible(@NotNull ItemStack stack) {
//If We are currently stacked, don't display the bar as it will overlap the stack count
//If we are currently stacked, don't display the bar as it will overlap the stack count
return stack.getCount() == 1;
}

@Override
public int getBarWidth(@NotNull ItemStack stack) {
if (stack.getCount() > 1) {
//Note: Technically this is handled by the below check as the capability isn't exposed (so this isn't even visible),
// but we may as well short circuit it here
return 0;
}
return StorageUtils.getEnergyBarWidth(stack);
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/mekanism/common/util/StorageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ public static Component getStoragePercent(double ratio, boolean colorText) {
}

public static int getBarWidth(ItemStack stack) {
if (stack.getCount() > 1) {
//Note: Technically this is handled by the below check as the capability isn't exposed (so this isn't even visible),
// but we may as well short circuit it here
return 0;
}
return MathUtils.clampToInt(Math.round(13.0F - 13.0F * getDurabilityForDisplay(stack)));
}

Expand All @@ -375,6 +380,11 @@ private static double getDurabilityForDisplay(ItemStack stack) {
}

public static int getEnergyBarWidth(ItemStack stack) {
if (stack.getCount() > 1) {
//Note: Technically this is handled by the below check as the capability isn't exposed (so this isn't even visible),
// but we may as well short circuit it here
return 0;
}
return MathUtils.clampToInt(Math.round(13.0F - 13.0F * getEnergyDurabilityForDisplay(stack)));
}

Expand Down

0 comments on commit d603edc

Please sign in to comment.