Merge branch 'non_player_kinetic_placement_fix' into mc1.15/dev

This commit is contained in:
LordGrimmauld 2020-07-04 14:29:38 +02:00
commit 8ddf3fabba
24 changed files with 294 additions and 180 deletions

View File

@ -27,14 +27,17 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
} }
protected Direction getFacingForPlacement(BlockItemUseContext context) { protected Direction getFacingForPlacement(BlockItemUseContext context) {
Direction facing = context.getNearestLookingDirection().getOpposite(); Direction facing = context.getNearestLookingDirection()
if (context.getPlayer().isSneaking()) .getOpposite();
if (context.getPlayer() != null && context.getPlayer()
.isSneaking())
facing = facing.getOpposite(); facing = facing.getOpposite();
return facing; return facing;
} }
protected boolean getAxisAlignmentForPlacement(BlockItemUseContext context) { protected boolean getAxisAlignmentForPlacement(BlockItemUseContext context) {
return context.getPlacementHorizontalFacing().getAxis() == Axis.X; return context.getPlacementHorizontalFacing()
.getAxis() == Axis.X;
} }
@Override @Override
@ -44,30 +47,37 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
World world = context.getWorld(); World world = context.getWorld();
boolean alongFirst = false; boolean alongFirst = false;
if (facing.getAxis().isHorizontal()) { if (facing.getAxis()
.isHorizontal()) {
alongFirst = facing.getAxis() == Axis.Z; 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, boolean shaftAbove = blockAbove instanceof IRotate && ((IRotate) blockAbove).hasShaftTowards(world,
pos.up(), world.getBlockState(pos.up()), Direction.DOWN); pos.up(), world.getBlockState(pos.up()), Direction.DOWN);
Block blockBelow = world.getBlockState(pos.offset(Direction.DOWN)).getBlock(); Block blockBelow = world.getBlockState(pos.offset(Direction.DOWN))
.getBlock();
boolean shaftBelow = blockBelow instanceof IRotate && ((IRotate) blockBelow).hasShaftTowards(world, 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) if (shaftAbove || shaftBelow)
alongFirst = facing.getAxis() == Axis.X; alongFirst = facing.getAxis() == Axis.X;
} }
if (facing.getAxis().isVertical()) { if (facing.getAxis()
.isVertical()) {
alongFirst = getAxisAlignmentForPlacement(context); alongFirst = getAxisAlignmentForPlacement(context);
Direction prefferedSide = null; Direction prefferedSide = null;
for (Direction side : Direction.values()) { for (Direction side : Direction.values()) {
if (side.getAxis().isVertical()) if (side.getAxis()
.isVertical())
continue; 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 (blockState.getBlock() instanceof IRotate) {
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos()
context.getPos().offset(side), blockState, side.getOpposite())) .offset(side), blockState, side.getOpposite()))
if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) { if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
prefferedSide = null; prefferedSide = null;
break; 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 @Override
public Axis getRotationAxis(BlockState state) { 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); boolean alongFirst = state.get(AXIS_ALONG_FIRST_COORDINATE);
if (pistonAxis == Axis.X) if (pistonAxis == Axis.X)

View File

@ -27,10 +27,12 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
public Direction getPreferredFacing(BlockItemUseContext context) { public Direction getPreferredFacing(BlockItemUseContext context) {
Direction prefferedSide = null; Direction prefferedSide = null;
for (Direction side : Direction.values()) { 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 (blockState.getBlock() instanceof IRotate) {
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos().offset(side), if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos()
blockState, side.getOpposite())) .offset(side), blockState, side.getOpposite()))
if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) { if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
prefferedSide = null; prefferedSide = null;
break; break;
@ -45,10 +47,11 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context); Direction preferred = getPreferredFacing(context);
if (preferred == null || context.getPlayer().isSneaking()) { if (preferred == null || (context.getPlayer() != null && context.getPlayer()
.isSneaking())) {
Direction nearestLookingDirection = context.getNearestLookingDirection(); Direction nearestLookingDirection = context.getNearestLookingDirection();
return getDefaultState().with(FACING, return getDefaultState().with(FACING, context.getPlayer() != null && context.getPlayer()
context.getPlayer().isSneaking() ? nearestLookingDirection : nearestLookingDirection.getOpposite()); .isSneaking() ? nearestLookingDirection : nearestLookingDirection.getOpposite());
} }
return getDefaultState().with(FACING, preferred.getOpposite()); return getDefaultState().with(FACING, preferred.getOpposite());
} }

View File

@ -16,7 +16,8 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
public RotatedPillarKineticBlock(Properties properties) { public RotatedPillarKineticBlock(Properties properties) {
super(properties); super(properties);
this.setDefaultState(this.getDefaultState().with(AXIS, Direction.Axis.Y)); this.setDefaultState(this.getDefaultState()
.with(AXIS, Direction.Axis.Y));
} }
@Override @Override
@ -40,10 +41,12 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
public static Axis getPreferredAxis(BlockItemUseContext context) { public static Axis getPreferredAxis(BlockItemUseContext context) {
Axis prefferedAxis = null; Axis prefferedAxis = null;
for (Direction side : Direction.values()) { 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 (blockState.getBlock() instanceof IRotate) {
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos().offset(side), if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos()
blockState, side.getOpposite())) .offset(side), blockState, side.getOpposite()))
if (prefferedAxis != null && prefferedAxis != side.getAxis()) { if (prefferedAxis != null && prefferedAxis != side.getAxis()) {
prefferedAxis = null; prefferedAxis = null;
break; break;
@ -63,10 +66,15 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Axis preferredAxis = getPreferredAxis(context); Axis preferredAxis = getPreferredAxis(context);
if (preferredAxis != null && !context.getPlayer().isSneaking()) if (preferredAxis != null && (context.getPlayer() == null || !context.getPlayer()
return this.getDefaultState().with(AXIS, preferredAxis); .isSneaking()))
return this.getDefaultState().with(AXIS, context.getPlayer().isSneaking() ? context.getFace().getAxis() return this.getDefaultState()
: context.getNearestLookingDirection().getAxis()); .with(AXIS, preferredAxis);
return this.getDefaultState()
.with(AXIS, preferredAxis != null && context.getPlayer()
.isSneaking() ? context.getFace()
.getAxis()
: context.getNearestLookingDirection()
.getAxis());
} }
} }

View File

