Skip to content

Commit d689574

Browse files
committed
Update HeatCollectorTileEntity.java
1 parent 5a9ca16 commit d689574

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/main/java/io/github/cadiboo/examplemod/tileentity/HeatCollectorTileEntity.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected void onContentsChanged(final int slot) {
7070
private final LazyOptional<ItemStackHandler> inventoryCapabilityExternal = LazyOptional.of(() -> this.inventory);
7171
private final LazyOptional<EnergyStorage> energyCapabilityExternal = LazyOptional.of(() -> this.energy);
7272

73-
private int lastSyncedEnergy = -1;
73+
private int lastEnergy = -1;
7474

7575
public HeatCollectorTileEntity() {
7676
super(ModTileEntityTypes.HEAT_COLLECTOR);
@@ -111,7 +111,7 @@ else if (blockState.getBlock() == Blocks.CAMPFIRE)
111111
if (fluidState.isTagged(FluidTags.LAVA))
112112
fireEnergy += 50;
113113

114-
if(fireEnergy > 0)
114+
if (fireEnergy > 0)
115115
energy.receiveEnergy(fireEnergy, false);
116116

117117
}
@@ -143,7 +143,7 @@ else if (blockState.getBlock() == Blocks.CAMPFIRE)
143143
}
144144

145145
// If the energy has changed.
146-
if (lastSyncedEnergy != energy.getEnergyStored()) {
146+
if (lastEnergy != energy.getEnergyStored()) {
147147

148148
// "markDirty" tells vanilla that the chunk containing the tile entity has
149149
// changed and means the game will save the chunk to disk later.
@@ -157,7 +157,7 @@ else if (blockState.getBlock() == Blocks.CAMPFIRE)
157157
world.notifyBlockUpdate(pos, blockState, blockState, 2);
158158

159159
// Update the last synced energy to the current energy
160-
lastSyncedEnergy = energy.getEnergyStored();
160+
lastEnergy = energy.getEnergyStored();
161161
}
162162

163163
}
@@ -186,7 +186,7 @@ public void onLoad() {
186186
// We set this in onLoad instead of the constructor so that TileEntities
187187
// constructed from NBT (saved tile entities) have this set to the proper value
188188
if (world != null && !world.isRemote)
189-
lastSyncedEnergy = energy.getEnergyStored();
189+
lastEnergy = energy.getEnergyStored();
190190
}
191191

192192
/**
@@ -234,6 +234,18 @@ public CompoundNBT getUpdateTag() {
234234
return this.write(new CompoundNBT());
235235
}
236236

237+
/**
238+
* Invalidates our tile entity
239+
*/
240+
@Override
241+
public void remove() {
242+
super.remove();
243+
// We need to invalidate our capability references so that any cached references (by other mods) don't
244+
// continue to reference our capabilities and try to use them and/or prevent them from being garbage collected
245+
inventoryCapabilityExternal.invalidate();
246+
energyCapabilityExternal.invalidate();
247+
}
248+
237249
@Nonnull
238250
@Override
239251
public ITextComponent getDisplayName() {

0 commit comments

Comments
 (0)