Try to place block once item is available

This commit is contained in:
Bartek Bok 2017-07-30 15:09:14 +02:00
parent d824edd688
commit 42d038e89f
No known key found for this signature in database
GPG Key ID: D4AB7344B821F0B5
2 changed files with 17 additions and 4 deletions

View File

@ -31,13 +31,18 @@ public abstract class TileEntityBlockManipulator extends OpenTileEntity implemen
}
if (isPowered)
triggerBreakBlock(newState);
triggerBlockAction(newState);
}
}
}
private void triggerBreakBlock(IBlockState newState) {
final EnumFacing direction = getFront(newState);
protected void triggerBlockAction() {
final IBlockState state = worldObj.getBlockState(getPos());
triggerBlockAction(state);
}
private void triggerBlockAction(IBlockState state) {
final EnumFacing direction = getFront(state);
final BlockPos target = pos.offset(direction);
if (worldObj.isBlockLoaded(target)) {

View File

@ -16,6 +16,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
import openblocks.client.gui.GuiBlockPlacer;
import openblocks.common.container.ContainerBlockPlacer;
import openmods.api.IHasGui;
import openmods.api.IInventoryCallback;
import openmods.fakeplayer.FakePlayerPool;
import openmods.fakeplayer.UseItemAction;
import openmods.include.IncludeInterface;
@ -27,7 +28,14 @@ public class TileEntityBlockPlacer extends TileEntityBlockManipulator implements
static final int BUFFER_SIZE = 9;
private final GenericInventory inventory = registerInventoryCallback(new TileEntityInventory(this, "blockPlacer", false, BUFFER_SIZE));
private final GenericInventory inventory = new TileEntityInventory(this, "blockPlacer", false, BUFFER_SIZE)
.addCallback(new IInventoryCallback() {
@Override
public void onInventoryChanged(IInventory inventory, int slotNumber) {
markUpdated();
triggerBlockAction();
}
});
@Override
protected boolean canWork(IBlockState targetState, BlockPos target, EnumFacing direction) {