diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalAxisKineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalAxisKineticBlock.java index 605184e99..dd623508c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalAxisKineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalAxisKineticBlock.java @@ -27,14 +27,17 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc } protected Direction getFacingForPlacement(BlockItemUseContext context) { - Direction facing = context.getNearestLookingDirection().getOpposite(); - if (context.getPlayer().isSneaking()) + Direction facing = context.getNearestLookingDirection() + .getOpposite(); + if (context.getPlayer() != null && context.getPlayer() + .isSneaking()) facing = facing.getOpposite(); return facing; } protected boolean getAxisAlignmentForPlacement(BlockItemUseContext context) { - return context.getPlacementHorizontalFacing().getAxis() == Axis.X; + return context.getPlacementHorizontalFacing() + .getAxis() == Axis.X; } @Override @@ -44,30 +47,37 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc World world = context.getWorld(); boolean alongFirst = false; - if (facing.getAxis().isHorizontal()) { + if (facing.getAxis() + .isHorizontal()) { alongFirst = facing.getAxis() == Axis.Z; - Block blockAbove = world.getBlockState(pos.offset(Direction.UP)).getBlock(); + Block blockAbove = world.getBlockState(pos.offset(Direction.UP)) + .getBlock(); boolean shaftAbove = blockAbove instanceof IRotate && ((IRotate) blockAbove).hasShaftTowards(world, - pos.up(), world.getBlockState(pos.up()), Direction.DOWN); - Block blockBelow = world.getBlockState(pos.offset(Direction.DOWN)).getBlock(); + pos.up(), world.getBlockState(pos.up()), Direction.DOWN); + Block blockBelow = world.getBlockState(pos.offset(Direction.DOWN)) + .getBlock(); boolean shaftBelow = blockBelow instanceof IRotate && ((IRotate) blockBelow).hasShaftTowards(world, - pos.down(), world.getBlockState(pos.down()), Direction.UP); + pos.down(), world.getBlockState(pos.down()), Direction.UP); if (shaftAbove || shaftBelow) alongFirst = facing.getAxis() == Axis.X; } - if (facing.getAxis().isVertical()) { + if (facing.getAxis() + .isVertical()) { alongFirst = getAxisAlignmentForPlacement(context); Direction prefferedSide = null; for (Direction side : Direction.values()) { - if (side.getAxis().isVertical()) + if (side.getAxis() + .isVertical()) continue; - BlockState blockState = context.getWorld().getBlockState(context.getPos().offset(side)); + BlockState blockState = context.getWorld() + .getBlockState(context.getPos() + .offset(side)); if (blockState.getBlock() instanceof IRotate) { - if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), - context.getPos().offset(side), blockState, side.getOpposite())) + if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos() + .offset(side), blockState, side.getOpposite())) if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) { prefferedSide = null; break; @@ -81,12 +91,15 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc } } - return this.getDefaultState().with(FACING, facing).with(AXIS_ALONG_FIRST_COORDINATE, alongFirst); + return this.getDefaultState() + .with(FACING, facing) + .with(AXIS_ALONG_FIRST_COORDINATE, alongFirst); } @Override public Axis getRotationAxis(BlockState state) { - Axis pistonAxis = state.get(FACING).getAxis(); + Axis pistonAxis = state.get(FACING) + .getAxis(); boolean alongFirst = state.get(AXIS_ALONG_FIRST_COORDINATE); if (pistonAxis == Axis.X) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalKineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalKineticBlock.java index 28b281500..a2bc9e6f4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalKineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/DirectionalKineticBlock.java @@ -27,10 +27,12 @@ public abstract class DirectionalKineticBlock extends KineticBlock { public Direction getPreferredFacing(BlockItemUseContext context) { Direction prefferedSide = null; for (Direction side : Direction.values()) { - BlockState blockState = context.getWorld().getBlockState(context.getPos().offset(side)); + BlockState blockState = context.getWorld() + .getBlockState(context.getPos() + .offset(side)); if (blockState.getBlock() instanceof IRotate) { - if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos().offset(side), - blockState, side.getOpposite())) + if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos() + .offset(side), blockState, side.getOpposite())) if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) { prefferedSide = null; break; @@ -45,10 +47,11 @@ public abstract class DirectionalKineticBlock extends KineticBlock { @Override public BlockState getStateForPlacement(BlockItemUseContext context) { Direction preferred = getPreferredFacing(context); - if (preferred == null || context.getPlayer().isSneaking()) { + if (preferred == null || (context.getPlayer() != null && context.getPlayer() + .isSneaking())) { Direction nearestLookingDirection = context.getNearestLookingDirection(); - return getDefaultState().with(FACING, - context.getPlayer().isSneaking() ? nearestLookingDirection : nearestLookingDirection.getOpposite()); + return getDefaultState().with(FACING, context.getPlayer() != null && context.getPlayer() + .isSneaking() ? nearestLookingDirection : nearestLookingDirection.getOpposite()); } return getDefaultState().with(FACING, preferred.getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java index b4f661d1f..dda1b90f4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java @@ -16,7 +16,8 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock { public RotatedPillarKineticBlock(Properties properties) { super(properties); - this.setDefaultState(this.getDefaultState().with(AXIS, Direction.Axis.Y)); + this.setDefaultState(this.getDefaultState() + .with(AXIS, Direction.Axis.Y)); } @Override @@ -40,10 +41,12 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock { public static Axis getPreferredAxis(BlockItemUseContext context) { Axis prefferedAxis = null; for (Direction side : Direction.values()) { - BlockState blockState = context.getWorld().getBlockState(context.getPos().offset(side)); + BlockState blockState = context.getWorld() + .getBlockState(context.getPos() + .offset(side)); if (blockState.getBlock() instanceof IRotate) { - if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos().offset(side), - blockState, side.getOpposite())) + if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos() + .offset(side), blockState, side.getOpposite())) if (prefferedAxis != null && prefferedAxis != side.getAxis()) { prefferedAxis = null; break; @@ -63,10 +66,15 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock { @Override public BlockState getStateForPlacement(BlockItemUseContext context) { Axis preferredAxis = getPreferredAxis(context); - if (preferredAxis != null && !context.getPlayer().isSneaking()) - return this.getDefaultState().with(AXIS, preferredAxis); - return this.getDefaultState().with(AXIS, context.getPlayer().isSneaking() ? context.getFace().getAxis() - : context.getNearestLookingDirection().getAxis()); + if (preferredAxis != null && (context.getPlayer() == null || !context.getPlayer() + .isSneaking())) + return this.getDefaultState() + .with(AXIS, preferredAxis); + return this.getDefaultState() + .with(AXIS, preferredAxis != null && context.getPlayer() + .isSneaking() ? context.getFace() + .getAxis() + : context.getNearestLookingDirection() + .getAxis()); } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java index e19d27f0b..4d34fd6a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java @@ -76,8 +76,8 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT BlockState blockState = context.getWorld() .getBlockState(placedOnPos); - if ((blockState.getBlock() != this) || context.getPlayer() - .isSneaking()) { + if ((blockState.getBlock() != this) || (context.getPlayer() != null && context.getPlayer() + .isSneaking())) { BlockState stateForPlacement = super.getStateForPlacement(context); Direction direction = stateForPlacement.get(HORIZONTAL_FACING); if (direction != face) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankBlock.java index d375ccca9..da13c072d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankBlock.java @@ -33,7 +33,7 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE 0; i--) { Vec3d offset = VecHelper.rotate(plane, 360 * world.rand.nextFloat(), direction.getAxis()); - Vec3d motion = offset.normalize().scale(1 / 16f); + Vec3d motion = offset.normalize() + .scale(1 / 16f); if (fullBlock) offset = new Vec3d(MathHelper.clamp(offset.x, -.5, .5), MathHelper.clamp(offset.y, -.5, .5), - MathHelper.clamp(offset.z, -.5, .5)); + MathHelper.clamp(offset.z, -.5, .5)); Vec3d particlePos = facePos.add(offset); world.addParticle(new ItemParticleData(ParticleTypes.ITEM, stack), particlePos.x, particlePos.y, - particlePos.z, motion.x, motion.y, motion.z); + particlePos.z, motion.x, motion.y, motion.z); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelBlock.java index 83d2f16c7..e5923468e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelBlock.java @@ -34,7 +34,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE beltsToCreate = getBeltChainBetween(start, end, slope, facing); BlockState beltBlock = AllBlocks.BELT.getDefaultState(); @@ -134,8 +135,8 @@ public class BeltConnectorItem extends BlockItem { if (part == Part.MIDDLE && pulley) part = Part.PULLEY; world.setBlockState(pos, beltBlock.with(BeltBlock.SLOPE, slope) - .with(BeltBlock.PART, part) - .with(BeltBlock.HORIZONTAL_FACING, facing), 3); + .with(BeltBlock.PART, part) + .with(BeltBlock.HORIZONTAL_FACING, facing), 3); } } @@ -148,7 +149,7 @@ public class BeltConnectorItem extends BlockItem { axisDirection = diff.getY() > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE; else axisDirection = beltAxis.getCoordinate(diff.getX(), 0, diff.getZ()) > 0 ? AxisDirection.POSITIVE - : AxisDirection.NEGATIVE; + : AxisDirection.NEGATIVE; return Direction.getFacingFromAxis(axisDirection, beltAxis); } @@ -197,20 +198,20 @@ public class BeltConnectorItem extends BlockItem { BlockPos diff = second.subtract(first); Axis axis = world.getBlockState(first) - .get(BlockStateProperties.AXIS); + .get(BlockStateProperties.AXIS); int x = diff.getX(); int y = diff.getY(); int z = diff.getZ(); int sames = ((Math.abs(x) == Math.abs(y)) ? 1 : 0) + ((Math.abs(y) == Math.abs(z)) ? 1 : 0) - + ((Math.abs(z) == Math.abs(x)) ? 1 : 0); + + ((Math.abs(z) == Math.abs(x)) ? 1 : 0); if (axis.getCoordinate(x, y, z) != 0) return false; if (sames != 1) return false; if (axis != world.getBlockState(second) - .get(BlockStateProperties.AXIS)) + .get(BlockStateProperties.AXIS)) return false; TileEntity tileEntity = world.getTileEntity(first); @@ -234,7 +235,7 @@ public class BeltConnectorItem extends BlockItem { if (ShaftBlock.isShaft(blockState) && blockState.get(ShaftBlock.AXIS) == axis) continue; if (!blockState.getMaterial() - .isReplaceable()) + .isReplaceable()) return false; } @@ -248,7 +249,7 @@ public class BeltConnectorItem extends BlockItem { if (!ShaftBlock.isShaft(world.getBlockState(pos))) return false; if (world.getBlockState(pos) - .get(BlockStateProperties.AXIS) == Axis.Y) + .get(BlockStateProperties.AXIS) == Axis.Y) return false; return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedBeltBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedBeltBlock.java index e28b40615..46d0891c0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedBeltBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedBeltBlock.java @@ -29,7 +29,8 @@ import net.minecraft.world.IWorldReader; public class EncasedBeltBlock extends RotatedPillarKineticBlock { public static final IProperty PART = EnumProperty.create("part", Part.class); - public static final BooleanProperty CONNECTED_ALONG_FIRST_COORDINATE = DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; + public static final BooleanProperty CONNECTED_ALONG_FIRST_COORDINATE = + DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; public EncasedBeltBlock(Properties properties) { super(properties); @@ -40,12 +41,12 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { public boolean shouldCheckWeakPower(BlockState state, IWorldReader world, BlockPos pos, Direction side) { return false; } - + @Override public PushReaction getPushReaction(BlockState state) { return PushReaction.NORMAL; } - + @Override protected void fillStateContainer(Builder builder) { super.fillStateContainer(builder.add(PART, CONNECTED_ALONG_FIRST_COORDINATE)); @@ -53,8 +54,10 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - Axis placedAxis = context.getNearestLookingDirection().getAxis(); - Axis axis = context.getPlayer().isSneaking() ? placedAxis : getPreferredAxis(context); + Axis placedAxis = context.getNearestLookingDirection() + .getAxis(); + Axis axis = context.getPlayer() != null && context.getPlayer() + .isSneaking() ? placedAxis : getPreferredAxis(context); if (axis == null) axis = placedAxis; @@ -64,20 +67,20 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { continue; BlockPos pos = context.getPos(); BlockPos offset = pos.offset(facing); - state = updatePostPlacement(state, facing, context.getWorld().getBlockState(offset), context.getWorld(), - pos, offset); + state = updatePostPlacement(state, facing, context.getWorld() + .getBlockState(offset), context.getWorld(), pos, offset); } return state; } @Override public BlockState updatePostPlacement(BlockState stateIn, Direction face, BlockState neighbour, IWorld worldIn, - BlockPos currentPos, BlockPos facingPos) { + BlockPos currentPos, BlockPos facingPos) { Part part = stateIn.get(PART); Axis axis = stateIn.get(AXIS); boolean connectionAlongFirst = stateIn.get(CONNECTED_ALONG_FIRST_COORDINATE); - Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) - : (axis == Axis.Z ? Axis.Y : Axis.Z); + Axis connectionAxis = + connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) : (axis == Axis.Z ? Axis.Y : Axis.Z); Axis faceAxis = face.getAxis(); boolean facingAlongFirst = axis == Axis.X ? faceAxis.isVertical() : faceAxis == Axis.X; @@ -99,8 +102,8 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { Part otherPart = neighbour.get(PART); Axis otherAxis = neighbour.get(AXIS); boolean otherConnection = neighbour.get(CONNECTED_ALONG_FIRST_COORDINATE); - Axis otherConnectionAxis = otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) - : (otherAxis == Axis.Z ? Axis.Y : Axis.Z); + Axis otherConnectionAxis = + otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) : (otherAxis == Axis.Z ? Axis.Y : Axis.Z); if (neighbour.get(AXIS) == faceAxis) return stateIn; @@ -117,12 +120,14 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { if ((part == Part.START) != positive) part = Part.MIDDLE; - return stateIn.with(PART, part).with(CONNECTED_ALONG_FIRST_COORDINATE, connectionAlongFirst); + return stateIn.with(PART, part) + .with(CONNECTED_ALONG_FIRST_COORDINATE, connectionAlongFirst); } @Override public BlockState updateAfterWrenched(BlockState newState, ItemUseContext context) { - Blocks.AIR.getDefaultState().updateNeighbors(context.getWorld(), context.getPos(), 1); + Blocks.AIR.getDefaultState() + .updateNeighbors(context.getWorld(), context.getPos(), 1); Axis axis = newState.get(AXIS); newState = getDefaultState().with(AXIS, axis); for (Direction facing : Direction.values()) { @@ -130,8 +135,9 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { continue; BlockPos pos = context.getPos(); BlockPos offset = pos.offset(facing); - newState = updatePostPlacement(newState, facing, context.getWorld().getBlockState(offset), context.getWorld(), - pos, offset); } + newState = updatePostPlacement(newState, facing, context.getWorld() + .getBlockState(offset), context.getWorld(), pos, offset); + } newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2); return newState; } @@ -150,13 +156,13 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { Part part = state.get(PART); Axis axis = state.get(AXIS); boolean connectionAlongFirst = state.get(CONNECTED_ALONG_FIRST_COORDINATE); - Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) - : (axis == Axis.Z ? Axis.Y : Axis.Z); + Axis connectionAxis = + connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) : (axis == Axis.Z ? Axis.Y : Axis.Z); Axis otherAxis = other.get(AXIS); boolean otherConnection = other.get(CONNECTED_ALONG_FIRST_COORDINATE); - Axis otherConnectionAxis = otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) - : (otherAxis == Axis.Z ? Axis.Y : Axis.Z); + Axis otherConnectionAxis = + otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) : (otherAxis == Axis.Z ? Axis.Y : Axis.Z); if (otherConnectionAxis != connectionAxis) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java index 56b8ccfe2..ef275df56 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java @@ -36,11 +36,13 @@ public class EncasedShaftBlock extends RotatedPillarKineticBlock { @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - if (context.getPlayer().isSneaking()) + if (context.getPlayer() != null && context.getPlayer() + .isSneaking()) return super.getStateForPlacement(context); Axis preferredAxis = getPreferredAxis(context); - return this.getDefaultState().with(AXIS, - preferredAxis == null ? context.getNearestLookingDirection().getAxis() : preferredAxis); + return this.getDefaultState() + .with(AXIS, preferredAxis == null ? context.getNearestLookingDirection() + .getAxis() : preferredAxis); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java index 13efbdc8d..6b4bb4481 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java @@ -52,7 +52,7 @@ public interface IWrenchable { BlockPos pos = context.getPos(); PlayerEntity player = context.getPlayer(); if (world instanceof ServerWorld) { - if (!player.isCreative()) + if (player != null && !player.isCreative()) Block.getDrops(state, (ServerWorld) world, pos, world.getTileEntity(pos), player, context.getItem()) .forEach(itemStack -> { player.inventory.placeItemBackInInventory(world, itemStack); diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItem.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItem.java index e71a6d08d..839d6ec74 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItem.java @@ -6,24 +6,28 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResultType; +import javax.annotation.Nonnull; + public class WrenchItem extends Item { public WrenchItem(Properties properties) { super(properties); } + @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { PlayerEntity player = context.getPlayer(); - if (!player.isAllowEdit()) + if (player == null || !player.isAllowEdit()) return super.onItemUse(context); - - BlockState state = context.getWorld().getBlockState(context.getPos()); + + BlockState state = context.getWorld() + .getBlockState(context.getPos()); if (!(state.getBlock() instanceof IWrenchable)) return super.onItemUse(context); IWrenchable actor = (IWrenchable) state.getBlock(); - if (player.isSneaking()) + if (player.isSneaking()) return actor.onSneakWrenched(state, context); return actor.onWrenched(state, context); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java index c43b8dca9..104095a74 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java @@ -21,7 +21,8 @@ public class TreeFertilizerItem extends Item { @Override public ActionResultType onItemUse(ItemUseContext context) { - BlockState state = context.getWorld().getBlockState(context.getPos()); + BlockState state = context.getWorld() + .getBlockState(context.getPos()); Block block = state.getBlock(); if (block instanceof SaplingBlock) { @@ -34,31 +35,46 @@ public class TreeFertilizerItem extends Item { BlockPos saplingPos = context.getPos(); for (BlockPos pos : BlockPos.getAllInBoxMutable(-1, 0, -1, 1, 0, 1)) { - if (context.getWorld().getBlockState(saplingPos.add(pos)).getBlock() == block) + if (context.getWorld() + .getBlockState(saplingPos.add(pos)) + .getBlock() == block) world.setBlockState(pos.up(10), state.with(SaplingBlock.STAGE, 1)); } - ((SaplingBlock) block).grow(world, world.getRandom(), BlockPos.ZERO.up(10), state.with(SaplingBlock.STAGE, 1)); + ((SaplingBlock) block).grow(world, world.getRandom(), BlockPos.ZERO.up(10), + state.with(SaplingBlock.STAGE, 1)); for (BlockPos pos : world.blocksAdded.keySet()) { - BlockPos actualPos = pos.add(saplingPos).down(10); + BlockPos actualPos = pos.add(saplingPos) + .down(10); // Don't replace Bedrock - if (context.getWorld().getBlockState(actualPos).getBlockHardness(context.getWorld(), actualPos) == -1) + if (context.getWorld() + .getBlockState(actualPos) + .getBlockHardness(context.getWorld(), actualPos) == -1) continue; // Don't replace solid blocks with leaves - if (!world.getBlockState(pos).isNormalCube(world, pos) && !context.getWorld().getBlockState(actualPos) - .getCollisionShape(context.getWorld(), actualPos).isEmpty()) + if (!world.getBlockState(pos) + .isNormalCube(world, pos) + && !context.getWorld() + .getBlockState(actualPos) + .getCollisionShape(context.getWorld(), actualPos) + .isEmpty()) continue; - if (world.getBlockState(pos).getBlock() == Blocks.GRASS_BLOCK - || world.getBlockState(pos).getBlock() == Blocks.PODZOL) + if (world.getBlockState(pos) + .getBlock() == Blocks.GRASS_BLOCK + || world.getBlockState(pos) + .getBlock() == Blocks.PODZOL) continue; - context.getWorld().setBlockState(actualPos, world.getBlockState(pos)); + context.getWorld() + .setBlockState(actualPos, world.getBlockState(pos)); } - if (!context.getPlayer().isCreative()) - context.getItem().shrink(1); + if (context.getPlayer() != null && !context.getPlayer() + .isCreative()) + context.getItem() + .shrink(1); return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandItem.java b/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandItem.java index 40b5fb682..5ee1ba62a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandItem.java @@ -38,6 +38,8 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.PacketDistributor; +import javax.annotation.Nonnull; + public class SymmetryWandItem extends Item { public static final String SYMMETRY = "symmetry"; @@ -48,10 +50,13 @@ public class SymmetryWandItem extends Item { .rarity(Rarity.UNCOMMON)); } + @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { PlayerEntity player = context.getPlayer(); BlockPos pos = context.getPos(); + if (player == null) + return ActionResultType.PASS; player.getCooldownTracker() .setCooldown(this, 5); ItemStack wand = player.getHeldItem(context.getHand()); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java index 18328c84f..952e42022 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java @@ -41,6 +41,8 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.PacketDistributor; +import javax.annotation.Nonnull; + public abstract class ZapperItem extends Item { public ZapperItem(Properties properties) { @@ -80,10 +82,11 @@ public abstract class ZapperItem extends Item { return newStack.getItem() instanceof ZapperItem; } + @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { // Shift -> open GUI - if (context.getPlayer() + if (context.getPlayer() != null && context.getPlayer() .isSneaking()) { if (context.getWorld().isRemote) { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { @@ -218,7 +221,7 @@ public abstract class ZapperItem extends Item { public boolean onEntitySwing(ItemStack stack, LivingEntity entity) { return true; } - + @Override public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) { return false; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/CrateBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/CrateBlock.java index 0bc4a69c4..12ff27a6e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/CrateBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/CrateBlock.java @@ -23,7 +23,8 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable { public CrateBlock(Properties p_i48415_1_) { super(p_i48415_1_); - setDefaultState(getDefaultState().with(FACING, Direction.UP).with(DOUBLE, false)); + setDefaultState(getDefaultState().with(FACING, Direction.UP) + .with(DOUBLE, false)); } @Override @@ -33,17 +34,18 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable { @Override public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, - BlockPos currentPos, BlockPos facingPos) { + BlockPos currentPos, BlockPos facingPos) { boolean isDouble = stateIn.get(DOUBLE); Direction blockFacing = stateIn.get(FACING); boolean isFacingOther = facingState.getBlock() == this && facingState.get(DOUBLE) - && facingState.get(FACING) == facing.getOpposite(); + && facingState.get(FACING) == facing.getOpposite(); if (!isDouble) { if (!isFacingOther) return stateIn; - return stateIn.with(DOUBLE, true).with(FACING, facing); + return stateIn.with(DOUBLE, true) + .with(FACING, facing); } if (facing != blockFacing) @@ -59,18 +61,22 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable { BlockPos pos = context.getPos(); World world = context.getWorld(); - if (!context.getPlayer().isSneaking()) { + if (context.getPlayer() == null || !context.getPlayer() + .isSneaking()) { for (Direction d : Direction.values()) { BlockState state = world.getBlockState(pos.offset(d)); if (state.getBlock() == this && !state.get(DOUBLE)) - return getDefaultState().with(FACING, d).with(DOUBLE, true); + return getDefaultState().with(FACING, d) + .with(DOUBLE, true); } } - Direction placedOnFace = context.getFace().getOpposite(); + Direction placedOnFace = context.getFace() + .getOpposite(); BlockState state = world.getBlockState(pos.offset(placedOnFace)); if (state.getBlock() == this && !state.get(DOUBLE)) - return getDefaultState().with(FACING, placedOnFace).with(DOUBLE, true); + return getDefaultState().with(FACING, placedOnFace) + .with(DOUBLE, true); return getDefaultState(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java index f24c11904..72ea19d51 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java @@ -28,7 +28,8 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor public RedstoneContactBlock(Properties properties) { super(properties); - setDefaultState(getDefaultState().with(POWERED, false).with(FACING, Direction.UP)); + setDefaultState(getDefaultState().with(POWERED, false) + .with(FACING, Direction.UP)); } @Override @@ -39,10 +40,13 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - BlockState state = getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite()); - Direction placeDirection = context.getFace().getOpposite(); + BlockState state = getDefaultState().with(FACING, context.getNearestLookingDirection() + .getOpposite()); + Direction placeDirection = context.getFace() + .getOpposite(); - if (context.getPlayer().isSneaking() || hasValidContact(context.getWorld(), context.getPos(), placeDirection)) + if ((context.getPlayer() != null && context.getPlayer() + .isSneaking()) || hasValidContact(context.getWorld(), context.getPos(), placeDirection)) state = state.with(FACING, placeDirection); if (hasValidContact(context.getWorld(), context.getPos(), state.get(FACING))) state = state.with(POWERED, true); @@ -52,7 +56,7 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor @Override public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, - BlockPos currentPos, BlockPos facingPos) { + BlockPos currentPos, BlockPos facingPos) { if (facing != stateIn.get(FACING)) return stateIn; boolean hasValidContact = hasValidContact(worldIn, currentPos, facing); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java index 039109ff7..feb43b008 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java @@ -36,6 +36,8 @@ import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; +import javax.annotation.Nonnull; + public class FilterItem extends Item implements INamedContainerProvider { private FilterType type; @@ -43,22 +45,25 @@ public class FilterItem extends Item implements INamedContainerProvider { private enum FilterType { REGULAR, ATTRIBUTE; } - + public static FilterItem regular(Properties properties) { return new FilterItem(FilterType.REGULAR, properties); } - + public static FilterItem attribute(Properties properties) { return new FilterItem(FilterType.ATTRIBUTE, properties); } - + private FilterItem(FilterType type, Properties properties) { super(properties); this.type = type; } + @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { + if (context.getPlayer() == null) + return ActionResultType.PASS; return onItemRightClick(context.getWorld(), context.getPlayer(), context.getHand()).getType(); } @@ -73,16 +78,17 @@ public class FilterItem extends Item implements INamedContainerProvider { ItemDescription.add(tooltip, makeSummary); } } - + private List makeSummary(ItemStack filter) { List list = new ArrayList<>(); if (type == FilterType.REGULAR) { ItemStackHandler filterItems = getFilterItems(filter); - boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist"); + boolean blacklist = filter.getOrCreateTag() + .getBoolean("Blacklist"); list.add(TextFormatting.GOLD - + (blacklist ? Lang.translate("gui.filter.blacklist") : Lang.translate("gui.filter.whitelist"))); + + (blacklist ? Lang.translate("gui.filter.blacklist") : Lang.translate("gui.filter.whitelist"))); int count = 0; for (int i = 0; i < filterItems.getSlots(); i++) { if (count > 3) { @@ -93,7 +99,8 @@ public class FilterItem extends Item implements INamedContainerProvider { ItemStack filterStack = filterItems.getStackInSlot(i); if (filterStack.isEmpty()) continue; - list.add(TextFormatting.GRAY + "- " + filterStack.getDisplayName().getFormattedText()); + list.add(TextFormatting.GRAY + "- " + filterStack.getDisplayName() + .getFormattedText()); count++; } @@ -102,15 +109,17 @@ public class FilterItem extends Item implements INamedContainerProvider { } if (type == FilterType.ATTRIBUTE) { - WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag().getInt("WhitelistMode")]; + WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag() + .getInt("WhitelistMode")]; list.add(TextFormatting.GOLD + (whitelistMode == WhitelistMode.WHITELIST_CONJ - ? Lang.translate("gui.attribute_filter.whitelist_conjunctive") - : whitelistMode == WhitelistMode.WHITELIST_DISJ - ? Lang.translate("gui.attribute_filter.whitelist_disjunctive") - : Lang.translate("gui.attribute_filter.blacklist"))); + ? Lang.translate("gui.attribute_filter.whitelist_conjunctive") + : whitelistMode == WhitelistMode.WHITELIST_DISJ + ? Lang.translate("gui.attribute_filter.whitelist_disjunctive") + : Lang.translate("gui.attribute_filter.blacklist"))); int count = 0; - ListNBT attributes = filter.getOrCreateTag().getList("MatchedAttributes", NBT.TAG_COMPOUND); + ListNBT attributes = filter.getOrCreateTag() + .getList("MatchedAttributes", NBT.TAG_COMPOUND); for (INBT inbt : attributes) { ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt); if (count > 3) { @@ -174,15 +183,17 @@ public class FilterItem extends Item implements INamedContainerProvider { private static boolean test(World world, ItemStack stack, ItemStack filter, boolean matchNBT) { if (filter.isEmpty()) return true; - + if (!(filter.getItem() instanceof FilterItem)) return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack) - : ItemStack.areItemsEqual(filter, stack)); + : ItemStack.areItemsEqual(filter, stack)); if (AllItems.FILTER.get() == filter.getItem()) { ItemStackHandler filterItems = getFilterItems(filter); - boolean respectNBT = filter.getOrCreateTag().getBoolean("RespectNBT"); - boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist"); + boolean respectNBT = filter.getOrCreateTag() + .getBoolean("RespectNBT"); + boolean blacklist = filter.getOrCreateTag() + .getBoolean("Blacklist"); for (int slot = 0; slot < filterItems.getSlots(); slot++) { ItemStack stackInSlot = filterItems.getStackInSlot(slot); if (stackInSlot.isEmpty()) @@ -195,8 +206,10 @@ public class FilterItem extends Item implements INamedContainerProvider { } if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) { - WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag().getInt("WhitelistMode")]; - ListNBT attributes = filter.getOrCreateTag().getList("MatchedAttributes", NBT.TAG_COMPOUND); + WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag() + .getInt("WhitelistMode")]; + ListNBT attributes = filter.getOrCreateTag() + .getList("MatchedAttributes", NBT.TAG_COMPOUND); for (INBT inbt : attributes) { ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt); boolean matches = attribute.appliesTo(stack, world); diff --git a/src/main/java/com/simibubi/create/content/schematics/item/SchematicItem.java b/src/main/java/com/simibubi/create/content/schematics/item/SchematicItem.java index fe8a15868..521d74a2e 100644 --- a/src/main/java/com/simibubi/create/content/schematics/item/SchematicItem.java +++ b/src/main/java/com/simibubi/create/content/schematics/item/SchematicItem.java @@ -41,6 +41,8 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.thread.SidedThreadGroups; +import javax.annotation.Nonnull; + public class SchematicItem extends Item { public SchematicItem(Properties properties) { @@ -70,8 +72,10 @@ public class SchematicItem extends Item { @OnlyIn(value = Dist.CLIENT) public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flagIn) { if (stack.hasTag()) { - if (stack.getTag().contains("File")) - tooltip.add(new StringTextComponent(TextFormatting.GOLD + stack.getTag().getString("File"))); + if (stack.getTag() + .contains("File")) + tooltip.add(new StringTextComponent(TextFormatting.GOLD + stack.getTag() + .getString("File"))); } else { tooltip.add(new StringTextComponent(TextFormatting.RED + Lang.translate("schematic.invalid"))); } @@ -95,12 +99,15 @@ public class SchematicItem extends Item { public static Template loadSchematic(ItemStack blueprint) { Template t = new Template(); - String owner = blueprint.getTag().getString("Owner"); - String schematic = blueprint.getTag().getString("File"); + String owner = blueprint.getTag() + .getString("Owner"); + String schematic = blueprint.getTag() + .getString("File"); String filepath = ""; - if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER) + if (Thread.currentThread() + .getThreadGroup() == SidedThreadGroups.SERVER) filepath = "schematics/uploaded/" + owner + "/" + schematic; else filepath = "schematics/" + schematic; @@ -121,9 +128,10 @@ public class SchematicItem extends Item { return t; } + @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { - if (!onItemUse(context.getPlayer(), context.getHand())) + if (context.getPlayer() != null && !onItemUse(context.getPlayer(), context.getHand())) return super.onItemUse(context); return ActionResultType.SUCCESS; } @@ -138,7 +146,8 @@ public class SchematicItem extends Item { private boolean onItemUse(PlayerEntity player, Hand hand) { if (!player.isSneaking() || hand != Hand.MAIN_HAND) return false; - if (!player.getHeldItem(hand).hasTag()) + if (!player.getHeldItem(hand) + .hasTag()) return false; DistExecutor.runWhenOn(Dist.CLIENT, () -> this::displayBlueprintScreen); return true;