use of net.minecraft.world.level.block.ObserverBlock in project Create by Creators-of-Create.
the class EjectorTileEntity method launchItems.
protected void launchItems() {
ItemStack heldItemStack = depotBehaviour.getHeldItemStack();
Direction funnelFacing = getFacing().getOpposite();
if (AbstractFunnelBlock.getFunnelFacing(level.getBlockState(worldPosition.above())) == funnelFacing) {
DirectBeltInputBehaviour directOutput = getBehaviour(DirectBeltInputBehaviour.TYPE);
if (depotBehaviour.heldItem != null) {
ItemStack remainder = directOutput.tryExportingToBeltFunnel(heldItemStack, funnelFacing, false);
if (remainder == null)
;
else if (remainder.isEmpty())
depotBehaviour.removeHeldItem();
else if (!remainder.sameItem(heldItemStack))
depotBehaviour.heldItem.stack = remainder;
}
for (Iterator<TransportedItemStack> iterator = depotBehaviour.incoming.iterator(); iterator.hasNext(); ) {
TransportedItemStack transportedItemStack = iterator.next();
ItemStack stack = transportedItemStack.stack;
ItemStack remainder = directOutput.tryExportingToBeltFunnel(stack, funnelFacing, false);
if (remainder == null)
;
else if (remainder.isEmpty())
iterator.remove();
else if (!remainder.sameItem(stack))
transportedItemStack.stack = remainder;
}
ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
for (int i = 0; i < outputs.getSlots(); i++) {
ItemStack remainder = directOutput.tryExportingToBeltFunnel(outputs.getStackInSlot(i), funnelFacing, false);
if (remainder != null)
outputs.setStackInSlot(i, remainder);
}
return;
}
if (!level.isClientSide)
for (Direction d : Iterate.directions) {
BlockState blockState = level.getBlockState(worldPosition.relative(d));
if (!(blockState.getBlock() instanceof ObserverBlock))
continue;
if (blockState.getValue(ObserverBlock.FACING) != d.getOpposite())
continue;
blockState.updateShape(d.getOpposite(), blockState, level, worldPosition.relative(d), worldPosition);
}
if (depotBehaviour.heldItem != null) {
addToLaunchedItems(heldItemStack);
depotBehaviour.removeHeldItem();
}
for (TransportedItemStack transportedItemStack : depotBehaviour.incoming) addToLaunchedItems(transportedItemStack.stack);
depotBehaviour.incoming.clear();
ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
for (int i = 0; i < outputs.getSlots(); i++) {
ItemStack extractItem = outputs.extractItem(i, 64, false);
if (!extractItem.isEmpty())
addToLaunchedItems(extractItem);
}
}
use of net.minecraft.world.level.block.ObserverBlock in project fabric-carpet by gnembon.
the class BlockRotator method alternativeBlockPlacement.
public static // World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
BlockState alternativeBlockPlacement(// World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
Block block, // World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
BlockPlaceContext context) {
//
if (true)
throw new UnsupportedOperationException("Alternative Block Placement / client controlled / is not implemnted");
Direction facing;
Vec3 vec3d = context.getClickLocation();
float hitX = (float) vec3d.x;
if (// vanilla
hitX < 2)
return null;
int code = (int) (hitX - 2) / 2;
//
// now it would be great if hitX was adjusted in context to original range from 0.0 to 1.0
// since its actually using it. Its private - maybe with Reflections?
//
Player placer = context.getPlayer();
BlockPos pos = context.getClickedPos();
Level world = context.getLevel();
if (block instanceof GlazedTerracottaBlock) {
facing = Direction.from3DDataValue(code);
if (facing == Direction.UP || facing == Direction.DOWN) {
facing = placer.getDirection().getOpposite();
}
return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing);
} else if (block instanceof ObserverBlock) {
return block.defaultBlockState().setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code)).setValue(ObserverBlock.POWERED, true);
} else if (block instanceof RepeaterBlock) {
facing = Direction.from3DDataValue(code % 16);
if (facing == Direction.UP || facing == Direction.DOWN) {
facing = placer.getDirection().getOpposite();
}
return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing).setValue(RepeaterBlock.DELAY, Mth.clamp(code / 16, 1, 4)).setValue(RepeaterBlock.LOCKED, Boolean.FALSE);
} else if (block instanceof TrapDoorBlock) {
return block.defaultBlockState().setValue(TrapDoorBlock.FACING, Direction.from3DDataValue(code % 16)).setValue(TrapDoorBlock.OPEN, Boolean.FALSE).setValue(TrapDoorBlock.HALF, (code >= 16) ? Half.TOP : Half.BOTTOM).setValue(TrapDoorBlock.OPEN, world.hasNeighborSignal(pos));
} else if (block instanceof ComparatorBlock) {
facing = Direction.from3DDataValue(code % 16);
if ((facing == Direction.UP) || (facing == Direction.DOWN)) {
facing = placer.getDirection().getOpposite();
}
ComparatorMode m = (hitX >= 16) ? ComparatorMode.SUBTRACT : ComparatorMode.COMPARE;
return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing).setValue(ComparatorBlock.POWERED, Boolean.FALSE).setValue(ComparatorBlock.MODE, m);
} else if (block instanceof DispenserBlock) {
return block.defaultBlockState().setValue(DispenserBlock.FACING, Direction.from3DDataValue(code)).setValue(DispenserBlock.TRIGGERED, Boolean.FALSE);
} else if (block instanceof PistonBaseBlock) {
return block.defaultBlockState().setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code)).setValue(PistonBaseBlock.EXTENDED, Boolean.FALSE);
} else if (block instanceof StairBlock) {
return // worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
block.getStateForPlacement(context).setValue(StairBlock.FACING, Direction.from3DDataValue(code % 16)).setValue(StairBlock.HALF, (hitX >= 16) ? Half.TOP : Half.BOTTOM);
}
return null;
}
use of net.minecraft.world.level.block.ObserverBlock in project fabric-carpet by gnembon.
the class BlockRotator method flip_block.
public static boolean flip_block(BlockState state, Level world, Player player, InteractionHand hand, BlockHitResult hit) {
Block block = state.getBlock();
BlockPos pos = hit.getBlockPos();
Vec3 hitVec = hit.getLocation().subtract(pos.getX(), pos.getY(), pos.getZ());
Direction facing = hit.getDirection();
BlockState newState = null;
if ((block instanceof GlazedTerracottaBlock) || (block instanceof DiodeBlock) || (block instanceof BaseRailBlock) || (block instanceof TrapDoorBlock) || (block instanceof LeverBlock) || (block instanceof FenceGateBlock)) {
newState = state.rotate(Rotation.CLOCKWISE_90);
} else if ((block instanceof ObserverBlock) || (block instanceof EndRodBlock)) {
newState = state.setValue(DirectionalBlock.FACING, state.getValue(DirectionalBlock.FACING).getOpposite());
} else if (block instanceof DispenserBlock) {
newState = state.setValue(DispenserBlock.FACING, state.getValue(DispenserBlock.FACING).getOpposite());
} else if (block instanceof PistonBaseBlock) {
if (!(state.getValue(PistonBaseBlock.EXTENDED)))
newState = state.setValue(DirectionalBlock.FACING, state.getValue(DirectionalBlock.FACING).getOpposite());
} else if (block instanceof SlabBlock) {
if (((SlabBlock) block).useShapeForLightOcclusion(state)) {
newState = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
}
} else if (block instanceof HopperBlock) {
if (state.getValue(HopperBlock.FACING) != Direction.DOWN) {
newState = state.setValue(HopperBlock.FACING, state.getValue(HopperBlock.FACING).getClockWise());
}
} else if (block instanceof StairBlock) {
// LOG.error(String.format("hit with facing: %s, at side %.1fX, X %.1fY, Y %.1fZ",facing, hitX, hitY, hitZ));
if ((facing == Direction.UP && hitVec.y == 1.0f) || (facing == Direction.DOWN && hitVec.y == 0.0f)) {
newState = state.setValue(StairBlock.HALF, state.getValue(StairBlock.HALF) == Half.TOP ? Half.BOTTOM : Half.TOP);
} else {
boolean turn_right;
if (facing == Direction.NORTH) {
turn_right = (hitVec.x <= 0.5);
} else if (facing == Direction.SOUTH) {
turn_right = !(hitVec.x <= 0.5);
} else if (facing == Direction.EAST) {
turn_right = (hitVec.z <= 0.5);
} else if (facing == Direction.WEST) {
turn_right = !(hitVec.z <= 0.5);
} else {
return false;
}
if (turn_right) {
newState = state.rotate(Rotation.COUNTERCLOCKWISE_90);
} else {
newState = state.rotate(Rotation.CLOCKWISE_90);
}
}
} else if (block instanceof RotatedPillarBlock) {
switch((Direction.Axis) state.getValue(RotatedPillarBlock.AXIS)) {
case X:
newState = (BlockState) state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.Z);
break;
case Z:
newState = (BlockState) state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.Y);
break;
case Y:
newState = (BlockState) state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.X);
break;
}
} else {
return false;
}
if (newState != null) {
world.setBlock(pos, newState, 2 | 1024);
world.setBlocksDirty(pos, state, newState);
return true;
}
return false;
}
Aggregations