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,13 +47,16 @@ 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);
@ -58,16 +64,20 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
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

@ -42,7 +42,8 @@ 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,17 +55,20 @@ 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
@ -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()
.isSneaking()) {
if (isChassis(blockState))
return getDefaultState().with(AXIS, blockState.get(AXIS)); return getDefaultState().with(AXIS, blockState.get(AXIS));
if (!context.getPlayer()
.isSneaking())
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,7 +91,8 @@ 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));

View File

@ -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;
} }
@ -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,10 +51,11 @@ 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;
@ -78,7 +82,7 @@ public class BeltConnectorItem extends BlockItem {
} }
} }
if (!validAxis) if (!validAxis || playerEntity == null)
return ActionResultType.FAIL; return ActionResultType.FAIL;
if (tag.contains("FirstPulley")) { if (tag.contains("FirstPulley")) {
@ -86,11 +90,10 @@ 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);
} }
@ -99,8 +102,7 @@ public class BeltConnectorItem extends BlockItem {
.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;
@ -109,8 +111,7 @@ public class BeltConnectorItem extends BlockItem {
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;
} }

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);
@ -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,8 +67,8 @@ 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;
} }
@ -76,8 +79,8 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
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,19 +6,23 @@ 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();

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, () -> () -> {

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
@ -43,7 +44,8 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
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);

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;
@ -57,8 +59,11 @@ public class FilterItem extends Item implements INamedContainerProvider {
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();
} }
@ -79,7 +84,8 @@ public class FilterItem extends Item implements INamedContainerProvider {
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")));
@ -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,7 +109,8 @@ 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
@ -110,7 +118,8 @@ public class FilterItem extends Item implements INamedContainerProvider {
: 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) {
@ -181,8 +190,10 @@ public class FilterItem extends Item implements INamedContainerProvider {
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;