@ -76,8 +76,8 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
BlockState blockState = context.getWorld() BlockState blockState = context.getWorld()
.getBlockState(placedOnPos); .getBlockState(placedOnPos);
if ((blockState.getBlock() != this) || context.getPlayer() if ((blockState.getBlock() != this) || (context.getPlayer() != null && context.getPlayer()
.isSneaking()) { .isSneaking())) {
BlockState stateForPlacement = super.getStateForPlacement(context); BlockState stateForPlacement = super.getStateForPlacement(context);
Direction direction = stateForPlacement.get(HORIZONTAL_FACING); Direction direction = stateForPlacement.get(HORIZONTAL_FACING);
if (direction != face) if (direction != face)

View File

@ -33,7 +33,7 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandC
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return AllShapes.CRANK.get(state.get(FACING)); return AllShapes.CRANK.get(state.get(FACING));
} }
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED; return BlockRenderType.ENTITYBLOCK_ANIMATED;
@ -41,8 +41,9 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandC
@Override @Override
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) { BlockRayTraceResult hit) {
boolean handEmpty = player.getHeldItem(handIn).isEmpty(); boolean handEmpty = player.getHeldItem(handIn)
.isEmpty();
if (!handEmpty && player.isSneaking()) if (!handEmpty && player.isSneaking())
return ActionResultType.PASS; return ActionResultType.PASS;
@ -54,22 +55,25 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandC
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context); Direction preferred = getPreferredFacing(context);
if (preferred == null || context.getPlayer().isSneaking()) if (preferred == null || (context.getPlayer() != null && context.getPlayer()
.isSneaking()))
return getDefaultState().with(FACING, context.getFace()); return getDefaultState().with(FACING, context.getFace());
return getDefaultState().with(FACING, preferred.getOpposite()); return getDefaultState().with(FACING, preferred.getOpposite());
} }
@Override @Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) { public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
Direction facing = state.get(FACING).getOpposite(); Direction facing = state.get(FACING)
.getOpposite();
BlockPos neighbourPos = pos.offset(facing); BlockPos neighbourPos = pos.offset(facing);
BlockState neighbour = worldIn.getBlockState(neighbourPos); BlockState neighbour = worldIn.getBlockState(neighbourPos);
return !neighbour.getCollisionShape(worldIn, neighbourPos).isEmpty(); return !neighbour.getCollisionShape(worldIn, neighbourPos)
.isEmpty();
} }
@Override @Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) { boolean isMoving) {
if (worldIn.isRemote) if (worldIn.isRemote)
return; return;
@ -89,12 +93,14 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandC
@Override @Override
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) { public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
return face == state.get(FACING).getOpposite(); return face == state.get(FACING)
.getOpposite();
} }
@Override @Override
public Axis getRotationAxis(BlockState state) { public Axis getRotationAxis(BlockState state) {
return state.get(FACING).getAxis(); return state.get(FACING)
.getAxis();
} }
@Override @Override

View File

@ -65,7 +65,7 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements ITE<Enca
Direction preferredFacing = getPreferredFacing(context); Direction preferredFacing = getPreferredFacing(context);
if (preferredFacing == null) if (preferredFacing == null)
preferredFacing = context.getNearestLookingDirection(); preferredFacing = context.getNearestLookingDirection();
return getDefaultState().with(FACING, context.getPlayer() return getDefaultState().with(FACING, context.getPlayer() != null && context.getPlayer()
.isSneaking() ? preferredFacing : preferredFacing.getOpposite()); .isSneaking() ? preferredFacing : preferredFacing.getOpposite());
} }

View File

@ -34,7 +34,8 @@ public class CreativeMotorBlock extends DirectionalKineticBlock {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context); Direction preferred = getPreferredFacing(context);
if (context.getPlayer().isSneaking() || preferred == null) if ((context.getPlayer() != null && context.getPlayer()
.isSneaking()) || preferred == null)
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
return getDefaultState().with(FACING, preferred); return getDefaultState().with(FACING, preferred);
} }
@ -48,7 +49,8 @@ public class CreativeMotorBlock extends DirectionalKineticBlock {
@Override @Override
public Axis getRotationAxis(BlockState state) { public Axis getRotationAxis(BlockState state) {
return state.get(FACING).getAxis(); return state.get(FACING)
.getAxis();
} }
@Override @Override

View File

@ -40,13 +40,14 @@ public class LinearChassisBlock extends AbstractChassisBlock {
.getOpposite()); .getOpposite());
BlockState blockState = context.getWorld() BlockState blockState = context.getWorld()
.getBlockState(placedOnPos); .getBlockState(placedOnPos);
if (isChassis(blockState) && !context.getPlayer()
.isSneaking()) if (context.getPlayer() == null || !context.getPlayer()
return getDefaultState().with(AXIS, blockState.get(AXIS)); .isSneaking()) {
if (!context.getPlayer() if (isChassis(blockState))
.isSneaking()) return getDefaultState().with(AXIS, blockState.get(AXIS));
return getDefaultState().with(AXIS, context.getNearestLookingDirection() return getDefaultState().with(AXIS, context.getNearestLookingDirection()
.getAxis()); .getAxis());
}
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
} }

View File

