Try to fix player interface capability invalidation.

This commit is contained in:
Flanks255 2024-03-15 17:30:51 -05:00
parent 58034533f9
commit 44e055499e
2 changed files with 6 additions and 6 deletions

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -55,7 +54,6 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
return null; return null;
} }
// TODO: [port] this might not be a stable way of doing this.
@Override @Override
public IItemHandler getItemHandler(Direction facing) { public IItemHandler getItemHandler(Direction facing) {
Player player = this.getPlayer(); Player player = this.getPlayer();
@ -66,6 +64,8 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
this.playerHandler = player == null this.playerHandler = player == null
? null ? null
: new PlayerInvWrapper(player.getInventory()); : new PlayerInvWrapper(player.getInventory());
this.invalidateCapabilities();
} }
return this.playerHandler; return this.playerHandler;
@ -90,7 +90,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
for (int i = 0; i < player.getInventory().getContainerSize(); i++) { for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
if (tile.storage.getEnergyStored() > 0) { if (tile.storage.getEnergyStored() > 0) {
ItemStack slot = player.getInventory().getItem(i); ItemStack slot = player.getInventory().getItem(i);
if (StackUtil.isValid(slot) && slot.getCount() == 1) { if (!slot.isEmpty() && slot.getCount() == 1) {
int received = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM)) int received = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM))
.map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); .map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0);

View file

@ -173,9 +173,9 @@
"block.actuallyadditions.leaf_generator": "Leaf-Eating Generator", "block.actuallyadditions.leaf_generator": "Leaf-Eating Generator",
"block.actuallyadditions.long_range_breaker": "Long-Range Breaker", "block.actuallyadditions.long_range_breaker": "Long-Range Breaker",
"block.actuallyadditions.ranged_collector": "Ranged Collector", "block.actuallyadditions.ranged_collector": "Ranged Collector",
"block.actuallyadditions.laser_relay": "Energy Laser Relay (wip)", "block.actuallyadditions.laser_relay": "Energy Laser Relay",
"block.actuallyadditions.laser_relay_advanced": "Advanced Energy Laser Relay (wip)", "block.actuallyadditions.laser_relay_advanced": "Advanced Energy Laser Relay",
"block.actuallyadditions.laser_relay_extreme": "Extreme Energy Laser Relay (wip)", "block.actuallyadditions.laser_relay_extreme": "Extreme Energy Laser Relay",
"block.actuallyadditions.laser_relay_fluids": "Fluid Laser Relay (wip)", "block.actuallyadditions.laser_relay_fluids": "Fluid Laser Relay (wip)",
"block.actuallyadditions.iron_casing": "Iron Casing", "block.actuallyadditions.iron_casing": "Iron Casing",
"block.actuallyadditions.black_lotus": "Black Lotus", "block.actuallyadditions.black_lotus": "Black Lotus",