Fixed crash with the Constructor, fixes #1546

This commit is contained in:
raoulvdberge
2017-11-26 11:20:38 +01:00
parent 1cb72d9cb3
commit f6afe6fef1
3 changed files with 76 additions and 76 deletions

View File

@@ -6,6 +6,7 @@
- Added a "detailed" variant for every Grid view type option, to disable the modified information on the tooltip (raoulvdberge) - Added a "detailed" variant for every Grid view type option, to disable the modified information on the tooltip (raoulvdberge)
- Removed craft-only mode for the Exporter (raoulvdberge) - Removed craft-only mode for the Exporter (raoulvdberge)
- Fixed Exporter with Stack Upgrade not working correctly in Regulator Mode (raoulvdberge) - Fixed Exporter with Stack Upgrade not working correctly in Regulator Mode (raoulvdberge)
- Fixed crash with the Constructor (raoulvdberge)
### 1.5.23 ### 1.5.23
- Fixed duplication bug with autocrafting (raoulvdberge) - Fixed duplication bug with autocrafting (raoulvdberge)

View File

@@ -51,16 +51,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
private static final int BASE_SPEED = 20; private static final int BASE_SPEED = 20;
private ItemHandlerBase itemFilters = new ItemHandlerBase(1, new ItemHandlerListenerNetworkNode(this)) { private ItemHandlerBase itemFilters = new ItemHandlerBase(1, new ItemHandlerListenerNetworkNode(this));
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
item = getStackInSlot(slot).isEmpty() ? null : getStackInSlot(slot).copy();
block = SlotFilter.getBlockState(world, pos.offset(getDirection()), getStackInSlot(slot));
}
};
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(1, new ItemHandlerListenerNetworkNode(this)); private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(1, new ItemHandlerListenerNetworkNode(this));
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_CRAFTING, ItemUpgrade.TYPE_STACK); private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_CRAFTING, ItemUpgrade.TYPE_STACK);
@@ -69,9 +60,6 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
private int type = IType.ITEMS; private int type = IType.ITEMS;
private boolean drop = false; private boolean drop = false;
private IBlockState block;
private ItemStack item;
public NetworkNodeConstructor(World world, BlockPos pos) { public NetworkNodeConstructor(World world, BlockPos pos) {
super(world, pos); super(world, pos);
} }
@@ -86,14 +74,18 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
super.update(); super.update();
if (network != null && canUpdate() && ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) { if (network != null && canUpdate() && ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
if (type == IType.ITEMS) { if (type == IType.ITEMS && !itemFilters.getStackInSlot(0).isEmpty()) {
ItemStack item = itemFilters.getStackInSlot(0);
IBlockState block = SlotFilter.getBlockState(world, pos.offset(getDirection()), item);
if (block != null) { if (block != null) {
if (drop && item != null) { if (drop) {
dropItem(); dropItem();
} else { } else {
placeBlock(); placeBlock();
} }
} else if (item != null) { } else {
if (item.getItem() == Items.FIREWORKS && !drop) { if (item.getItem() == Items.FIREWORKS && !drop) {
ItemStack took = network.extractItem(item, 1, false); ItemStack took = network.extractItem(item, 1, false);
@@ -104,7 +96,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
dropItem(); dropItem();
} }
} }
} else if (type == IType.FLUIDS) { } else if (type == IType.FLUIDS && !fluidFilters.getStackInSlot(0).isEmpty()) {
FluidStack stack = fluidFilters.getFluidStackInSlot(0); FluidStack stack = fluidFilters.getFluidStackInSlot(0);
if (stack != null && stack.getFluid().canBePlacedInWorld()) { if (stack != null && stack.getFluid().canBePlacedInWorld()) {
@@ -149,18 +141,23 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
private void placeBlock() { private void placeBlock() {
BlockPos front = pos.offset(getDirection()); BlockPos front = pos.offset(getDirection());
if (world.isAirBlock(front) && block.getBlock().canPlaceBlockAt(world, front)) { ItemStack item = itemFilters.getStackInSlot(0);
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare, true);
ItemStack took = network.extractItem(item, 1, compare, true);
if (took != null) { if (took != null) {
IBlockState state = block.getBlock().getStateForPlacement(world, front, getDirection(), 0.5F, 0.5F, 0.5F, took.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) world), EnumHand.MAIN_HAND); IBlockState state = SlotFilter.getBlockState(world, front, took);
if (state != null && world.isAirBlock(front) && state.getBlock().canPlaceBlockAt(world, front)) {
state = state.getBlock().getStateForPlacement(world, front, getDirection(), 0.5F, 0.5F, 0.5F, took.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) world), EnumHand.MAIN_HAND);
if (!canPlace(front, state)) { if (!canPlace(front, state)) {
return; return;
} }
took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare, false); took = network.extractItem(item, 1, compare, false);
if (took != null) {
if (item.getItem() instanceof ItemBlock) { if (item.getItem() instanceof ItemBlock) {
((ItemBlock) item.getItem()).placeBlockAt( ((ItemBlock) item.getItem()).placeBlockAt(
took, took,
@@ -180,10 +177,10 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
} }
// From ItemBlock#onItemUse // From ItemBlock#onItemUse
SoundType blockSound = block.getBlock().getSoundType(state, world, pos, null); SoundType blockSound = state.getBlock().getSoundType(state, world, pos, null);
world.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F); world.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F);
if (block.getBlock() == Blocks.SKULL) { if (state.getBlock() == Blocks.SKULL) {
world.setBlockState(front, world.getBlockState(front).withProperty(BlockSkull.FACING, getDirection())); world.setBlockState(front, world.getBlockState(front).withProperty(BlockSkull.FACING, getDirection()));
TileEntity tile = world.getTileEntity(front); TileEntity tile = world.getTileEntity(front);
@@ -211,7 +208,8 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
Blocks.SKULL.checkWitherSpawn(world, front, skullTile); Blocks.SKULL.checkWitherSpawn(world, front, skullTile);
} }
}
}
} }
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) { } else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0); ItemStack craft = itemFilters.getStackInSlot(0);
@@ -219,10 +217,9 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
network.getCraftingManager().schedule(craft, 1, compare); network.getCraftingManager().schedule(craft, 1, compare);
} }
} }
}
private void dropItem() { private void dropItem() {
ItemStack took = network.extractItem(item, upgrades.getItemInteractCount(), false); ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getItemInteractCount(), false);
if (took != null) { if (took != null) {
BehaviorDefaultDispenseItem.doDispense(world, took, 6, getDirection(), new PositionImpl(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ())); BehaviorDefaultDispenseItem.doDispense(world, took, 6, getDirection(), new PositionImpl(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));

View File

@@ -12,6 +12,7 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.SlotItemHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class SlotFilter extends SlotItemHandler { public class SlotFilter extends SlotItemHandler {
public static final int FILTER_ALLOW_SIZE = 1; public static final int FILTER_ALLOW_SIZE = 1;
@@ -64,7 +65,8 @@ public class SlotFilter extends SlotItemHandler {
return (flags & FILTER_ALLOW_BLOCKS) == FILTER_ALLOW_BLOCKS; return (flags & FILTER_ALLOW_BLOCKS) == FILTER_ALLOW_BLOCKS;
} }
public static IBlockState getBlockState(IBlockAccess world, BlockPos pos, ItemStack stack) { @Nullable
public static IBlockState getBlockState(IBlockAccess world, BlockPos pos, @Nullable ItemStack stack) {
if (stack != null) { if (stack != null) {
Item item = stack.getItem(); Item item = stack.getItem();