@ -49,7 +49,7 @@ public class SuperGlueItem extends Item {
PlayerEntity playerentity = context.getPlayer(); PlayerEntity playerentity = context.getPlayer();
ItemStack itemstack = context.getItem(); ItemStack itemstack = context.getItem();
if (playerentity != null && !this.canPlace(playerentity, direction, itemstack, blockpos1)) if (playerentity == null || !this.canPlace(playerentity, direction, itemstack, blockpos1))
return ActionResultType.FAIL; return ActionResultType.FAIL;
World world = context.getWorld(); World world = context.getWorld();
@ -82,7 +82,8 @@ public class SuperGlueItem extends Item {
public static void spawnParticles(World world, BlockPos pos, Direction direction, boolean fullBlock) { public static void spawnParticles(World world, BlockPos pos, Direction direction, boolean fullBlock) {
Vec3d vec = new Vec3d(direction.getDirectionVec()); Vec3d vec = new Vec3d(direction.getDirectionVec());
Vec3d plane = VecHelper.planeByNormal(vec); Vec3d plane = VecHelper.planeByNormal(vec);
Vec3d facePos = VecHelper.getCenterOf(pos).add(vec.scale(.5f)); Vec3d facePos = VecHelper.getCenterOf(pos)
.add(vec.scale(.5f));
float distance = fullBlock ? 1f : .25f + .25f * (world.rand.nextFloat() - .5f); float distance = fullBlock ? 1f : .25f + .25f * (world.rand.nextFloat() - .5f);
plane = plane.scale(distance); plane = plane.scale(distance);
@ -90,13 +91,14 @@ public class SuperGlueItem extends Item {
for (int i = fullBlock ? 40 : 15; i > 0; i--) { for (int i = fullBlock ? 40 : 15; i > 0; i--) {
Vec3d offset = VecHelper.rotate(plane, 360 * world.rand.nextFloat(), direction.getAxis()); 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) if (fullBlock)
offset = new Vec3d(MathHelper.clamp(offset.x, -.5, .5), MathHelper.clamp(offset.y, -.5, .5), 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); Vec3d particlePos = facePos.add(offset);
world.addParticle(new ItemParticleData(ParticleTypes.ITEM, stack), particlePos.x, particlePos.y, 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);
} }
} }

View File

@ -34,7 +34,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return AllTileEntities.WATER_WHEEL.create(); return AllTileEntities.WATER_WHEEL.create();
} }
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED; return BlockRenderType.ENTITYBLOCK_ANIMATED;
@ -47,8 +47,11 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
BlockState neighbourState = worldIn.getBlockState(neighbourPos); BlockState neighbourState = worldIn.getBlockState(neighbourPos);
if (!AllBlocks.WATER_WHEEL.has(neighbourState)) if (!AllBlocks.WATER_WHEEL.has(neighbourState))
continue; continue;
if (neighbourState.get(HORIZONTAL_FACING).getAxis() != state.get(HORIZONTAL_FACING).getAxis() if (neighbourState.get(HORIZONTAL_FACING)
|| state.get(HORIZONTAL_FACING).getAxis() != direction.getAxis()) .getAxis() != state.get(HORIZONTAL_FACING)
.getAxis()
|| state.get(HORIZONTAL_FACING)
.getAxis() != direction.getAxis())
return false; return false;
} }
@ -57,7 +60,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn,
BlockPos currentPos, BlockPos facingPos) { BlockPos currentPos, BlockPos facingPos) {
World world = worldIn.getWorld(); World world = worldIn.getWorld();
if (world == null || worldIn instanceof WrappedWorld) if (world == null || worldIn instanceof WrappedWorld)
return stateIn; return stateIn;
@ -78,7 +81,8 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
} }
private void updateFlowAt(BlockState state, World world, BlockPos pos, Direction f) { private void updateFlowAt(BlockState state, World world, BlockPos pos, Direction f) {
if (f.getAxis() == state.get(HORIZONTAL_FACING).getAxis()) if (f.getAxis() == state.get(HORIZONTAL_FACING)
.getAxis())
return; return;
IFluidState fluid = world.getFluidState(pos.offset(f)); IFluidState fluid = world.getFluidState(pos.offset(f));
@ -87,7 +91,8 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
int clockwiseMultiplier = 2; int clockwiseMultiplier = 2;
Vec3d vec = fluid.getFlow(world, pos.offset(f)); Vec3d vec = fluid.getFlow(world, pos.offset(f));
vec = vec.scale(f.getAxisDirection().getOffset()); vec = vec.scale(f.getAxisDirection()
.getOffset());
vec = new Vec3d(Math.signum(vec.x), Math.signum(vec.y), Math.signum(vec.z)); vec = new Vec3d(Math.signum(vec.x), Math.signum(vec.y), Math.signum(vec.z));
Vec3d flow = vec; Vec3d flow = vec;
@ -125,23 +130,28 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction facing = context.getFace(); Direction facing = context.getFace();
BlockState placedOn = context.getWorld().getBlockState(context.getPos().offset(facing.getOpposite())); BlockState placedOn = context.getWorld()
.getBlockState(context.getPos()
.offset(facing.getOpposite()));
if (AllBlocks.WATER_WHEEL.has(placedOn)) if (AllBlocks.WATER_WHEEL.has(placedOn))
return getDefaultState().with(HORIZONTAL_FACING, placedOn.get(HORIZONTAL_FACING)); return getDefaultState().with(HORIZONTAL_FACING, placedOn.get(HORIZONTAL_FACING));
if (facing.getAxis().isHorizontal()) if (facing.getAxis()
return getDefaultState().with(HORIZONTAL_FACING, .isHorizontal())
context.getPlayer().isSneaking() ? facing.getOpposite() : facing); return getDefaultState().with(HORIZONTAL_FACING, context.getPlayer() != null && context.getPlayer()
.isSneaking() ? facing.getOpposite() : facing);
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
} }
@Override @Override
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) { public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
return state.get(HORIZONTAL_FACING).getAxis() == face.getAxis(); return state.get(HORIZONTAL_FACING)
.getAxis() == face.getAxis();
} }
@Override @Override
public Axis getRotationAxis(BlockState state) { public Axis getRotationAxis(BlockState state) {
return state.get(HORIZONTAL_FACING).getAxis(); return state.get(HORIZONTAL_FACING)
.getAxis();
} }
@Override @Override

View File

@ -102,8 +102,8 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Axis preferredAxis = RotatedPillarKineticBlock.getPreferredAxis(context); Axis preferredAxis = RotatedPillarKineticBlock.getPreferredAxis(context);
if (preferredAxis != null && !context.getPlayer() if (preferredAxis != null && (context.getPlayer() == null || !context.getPlayer()
.isSneaking()) .isSneaking()))
return withAxis(preferredAxis, context); return withAxis(preferredAxis, context);
return withAxis(context.getNearestLookingDirection() return withAxis(context.getNearestLookingDirection()
.getAxis(), context); .getAxis(), context);

View File

@ -291,7 +291,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
if (world.isRemote) if (world.isRemote)
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
world.setBlockState(context.getPos(), state.with(CASING, false), 3); world.setBlockState(context.getPos(), state.with(CASING, false), 3);
if (!player.isCreative()) if (player != null && !player.isCreative())
player.inventory.placeItemBackInInventory(world, AllBlocks.BRASS_CASING.asStack()); player.inventory.placeItemBackInInventory(world, AllBlocks.BRASS_CASING.asStack());
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@ -305,7 +305,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
belt.detachKinetics(); belt.detachKinetics();
belt.attachKinetics(); belt.attachKinetics();
} }
if (!player.isCreative()) if (player != null && !player.isCreative())
player.inventory.placeItemBackInInventory(world, AllBlocks.SHAFT.asStack()); player.inventory.placeItemBackInInventory(world, AllBlocks.SHAFT.asStack());
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }

