fix bug duplication #1012

This commit is contained in:
alexpic57 2017-09-08 21:18:57 +02:00
parent 1d873c2d33
commit 885ba9210c
3 changed files with 38 additions and 5 deletions

View file

@ -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<Consumer<InventoryCrafting>> craftEvents;
private Integer[] integerParts;
private final TileLegacyMachineBase tile;
public BuiltContainer(final String name, final Predicate<EntityPlayer> canInteract,
final List<Range<Integer>> playerSlotRange,
final List<Range<Integer>> tileSlotRange) {
final List<Range<Integer>> playerSlotRange,
final List<Range<Integer>> 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<Pair<IntSupplier, IntConsumer>> 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

View file

@ -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())

View file

@ -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);
}
}