Skip to content

Commit 124c9fa

Browse files
committed
Fix bin lock state and resistive heater energy usage not being persisted when broken
1 parent a79a447 commit 124c9fa

22 files changed

+129
-96
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ of things that we haven't finished porting yet.
2828

2929
## Known Bugs/Things that aren't done being ported yet ##
3030
- Options in the Module Tweaker that have side effects don't currently have those side effects displayed
31-
- Resistive Heaters do not keep their set Energy Usage when breaking and placing again
32-
- Bins forget if they are locked and what they are locked too if broken and placed
31+
- Fixed (Upcoming 10.6.2): Resistive Heaters do not keep their set Energy Usage when breaking and placing again
32+
- Fixed (Upcoming 10.6.2): Bins forget if they are locked and what they are locked too if broken and placed
3333
- When breaking and placing blocks that have fluid item input slots, they do not persist whether the item was actively being drained or whether it was being filled
3434
- The QIO Dashboard does not persist items stored in crafting windows when broken
3535
- The Portable QIO Dashboard's Crafting windows do not work at all. DO NOT TRY TO USE THEM

src/datagen/generated/mekanism/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/advanced_bin.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/basic_bin.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/creative_bin.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/elite_bin.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/resistive_heater.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datagen/generated/mekanism/data/mekanism/loot_table/blocks/ultimate_bin.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/mekanism/common/attachments/LockData.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public record LockData(ItemStack lock) {
2222
lock = lock.copy();
2323
}
2424

25+
public static LockData create(ItemStack lock) {
26+
if (lock.isEmpty()) {
27+
return EMPTY;
28+
}
29+
return new LockData(lock.copyWithCount(1));
30+
}
31+
2532
@Override
2633
public boolean equals(Object o) {
2734
if (this == o) {

src/main/java/mekanism/common/attachments/containers/energy/ComponentBackedResistiveEnergyContainer.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,69 @@
11
package mekanism.common.attachments.containers.energy;
22

3-
import java.util.Objects;
3+
import mekanism.api.AutomationType;
44
import mekanism.api.SerializationConstants;
55
import mekanism.api.annotations.NothingNullByDefault;
66
import mekanism.api.math.FloatingLong;
77
import mekanism.api.math.FloatingLongSupplier;
88
import mekanism.common.attachments.containers.ContainerType;
9-
import mekanism.common.block.attribute.AttributeEnergy;
109
import mekanism.common.capabilities.energy.BasicEnergyContainer;
1110
import mekanism.common.capabilities.energy.ResistiveHeaterEnergyContainer;
12-
import mekanism.common.registries.MekanismBlockTypes;
11+
import mekanism.common.registries.MekanismDataComponents;
12+
import mekanism.common.tile.machine.TileEntityResistiveHeater;
1313
import mekanism.common.util.NBTUtils;
1414
import net.minecraft.core.HolderLookup;
1515
import net.minecraft.nbt.CompoundTag;
1616
import net.minecraft.world.item.ItemStack;
17+
import org.jetbrains.annotations.Nullable;
1718

18-
@NothingNullByDefault//TODO - 1.21: Figure out how to implement this properly??
19+
@NothingNullByDefault
1920
public class ComponentBackedResistiveEnergyContainer extends ComponentBackedEnergyContainer {
2021

22+
private static final FloatingLongSupplier SUPPLIES_ZERO = () -> FloatingLong.ZERO;
23+
2124
public static ComponentBackedResistiveEnergyContainer create(ContainerType<?, ?, ?> ignored, ItemStack attachedTo, int containerIndex) {
22-
AttributeEnergy attributeEnergy = Objects.requireNonNull(MekanismBlockTypes.RESISTIVE_HEATER.get(AttributeEnergy.class));
23-
return new ComponentBackedResistiveEnergyContainer(attachedTo, containerIndex, () -> attributeEnergy.getStorage().multiply(0.005),
24-
attributeEnergy::getStorage, attributeEnergy.getUsage());
25+
return new ComponentBackedResistiveEnergyContainer(attachedTo, containerIndex);
2526
}
2627

27-
private FloatingLong currentMaxEnergy;
28-
private FloatingLong energyPerTick;
29-
30-
private ComponentBackedResistiveEnergyContainer(ItemStack attachedTo, int containerIndex, FloatingLongSupplier rate, FloatingLongSupplier capacity,
31-
FloatingLong baseEnergyPerTick) {
32-
super(attachedTo, containerIndex, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue, rate, capacity);
33-
this.currentMaxEnergy = super.getMaxEnergy();
34-
this.energyPerTick = baseEnergyPerTick.copyAsConst();
28+
private ComponentBackedResistiveEnergyContainer(ItemStack attachedTo, int containerIndex) {
29+
super(attachedTo, containerIndex, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue, SUPPLIES_ZERO, SUPPLIES_ZERO);
3530
}
3631

3732
@Override
3833
public FloatingLong getMaxEnergy() {
39-
return currentMaxEnergy;
34+
return getEnergyPerTick().multiply(ResistiveHeaterEnergyContainer.USAGE_MULTIPLIER);
35+
}
36+
37+
private FloatingLong getRate() {
38+
return getMaxEnergy().multiply(0.005);
39+
}
40+
41+
@Override
42+
protected FloatingLong getInsertRate(@Nullable AutomationType automationType) {
43+
//Allow unknown or manual interaction to bypass rate limit for the item
44+
return automationType == null || automationType == AutomationType.MANUAL ? FloatingLong.MAX_VALUE : getRate();
45+
}
46+
47+
@Override
48+
protected FloatingLong getExtractRate(@Nullable AutomationType automationType) {
49+
//Allow unknown or manual interaction to bypass rate limit for the item
50+
return automationType == null || automationType == AutomationType.MANUAL ? FloatingLong.MAX_VALUE : getRate();
51+
}
52+
53+
private FloatingLong getEnergyPerTick() {
54+
return attachedTo.getOrDefault(MekanismDataComponents.ENERGY_USAGE, TileEntityResistiveHeater.BASE_USAGE);
4055
}
4156

4257
private void updateEnergyUsage(FloatingLong energyUsage) {
43-
energyPerTick = energyUsage;
44-
this.currentMaxEnergy = energyUsage.multiply(ResistiveHeaterEnergyContainer.USAGE_MULTIPLIER).copyAsConst();
58+
attachedTo.set(MekanismDataComponents.ENERGY_USAGE, energyUsage);
4559
//Clamp the energy
4660
setEnergy(getEnergy());
4761
}
4862

4963
@Override
5064
public CompoundTag serializeNBT(HolderLookup.Provider provider) {
5165
CompoundTag nbt = super.serializeNBT(provider);
52-
nbt.putString(SerializationConstants.ENERGY_USAGE, energyPerTick.toString());
66+
nbt.putString(SerializationConstants.ENERGY_USAGE, getEnergyPerTick().toString());
5367
return nbt;
5468
}
5569

0 commit comments

Comments
 (0)