View File

@ -14,6 +14,7 @@ import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -30,6 +31,8 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class BeltConnectorItem extends BlockItem { public class BeltConnectorItem extends BlockItem {
public BeltConnectorItem(Properties properties) { public BeltConnectorItem(Properties properties) {
@ -48,12 +51,13 @@ public class BeltConnectorItem extends BlockItem {
super.fillItemGroup(p_150895_1_, p_150895_2_); super.fillItemGroup(p_150895_1_, p_150895_2_);
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
if (context.getPlayer() PlayerEntity playerEntity = context.getPlayer();
.isSneaking()) { if (playerEntity != null && playerEntity.isSneaking()) {
context.getItem() context.getItem()
.setTag(null); .setTag(null);
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@ -65,7 +69,7 @@ public class BeltConnectorItem extends BlockItem {
return validAxis ? ActionResultType.SUCCESS : ActionResultType.FAIL; return validAxis ? ActionResultType.SUCCESS : ActionResultType.FAIL;
CompoundNBT tag = context.getItem() CompoundNBT tag = context.getItem()
.getOrCreateTag(); .getOrCreateTag();
BlockPos firstPulley = null; BlockPos firstPulley = null;
// Remove first if no longer existant or valid // Remove first if no longer existant or valid
@ -74,11 +78,11 @@ public class BeltConnectorItem extends BlockItem {
if (!validateAxis(world, firstPulley)) { if (!validateAxis(world, firstPulley)) {
tag.remove("FirstPulley"); tag.remove("FirstPulley");
context.getItem() context.getItem()
.setTag(tag); .setTag(tag);
} }
} }
if (!validAxis) if (!validAxis || playerEntity == null)
return ActionResultType.FAIL; return ActionResultType.FAIL;
if (tag.contains("FirstPulley")) { if (tag.contains("FirstPulley")) {
@ -86,32 +90,29 @@ public class BeltConnectorItem extends BlockItem {
if (!canConnect(world, firstPulley, pos)) if (!canConnect(world, firstPulley, pos))
return ActionResultType.FAIL; return ActionResultType.FAIL;
if (firstPulley != null && !firstPulley.equals(pos) && !world.isRemote) { if (firstPulley != null && !firstPulley.equals(pos)) {
createBelts(world, firstPulley, pos); createBelts(world, firstPulley, pos);
AllTriggers.triggerFor(AllTriggers.CONNECT_BELT, context.getPlayer()); AllTriggers.triggerFor(AllTriggers.CONNECT_BELT, playerEntity);
if (!context.getPlayer() if (!playerEntity.isCreative())
.isCreative())
context.getItem() context.getItem()
.shrink(1); .shrink(1);
} }
if (!context.getItem() if (!context.getItem()
.isEmpty()) { .isEmpty()) {
context.getItem() context.getItem()
.setTag(null); .setTag(null);
context.getPlayer() playerEntity.getCooldownTracker()
.getCooldownTracker() .setCooldown(this, 5);
.setCooldown(this, 5);
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
tag.put("FirstPulley", NBTUtil.writeBlockPos(pos)); tag.put("FirstPulley", NBTUtil.writeBlockPos(pos));
context.getItem() context.getItem()
.setTag(tag); .setTag(tag);
context.getPlayer() playerEntity.getCooldownTracker()
.getCooldownTracker() .setCooldown(this, 5);
.setCooldown(this, 5);
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@ -123,7 +124,7 @@ public class BeltConnectorItem extends BlockItem {
BlockPos diff = end.subtract(start); BlockPos diff = end.subtract(start);
if (diff.getX() == diff.getZ()) if (diff.getX() == diff.getZ())
facing = Direction.getFacingFromAxis(facing.getAxisDirection(), world.getBlockState(start) facing = Direction.getFacingFromAxis(facing.getAxisDirection(), world.getBlockState(start)
.get(BlockStateProperties.AXIS) == Axis.X ? Axis.Z : Axis.X); .get(BlockStateProperties.AXIS) == Axis.X ? Axis.Z : Axis.X);
List<BlockPos> beltsToCreate = getBeltChainBetween(start, end, slope, facing); List<BlockPos> beltsToCreate = getBeltChainBetween(start, end, slope, facing);
BlockState beltBlock = AllBlocks.BELT.getDefaultState(); BlockState beltBlock = AllBlocks.BELT.getDefaultState();
@ -134,8 +135,8 @@ public class BeltConnectorItem extends BlockItem {
if (part == Part.MIDDLE && pulley) if (part == Part.MIDDLE && pulley)
part = Part.PULLEY; part = Part.PULLEY;
world.setBlockState(pos, beltBlock.with(BeltBlock.SLOPE, slope) world.setBlockState(pos, beltBlock.with(BeltBlock.SLOPE, slope)
.with(BeltBlock.PART, part) .with(BeltBlock.PART, part)
.with(BeltBlock.HORIZONTAL_FACING, facing), 3); .with(BeltBlock.HORIZONTAL_FACING, facing), 3);
} }
} }
@ -148,7 +149,7 @@ public class BeltConnectorItem extends BlockItem {
axisDirection = diff.getY() > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE; axisDirection = diff.getY() > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE;
else else
axisDirection = beltAxis.getCoordinate(diff.getX(), 0, diff.getZ()) > 0 ? AxisDirection.POSITIVE axisDirection = beltAxis.getCoordinate(diff.getX(), 0, diff.getZ()) > 0 ? AxisDirection.POSITIVE
: AxisDirection.NEGATIVE; : AxisDirection.NEGATIVE;
return Direction.getFacingFromAxis(axisDirection, beltAxis); return Direction.getFacingFromAxis(axisDirection, beltAxis);
} }
@ -197,20 +198,20 @@ public class BeltConnectorItem extends BlockItem {
BlockPos diff = second.subtract(first); BlockPos diff = second.subtract(first);
Axis axis = world.getBlockState(first) Axis axis = world.getBlockState(first)
.get(BlockStateProperties.AXIS); .get(BlockStateProperties.AXIS);
int x = diff.getX(); int x = diff.getX();
int y = diff.getY(); int y = diff.getY();
int z = diff.getZ(); int z = diff.getZ();
int sames = ((Math.abs(x) == Math.abs(y)) ? 1 : 0) + ((Math.abs(y) == Math.abs(z)) ? 1 : 0) 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) if (axis.getCoordinate(x, y, z) != 0)
return false; return false;
if (sames != 1) if (sames != 1)
return false; return false;
if (axis != world.getBlockState(second) if (axis != world.getBlockState(second)
.get(BlockStateProperties.AXIS)) .get(BlockStateProperties.AXIS))
return false; return false;
TileEntity tileEntity = world.getTileEntity(first); TileEntity tileEntity = world.getTileEntity(first);
@ -234,7 +235,7 @@ public class BeltConnectorItem extends BlockItem {
if (ShaftBlock.isShaft(blockState) && blockState.get(ShaftBlock.AXIS) == axis) if (ShaftBlock.isShaft(blockState) && blockState.get(ShaftBlock.AXIS) == axis)
continue; continue;
if (!blockState.getMaterial() if (!blockState.getMaterial()
.isReplaceable()) .isReplaceable())
return false; return false;
} }
@ -248,7 +249,7 @@ public class BeltConnectorItem extends BlockItem {
if (!ShaftBlock.isShaft(world.getBlockState(pos))) if (!ShaftBlock.isShaft(world.getBlockState(pos)))
return false; return false;
if (world.getBlockState(pos) if (world.getBlockState(pos)
.get(BlockStateProperties.AXIS) == Axis.Y) .get(BlockStateProperties.AXIS) == Axis.Y)
return false; return false;
return true; return true;
} }

View File

@ -29,7 +29,8 @@ import net.minecraft.world.IWorldReader;
public class EncasedBeltBlock extends RotatedPillarKineticBlock { public class EncasedBeltBlock extends RotatedPillarKineticBlock {
public static final IProperty<Part> PART = EnumProperty.create("part", Part.class); public static final IProperty<Part> 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) { public EncasedBeltBlock(Properties properties) {
super(properties); super(properties);
@ -40,12 +41,12 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
public boolean shouldCheckWeakPower(BlockState state, IWorldReader world, BlockPos pos, Direction side) { public boolean shouldCheckWeakPower(BlockState state, IWorldReader world, BlockPos pos, Direction side) {
return false; return false;
} }
@Override @Override
public PushReaction getPushReaction(BlockState state) { public PushReaction getPushReaction(BlockState state) {
return PushReaction.NORMAL; return PushReaction.NORMAL;
} }
@Override @Override
protected void fillStateContainer(Builder<Block, BlockState> builder) { protected void fillStateContainer(Builder<Block, BlockState> builder) {
super.fillStateContainer(builder.add(PART, CONNECTED_ALONG_FIRST_COORDINATE)); super.fillStateContainer(builder.add(PART, CONNECTED_ALONG_FIRST_COORDINATE));
@ -53,8 +54,10 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
Axis placedAxis = context.getNearestLookingDirection().getAxis(); Axis placedAxis = context.getNearestLookingDirection()
Axis axis = context.getPlayer().isSneaking() ? placedAxis : getPreferredAxis(context); .getAxis();
Axis axis = context.getPlayer() != null && context.getPlayer()
.isSneaking() ? placedAxis : getPreferredAxis(context);
if (axis == null) if (axis == null)
axis = placedAxis; axis = placedAxis;
@ -64,20 +67,20 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
continue; continue;
BlockPos pos = context.getPos(); BlockPos pos = context.getPos();
BlockPos offset = pos.offset(facing); BlockPos offset = pos.offset(facing);
state = updatePostPlacement(state, facing, context.getWorld().getBlockState(offset), context.getWorld(), state = updatePostPlacement(state, facing, context.getWorld()
pos, offset); .getBlockState(offset), context.getWorld(), pos, offset);
} }
return state; return state;
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction face, BlockState neighbour, IWorld worldIn, public BlockState updatePostPlacement(BlockState stateIn, Direction face, BlockState neighbour, IWorld worldIn,
BlockPos currentPos, BlockPos facingPos) { BlockPos currentPos, BlockPos facingPos) {
Part part = stateIn.get(PART); Part part = stateIn.get(PART);
Axis axis = stateIn.get(AXIS); Axis axis = stateIn.get(AXIS);
boolean connectionAlongFirst = stateIn.get(CONNECTED_ALONG_FIRST_COORDINATE); boolean connectionAlongFirst = stateIn.get(CONNECTED_ALONG_FIRST_COORDINATE);
Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) Axis connectionAxis =
: (axis == Axis.Z ? Axis.Y : Axis.Z); connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) : (axis == Axis.Z ? Axis.Y : Axis.Z);
Axis faceAxis = face.getAxis(); Axis faceAxis = face.getAxis();
boolean facingAlongFirst = axis == Axis.X ? faceAxis.isVertical() : faceAxis == Axis.X; boolean facingAlongFirst = axis == Axis.X ? faceAxis.isVertical() : faceAxis == Axis.X;
@ -99,8 +102,8 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
Part otherPart = neighbour.get(PART); Part otherPart = neighbour.get(PART);
Axis otherAxis = neighbour.get(AXIS); Axis otherAxis = neighbour.get(AXIS);
boolean otherConnection = neighbour.get(CONNECTED_ALONG_FIRST_COORDINATE); boolean otherConnection = neighbour.get(CONNECTED_ALONG_FIRST_COORDINATE);
Axis otherConnectionAxis = otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) Axis otherConnectionAxis =
: (otherAxis == Axis.Z ? Axis.Y : Axis.Z); otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) : (otherAxis == Axis.Z ? Axis.Y : Axis.Z);
if (neighbour.get(AXIS) == faceAxis) if (neighbour.get(AXIS) == faceAxis)
return stateIn; return stateIn;
@ -117,12 +120,14 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
if ((part == Part.START) != positive) if ((part == Part.START) != positive)
part = Part.MIDDLE; 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 @Override
public BlockState updateAfterWrenched(BlockState newState, ItemUseContext context) { 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); Axis axis = newState.get(AXIS);
newState = getDefaultState().with(AXIS, axis); newState = getDefaultState().with(AXIS, axis);
for (Direction facing : Direction.values()) { for (Direction facing : Direction.values()) {
@ -130,8 +135,9 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
continue; continue;
BlockPos pos = context.getPos(); BlockPos pos = context.getPos();
BlockPos offset = pos.offset(facing); BlockPos offset = pos.offset(facing);
newState = updatePostPlacement(newState, facing, context.getWorld().getBlockState(offset), context.getWorld(), newState = updatePostPlacement(newState, facing, context.getWorld()
pos, offset); } .getBlockState(offset), context.getWorld(), pos, offset);
}
newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2); newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2);
return newState; return newState;
} }
@ -150,13 +156,13 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
Part part = state.get(PART); Part part = state.get(PART);
Axis axis = state.get(AXIS); Axis axis = state.get(AXIS);
boolean connectionAlongFirst = state.get(CONNECTED_ALONG_FIRST_COORDINATE); boolean connectionAlongFirst = state.get(CONNECTED_ALONG_FIRST_COORDINATE);
Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) Axis connectionAxis =
: (axis == Axis.Z ? Axis.Y : Axis.Z); connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) : (axis == Axis.Z ? Axis.Y : Axis.Z);
Axis otherAxis = other.get(AXIS); Axis otherAxis = other.get(AXIS);
boolean otherConnection = other.get(CONNECTED_ALONG_FIRST_COORDINATE); boolean otherConnection = other.get(CONNECTED_ALONG_FIRST_COORDINATE);
Axis otherConnectionAxis = otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) Axis otherConnectionAxis =
: (otherAxis == Axis.Z ? Axis.Y : Axis.Z); otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) : (otherAxis == Axis.Z ? Axis.Y : Axis.Z);
if (otherConnectionAxis != connectionAxis) if (otherConnectionAxis != connectionAxis)
return false; return false;

