diff --git a/src/main/java/techreborn/client/container/builder/BuiltContainer.java b/src/main/java/techreborn/client/container/builder/BuiltContainer.java index a1d56bc73..375cf83e5 100644 --- a/src/main/java/techreborn/client/container/builder/BuiltContainer.java +++ b/src/main/java/techreborn/client/container/builder/BuiltContainer.java @@ -24,6 +24,7 @@ package techreborn.client.container.builder; +import ic2.core.energy.grid.Tile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; @@ -32,6 +33,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.Range; import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Pair; +import reborncore.common.tile.TileLegacyMachineBase; import reborncore.common.util.ItemUtils; import techreborn.client.container.IRightClickHandler; @@ -55,9 +57,11 @@ public class BuiltContainer extends Container { private List> craftEvents; private Integer[] integerParts; + private final TileLegacyMachineBase tile; + public BuiltContainer(final String name, final Predicate canInteract, - final List> playerSlotRange, - final List> tileSlotRange) { + final List> playerSlotRange, + final List> tileSlotRange, TileLegacyMachineBase tile) { this.name = name; this.canInteract = canInteract; @@ -67,6 +71,8 @@ public class BuiltContainer extends Container { this.shortValues = new ArrayList<>(); this.integerValues = new ArrayList<>(); + + this.tile = tile; } public void addShortSync(final List> syncables) { @@ -94,7 +100,11 @@ public class BuiltContainer extends Container { @Override public boolean canInteractWith(final EntityPlayer playerIn) { - return this.canInteract.test(playerIn); + if(this.tile != null) { + return tile.isUsableByPlayer(playerIn); + } else { + return this.canInteract.test(playerIn); // <- What does this thing do ? + } } @Override diff --git a/src/main/java/techreborn/client/container/builder/ContainerBuilder.java b/src/main/java/techreborn/client/container/builder/ContainerBuilder.java index b30e9d23e..1baebec56 100644 --- a/src/main/java/techreborn/client/container/builder/ContainerBuilder.java +++ b/src/main/java/techreborn/client/container/builder/ContainerBuilder.java @@ -31,6 +31,7 @@ import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import org.apache.commons.lang3.Range; import org.apache.commons.lang3.tuple.Pair; +import reborncore.common.tile.TileLegacyMachineBase; import java.util.ArrayList; import java.util.List; @@ -88,10 +89,32 @@ public class ContainerBuilder { this.tileInventoryRanges.add(range); } + @Deprecated + /** + * The container have to know if the tile is still available (the block was not destroyed) + * and if the player is not to far from him to close the GUI if necessary + */ public BuiltContainer create() { final BuiltContainer built = new BuiltContainer(this.name, this.canInteract, this.playerInventoryRanges, - this.tileInventoryRanges); + this.tileInventoryRanges, null); + if (!this.shortValues.isEmpty()) + built.addShortSync(this.shortValues); + if (!this.integerValues.isEmpty()) + built.addIntegerSync(this.integerValues); + if (!this.craftEvents.isEmpty()) + built.addCraftEvents(this.craftEvents); + + this.slots.forEach(built::addSlot); + + this.slots.clear(); + return built; + } + + public BuiltContainer create(final TileLegacyMachineBase tile) { + final BuiltContainer built = new BuiltContainer(this.name, this.canInteract, + this.playerInventoryRanges, + this.tileInventoryRanges, tile); if (!this.shortValues.isEmpty()) built.addShortSync(this.shortValues); if (!this.integerValues.isEmpty()) diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java index d9cbd1137..b0f65e9f1 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java @@ -365,6 +365,6 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IInv .syncIntegerValue(this::getCoilStatus, this::setCoilStatus) .syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime) .syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime) - .syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(); + .syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this); } }