View File

@ -36,11 +36,13 @@ public class EncasedShaftBlock extends RotatedPillarKineticBlock {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
if (context.getPlayer().isSneaking()) if (context.getPlayer() != null && context.getPlayer()
.isSneaking())
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
Axis preferredAxis = getPreferredAxis(context); Axis preferredAxis = getPreferredAxis(context);
return this.getDefaultState().with(AXIS, return this.getDefaultState()
preferredAxis == null ? context.getNearestLookingDirection().getAxis() : preferredAxis); .with(AXIS, preferredAxis == null ? context.getNearestLookingDirection()
.getAxis() : preferredAxis);
} }
@Override @Override

View File

@ -52,7 +52,7 @@ public interface IWrenchable {
BlockPos pos = context.getPos(); BlockPos pos = context.getPos();
PlayerEntity player = context.getPlayer(); PlayerEntity player = context.getPlayer();
if (world instanceof ServerWorld) { if (world instanceof ServerWorld) {
if (!player.isCreative()) if (player != null && !player.isCreative())
Block.getDrops(state, (ServerWorld) world, pos, world.getTileEntity(pos), player, context.getItem()) Block.getDrops(state, (ServerWorld) world, pos, world.getTileEntity(pos), player, context.getItem())
.forEach(itemStack -> { .forEach(itemStack -> {
player.inventory.placeItemBackInInventory(world, itemStack); player.inventory.placeItemBackInInventory(world, itemStack);

View File

@ -6,24 +6,28 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import javax.annotation.Nonnull;
public class WrenchItem extends Item { public class WrenchItem extends Item {
public WrenchItem(Properties properties) { public WrenchItem(Properties properties) {
super(properties); super(properties);
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
PlayerEntity player = context.getPlayer(); PlayerEntity player = context.getPlayer();
if (!player.isAllowEdit()) if (player == null || !player.isAllowEdit())
return super.onItemUse(context); return super.onItemUse(context);
BlockState state = context.getWorld().getBlockState(context.getPos()); BlockState state = context.getWorld()
.getBlockState(context.getPos());
if (!(state.getBlock() instanceof IWrenchable)) if (!(state.getBlock() instanceof IWrenchable))
return super.onItemUse(context); return super.onItemUse(context);
IWrenchable actor = (IWrenchable) state.getBlock(); IWrenchable actor = (IWrenchable) state.getBlock();
if (player.isSneaking()) if (player.isSneaking())
return actor.onSneakWrenched(state, context); return actor.onSneakWrenched(state, context);
return actor.onWrenched(state, context); return actor.onWrenched(state, context);
} }

View File

@ -21,7 +21,8 @@ public class TreeFertilizerItem extends Item {
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
BlockState state = context.getWorld().getBlockState(context.getPos()); BlockState state = context.getWorld()
.getBlockState(context.getPos());
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof SaplingBlock) { if (block instanceof SaplingBlock) {
@ -34,31 +35,46 @@ public class TreeFertilizerItem extends Item {
BlockPos saplingPos = context.getPos(); BlockPos saplingPos = context.getPos();
for (BlockPos pos : BlockPos.getAllInBoxMutable(-1, 0, -1, 1, 0, 1)) { 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)); 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()) { for (BlockPos pos : world.blocksAdded.keySet()) {
BlockPos actualPos = pos.add(saplingPos).down(10); BlockPos actualPos = pos.add(saplingPos)
.down(10);
// Don't replace Bedrock // 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; continue;
// Don't replace solid blocks with leaves // Don't replace solid blocks with leaves
if (!world.getBlockState(pos).isNormalCube(world, pos) && !context.getWorld().getBlockState(actualPos) if (!world.getBlockState(pos)
.getCollisionShape(context.getWorld(), actualPos).isEmpty()) .isNormalCube(world, pos)
&& !context.getWorld()
.getBlockState(actualPos)
.getCollisionShape(context.getWorld(), actualPos)
.isEmpty())
continue; continue;
if (world.getBlockState(pos).getBlock() == Blocks.GRASS_BLOCK if (world.getBlockState(pos)
|| world.getBlockState(pos).getBlock() == Blocks.PODZOL) .getBlock() == Blocks.GRASS_BLOCK
|| world.getBlockState(pos)
.getBlock() == Blocks.PODZOL)
continue; continue;
context.getWorld().setBlockState(actualPos, world.getBlockState(pos)); context.getWorld()
.setBlockState(actualPos, world.getBlockState(pos));
} }
if (!context.getPlayer().isCreative()) if (context.getPlayer() != null && !context.getPlayer()
context.getItem().shrink(1); .isCreative())
context.getItem()
.shrink(1);
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }

View File

@ -38,6 +38,8 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.PacketDistributor;
import javax.annotation.Nonnull;
public class SymmetryWandItem extends Item { public class SymmetryWandItem extends Item {
public static final String SYMMETRY = "symmetry"; public static final String SYMMETRY = "symmetry";
@ -48,10 +50,13 @@ public class SymmetryWandItem extends Item {
.rarity(Rarity.UNCOMMON)); .rarity(Rarity.UNCOMMON));
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
PlayerEntity player = context.getPlayer(); PlayerEntity player = context.getPlayer();
BlockPos pos = context.getPos(); BlockPos pos = context.getPos();
if (player == null)
return ActionResultType.PASS;
player.getCooldownTracker() player.getCooldownTracker()
.setCooldown(this, 5); .setCooldown(this, 5);
ItemStack wand = player.getHeldItem(context.getHand()); ItemStack wand = player.getHeldItem(context.getHand());

View File

@ -41,6 +41,8 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.PacketDistributor;
import javax.annotation.Nonnull;
public abstract class ZapperItem extends Item { public abstract class ZapperItem extends Item {
public ZapperItem(Properties properties) { public ZapperItem(Properties properties) {
@ -80,10 +82,11 @@ public abstract class ZapperItem extends Item {
return newStack.getItem() instanceof ZapperItem; return newStack.getItem() instanceof ZapperItem;
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
// Shift -> open GUI // Shift -> open GUI
if (context.getPlayer() if (context.getPlayer() != null && context.getPlayer()
.isSneaking()) { .isSneaking()) {
if (context.getWorld().isRemote) { if (context.getWorld().isRemote) {
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
@ -218,7 +221,7 @@ public abstract class ZapperItem extends Item {
public boolean onEntitySwing(ItemStack stack, LivingEntity entity) { public boolean onEntitySwing(ItemStack stack, LivingEntity entity) {
return true; return true;
} }
@Override @Override
public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) { public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
return false; return false;

View File

@ -23,7 +23,8 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
public CrateBlock(Properties p_i48415_1_) { public CrateBlock(Properties p_i48415_1_) {
super(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 @Override
@ -33,17 +34,18 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn,
BlockPos currentPos, BlockPos facingPos) { BlockPos currentPos, BlockPos facingPos) {
boolean isDouble = stateIn.get(DOUBLE); boolean isDouble = stateIn.get(DOUBLE);
Direction blockFacing = stateIn.get(FACING); Direction blockFacing = stateIn.get(FACING);
boolean isFacingOther = facingState.getBlock() == this && facingState.get(DOUBLE) boolean isFacingOther = facingState.getBlock() == this && facingState.get(DOUBLE)
&& facingState.get(FACING) == facing.getOpposite(); && facingState.get(FACING) == facing.getOpposite();
if (!isDouble) { if (!isDouble) {
if (!isFacingOther) if (!isFacingOther)
return stateIn; return stateIn;
return stateIn.with(DOUBLE, true).with(FACING, facing); return stateIn.with(DOUBLE, true)
.with(FACING, facing);
} }
if (facing != blockFacing) if (facing != blockFacing)
@ -59,18 +61,22 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
BlockPos pos = context.getPos(); BlockPos pos = context.getPos();
World world = context.getWorld(); World world = context.getWorld();
if (!context.getPlayer().isSneaking()) { if (context.getPlayer() == null || !context.getPlayer()
.isSneaking()) {
for (Direction d : Direction.values()) { for (Direction d : Direction.values()) {
BlockState state = world.getBlockState(pos.offset(d)); BlockState state = world.getBlockState(pos.offset(d));
if (state.getBlock() == this && !state.get(DOUBLE)) 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)); BlockState state = world.getBlockState(pos.offset(placedOnFace));
if (state.getBlock() == this && !state.get(DOUBLE)) 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(); return getDefaultState();
} }

View File

@ -28,7 +28,8 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor
public RedstoneContactBlock(Properties properties) { public RedstoneContactBlock(Properties properties) {
super(properties); super(properties);
setDefaultState(getDefaultState().with(POWERED, false).with(FACING, Direction.UP)); setDefaultState(getDefaultState().with(POWERED, false)
.with(FACING, Direction.UP));
} }
@Override @Override
@ -39,10 +40,13 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState state = getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite()); BlockState state = getDefaultState().with(FACING, context.getNearestLookingDirection()
Direction placeDirection = context.getFace().getOpposite(); .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); state = state.with(FACING, placeDirection);
if (hasValidContact(context.getWorld(), context.getPos(), state.get(FACING))) if (hasValidContact(context.getWorld(), context.getPos(), state.get(FACING)))
state = state.with(POWERED, true); state = state.with(POWERED, true);
@ -52,7 +56,7 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn,
BlockPos currentPos, BlockPos facingPos) { BlockPos currentPos, BlockPos facingPos) {
if (facing != stateIn.get(FACING)) if (facing != stateIn.get(FACING))
return stateIn; return stateIn;
boolean hasValidContact = hasValidContact(worldIn, currentPos, facing); boolean hasValidContact = hasValidContact(worldIn, currentPos, facing);

View File

@ -36,6 +36,8 @@ import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
public class FilterItem extends Item implements INamedContainerProvider { public class FilterItem extends Item implements INamedContainerProvider {
private FilterType type; private FilterType type;
@ -43,22 +45,25 @@ public class FilterItem extends Item implements INamedContainerProvider {
private enum FilterType { private enum FilterType {
REGULAR, ATTRIBUTE; REGULAR, ATTRIBUTE;
} }
public static FilterItem regular(Properties properties) { public static FilterItem regular(Properties properties) {
return new FilterItem(FilterType.REGULAR, properties); return new FilterItem(FilterType.REGULAR, properties);
} }
public static FilterItem attribute(Properties properties) { public static FilterItem attribute(Properties properties) {
return new FilterItem(FilterType.ATTRIBUTE, properties); return new FilterItem(FilterType.ATTRIBUTE, properties);
} }
private FilterItem(FilterType type, Properties properties) { private FilterItem(FilterType type, Properties properties) {
super(properties); super(properties);
this.type = type; this.type = type;
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
if (context.getPlayer() == null)
return ActionResultType.PASS;
return onItemRightClick(context.getWorld(), context.getPlayer(), context.getHand()).getType(); return onItemRightClick(context.getWorld(), context.getPlayer(), context.getHand()).getType();
} }
@ -73,16 +78,17 @@ public class FilterItem extends Item implements INamedContainerProvider {
ItemDescription.add(tooltip, makeSummary); ItemDescription.add(tooltip, makeSummary);
} }
} }
private List<String> makeSummary(ItemStack filter) { private List<String> makeSummary(ItemStack filter) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (type == FilterType.REGULAR) { if (type == FilterType.REGULAR) {
ItemStackHandler filterItems = getFilterItems(filter); ItemStackHandler filterItems = getFilterItems(filter);
boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist"); boolean blacklist = filter.getOrCreateTag()
.getBoolean("Blacklist");
list.add(TextFormatting.GOLD 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; int count = 0;
for (int i = 0; i < filterItems.getSlots(); i++) { for (int i = 0; i < filterItems.getSlots(); i++) {
if (count > 3) { if (count > 3) {
@ -93,7 +99,8 @@ public class FilterItem extends Item implements INamedContainerProvider {
ItemStack filterStack = filterItems.getStackInSlot(i); ItemStack filterStack = filterItems.getStackInSlot(i);
if (filterStack.isEmpty()) if (filterStack.isEmpty())
continue; continue;
list.add(TextFormatting.GRAY + "- " + filterStack.getDisplayName().getFormattedText()); list.add(TextFormatting.GRAY + "- " + filterStack.getDisplayName()
.getFormattedText());
count++; count++;
} }
@ -102,15 +109,17 @@ public class FilterItem extends Item implements INamedContainerProvider {
} }
if (type == FilterType.ATTRIBUTE) { 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 list.add(TextFormatting.GOLD + (whitelistMode == WhitelistMode.WHITELIST_CONJ
? Lang.translate("gui.attribute_filter.whitelist_conjunctive") ? Lang.translate("gui.attribute_filter.whitelist_conjunctive")
: whitelistMode == WhitelistMode.WHITELIST_DISJ : whitelistMode == WhitelistMode.WHITELIST_DISJ
? Lang.translate("gui.attribute_filter.whitelist_disjunctive") ? Lang.translate("gui.attribute_filter.whitelist_disjunctive")
: Lang.translate("gui.attribute_filter.blacklist"))); : Lang.translate("gui.attribute_filter.blacklist")));
int count = 0; 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) { for (INBT inbt : attributes) {
ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt); ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt);
if (count > 3) { 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) { private static boolean test(World world, ItemStack stack, ItemStack filter, boolean matchNBT) {
if (filter.isEmpty()) if (filter.isEmpty())
return true; return true;
if (!(filter.getItem() instanceof FilterItem)) if (!(filter.getItem() instanceof FilterItem))
return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack) return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack)
: ItemStack.areItemsEqual(filter, stack)); : ItemStack.areItemsEqual(filter, stack));
if (AllItems.FILTER.get() == filter.getItem()) { if (AllItems.FILTER.get() == filter.getItem()) {
ItemStackHandler filterItems = getFilterItems(filter); ItemStackHandler filterItems = getFilterItems(filter);
boolean respectNBT = filter.getOrCreateTag().getBoolean("RespectNBT"); boolean respectNBT = filter.getOrCreateTag()
boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist"); .getBoolean("RespectNBT");
boolean blacklist = filter.getOrCreateTag()
.getBoolean("Blacklist");
for (int slot = 0; slot < filterItems.getSlots(); slot++) { for (int slot = 0; slot < filterItems.getSlots(); slot++) {
ItemStack stackInSlot = filterItems.getStackInSlot(slot); ItemStack stackInSlot = filterItems.getStackInSlot(slot);
if (stackInSlot.isEmpty()) if (stackInSlot.isEmpty())
@ -195,8 +206,10 @@ public class FilterItem extends Item implements INamedContainerProvider {
} }
if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) { if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) {
WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag().getInt("WhitelistMode")]; WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag()
ListNBT attributes = filter.getOrCreateTag().getList("MatchedAttributes", NBT.TAG_COMPOUND); .getInt("WhitelistMode")];
ListNBT attributes = filter.getOrCreateTag()
.getList("MatchedAttributes", NBT.TAG_COMPOUND);
for (INBT inbt : attributes) { for (INBT inbt : attributes) {
ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt); ItemAttribute attribute = ItemAttribute.fromNBT((CompoundNBT) inbt);
boolean matches = attribute.appliesTo(stack, world); boolean matches = attribute.appliesTo(stack, world);

View File

@ -41,6 +41,8 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.thread.SidedThreadGroups; import net.minecraftforge.fml.common.thread.SidedThreadGroups;
import javax.annotation.Nonnull;
public class SchematicItem extends Item { public class SchematicItem extends Item {
public SchematicItem(Properties properties) { public SchematicItem(Properties properties) {
@ -70,8 +72,10 @@ public class SchematicItem extends Item {
@OnlyIn(value = Dist.CLIENT) @OnlyIn(value = Dist.CLIENT)
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
if (stack.hasTag()) { if (stack.hasTag()) {
if (stack.getTag().contains("File")) if (stack.getTag()
tooltip.add(new StringTextComponent(TextFormatting.GOLD + stack.getTag().getString("File"))); .contains("File"))
tooltip.add(new StringTextComponent(TextFormatting.GOLD + stack.getTag()
.getString("File")));
} else { } else {
tooltip.add(new StringTextComponent(TextFormatting.RED + Lang.translate("schematic.invalid"))); 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) { public static Template loadSchematic(ItemStack blueprint) {
Template t = new Template(); Template t = new Template();
String owner = blueprint.getTag().getString("Owner"); String owner = blueprint.getTag()
String schematic = blueprint.getTag().getString("File"); .getString("Owner");
String schematic = blueprint.getTag()
.getString("File");
String filepath = ""; String filepath = "";
if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER) if (Thread.currentThread()
.getThreadGroup() == SidedThreadGroups.SERVER)
filepath = "schematics/uploaded/" + owner + "/" + schematic; filepath = "schematics/uploaded/" + owner + "/" + schematic;
else else
filepath = "schematics/" + schematic; filepath = "schematics/" + schematic;
@ -121,9 +128,10 @@ public class SchematicItem extends Item {
return t; return t;
} }
@Nonnull
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { 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 super.onItemUse(context);
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@ -138,7 +146,8 @@ public class SchematicItem extends Item {
private boolean onItemUse(PlayerEntity player, Hand hand) { private boolean onItemUse(PlayerEntity player, Hand hand) {
if (!player.isSneaking() || hand != Hand.MAIN_HAND) if (!player.isSneaking() || hand != Hand.MAIN_HAND)
return false; return false;
if (!player.getHeldItem(hand).hasTag()) if (!player.getHeldItem(hand)
.hasTag())
return false; return false;
DistExecutor.runWhenOn(Dist.CLIENT, () -> this::displayBlueprintScreen); DistExecutor.runWhenOn(Dist.CLIENT, () -> this::displayBlueprintScreen);
return true; return true;