net.minecraft.item.ItemPlacementContext Java Examples
The following examples show how to use
net.minecraft.item.ItemPlacementContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AluminumWireBlock.java From Galacticraft-Rewoven with MIT License | 7 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { BlockState state = this.getDefaultState(); for (Direction direction : Direction.values()) { Block block = context.getWorld().getBlockState(context.getBlockPos().offset(direction)).getBlock(); if (block instanceof WireConnectable) { if (((WireConnectable) block).canWireConnect(context.getWorld(), direction.getOpposite(), context.getBlockPos(), context.getBlockPos().offset(direction)) != WireConnectionType.NONE) { state = state.with(propFromDirection(direction), true); } } else if (block instanceof ComponentProvider && ((ComponentProvider) block).hasComponent(UniversalComponents.CAPACITOR_COMPONENT)) { state = state.with(propFromDirection(direction), true); } } return state; }
Example #2
Source File: BlockItem_creativeNoClipMixin.java From fabric-carpet with MIT License | 6 votes |
@Redirect(method = "canPlace", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;canPlace(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityContext;)Z" )) private boolean canSpectatingPlace(World world, BlockState state, BlockPos pos, EntityContext context, ItemPlacementContext contextOuter, BlockState stateOuter) { PlayerEntity player = contextOuter.getPlayer(); if (CarpetSettings.creativeNoClip && player != null && player.isCreative() && player.abilities.flying) { // copy from canPlace VoxelShape voxelShape = state.getCollisionShape(world, pos, context); return voxelShape.isEmpty() || world.intersectsEntities(player, voxelShape.offset(pos.getX(), pos.getY(), pos.getZ())); } return world.canPlace(state, pos, context); }
Example #3
Source File: MixinBlockItem.java From Sandbox with GNU Lesser General Public License v3.0 | 6 votes |
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", at = @At(value = "HEAD"), cancellable = true ) public void place(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> info) { BlockEvent.Place event = EventDispatcher.publish(new BlockEvent.Place( (World) context.getWorld(), (Position) context.getBlockPos(), (org.sandboxpowered.sandbox.api.state.BlockState) state )); BlockState state2 = WrappingUtil.convert(event.getState()); if (event.isCancelled()) { info.setReturnValue(false); } else if (state2 != state) { info.setReturnValue(context.getWorld().setBlockState(context.getBlockPos(), state2, 11)); } }
Example #4
Source File: MixinBlockItem.java From multiconnect with MIT License | 6 votes |
@Inject(method = "canPlace", at = @At("HEAD"), cancellable = true) private void onCanPlace(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) { Block block = state.getBlock(); if (block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { World world = context.getWorld(); BlockPos pos = context.getBlockPos(); boolean foundAdjChest = false; for (Direction dir : Direction.Type.HORIZONTAL) { BlockState otherState = world.getBlockState(pos.offset(dir)); if (otherState.getBlock() == block) { if (foundAdjChest) { ci.setReturnValue(false); return; } foundAdjChest = true; if (otherState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) { ci.setReturnValue(false); return; } } } } } }
Example #5
Source File: TinyPumpkinBlock.java From the-hallow with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext placementContext) { final BlockState blockState = this.getDefaultState().with(FACING, placementContext.getPlayerFacing().getOpposite()); if (blockState.contains(Properties.WATERLOGGED)) { final FluidState fluidState = placementContext.getWorld().getFluidState(placementContext.getBlockPos()); return blockState.with(Properties.WATERLOGGED, fluidState.getFluid() == Fluids.WATER); } return blockState; }
Example #6
Source File: HopperBlock_cactusMixin.java From fabric-carpet with MIT License | 5 votes |
@Redirect(method = "getPlacementState", at = @At( value = "INVOKE", target = "Lnet/minecraft/item/ItemPlacementContext;getSide()Lnet/minecraft/util/math/Direction;" )) private Direction getOppositeOpposite(ItemPlacementContext context) { if (BlockRotator.flippinEligibility(context.getPlayer())) { return context.getSide().getOpposite(); } return context.getSide(); }
Example #7
Source File: CarpetBlockMixin.java From fabric-carpet with MIT License | 5 votes |
public BlockState getPlacementState(ItemPlacementContext context) { BlockState state = super.getPlacementState(context); if (context.getPlayer() != null && !context.getWorld().isClient) { WoolTool.carpetPlacedAction(((CarpetBlock)(Object)this).getColor(), context.getPlayer(), context.getBlockPos(), (ServerWorld) context.getWorld()); } return state; }
Example #8
Source File: BlockItem_scarpetEventMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At( value = "INVOKE", target = "Lnet/minecraft/block/Block;onPlaced(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER )) private void afterPlacement(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> cir) { if (context.getPlayer() instanceof ServerPlayerEntity && PLAYER_PLACES_BLOCK.isNeeded()) PLAYER_PLACES_BLOCK.onBlockPlaced((ServerPlayerEntity) context.getPlayer(), context.getBlockPos(), context.getHand(), context.getStack()); }
Example #9
Source File: BlockItemMixin_accurateBlockPlacement.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
@Redirect(method = "getPlacementState", at = @At( value = "INVOKE", target = "Lnet/minecraft/block/Block;getPlacementState(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/block/BlockState;" )) private BlockState getAlternatePlacement(Block block, ItemPlacementContext itemPlacementContext_1) { if (CarpetExtraSettings.accurateBlockPlacement) { BlockState tryAlternative = BlockPlacer.alternativeBlockPlacement(block, itemPlacementContext_1); if (tryAlternative != null) return tryAlternative; } return block.getPlacementState(itemPlacementContext_1); }
Example #10
Source File: CoalGeneratorBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #11
Source File: EnergyStorageModuleBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #12
Source File: ElectricCompressorBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext itemPlacementContext_1) { return super.getPlacementState(itemPlacementContext_1).with(FACING, itemPlacementContext_1.getPlayerFacing().getOpposite()).with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #13
Source File: GratingBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { FluidState fluidState = context.getWorld().getFluidState(context.getBlockPos()); BlockState blockState = this.getDefaultState().with(GRATING_STATE, GratingState.LOWER) .with(FLUID, Registry.FLUID.getId(fluidState.getFluid())) .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1)); BlockPos blockPos = context.getBlockPos(); Direction direction = context.getPlayerFacing(); return direction != Direction.DOWN && (direction == Direction.UP || context.getBlockPos().getY() - (double) blockPos.getY() <= 0.5D) ? blockState : blockState.with(GRATING_STATE, GratingState.UPPER); }
Example #14
Source File: FluidPipeBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { BlockState state = this.getDefaultState(); for (Direction direction : Direction.values()) { Block block = context.getWorld().getBlockState(context.getBlockPos().offset(direction)).getBlock(); if (block instanceof FluidPipeBlock) state = state.with(propFromDirection(direction), true); } return state; }
Example #15
Source File: Walkway.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { FluidState fluidState = context.getWorld().getFluidState(context.getBlockPos()); return this.getDefaultState() .with(FLUID, Registry.FLUID.getId(fluidState.getFluid())) .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1)); }
Example #16
Source File: OxygenCollectorBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #17
Source File: BasicSolarPanelBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #18
Source File: CircuitFabricatorBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #19
Source File: RefineryBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()) .with(FRONT_SIDE_OPTION, SideOption.DEFAULT) .with(BACK_SIDE_OPTION, SideOption.DEFAULT) .with(RIGHT_SIDE_OPTION, SideOption.DEFAULT) .with(LEFT_SIDE_OPTION, SideOption.DEFAULT) .with(TOP_SIDE_OPTION, SideOption.DEFAULT) .with(BOTTOM_SIDE_OPTION, SideOption.DEFAULT); }
Example #20
Source File: TombstoneBlock.java From the-hallow with MIT License | 4 votes |
@Override public BlockState getPlacementState(ItemPlacementContext placementContext) { return this.getDefaultState().with(FACING, placementContext.getPlayerFacing().getOpposite()); }
Example #21
Source File: HallowedGateBlock.java From the-hallow with MIT License | 4 votes |
@Nullable @Override public BlockState getPlacementState(ItemPlacementContext context) { return getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()); }
Example #22
Source File: BlockPlacer.java From carpet-extra with GNU Lesser General Public License v3.0 | 4 votes |
public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { //actual alternative block placement code Direction facing; Vec3d vec3d = context.getHitPos(); BlockPos pos = context.getBlockPos(); float hitX = (float) vec3d.x - pos.getX(); if (hitX<2) // vanilla 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? // PlayerEntity placer = context.getPlayer(); World world = context.getWorld(); if (block instanceof GlazedTerracottaBlock) { facing = Direction.byId(code); if(facing == Direction.UP || facing == Direction.DOWN) { facing = placer.getHorizontalFacing().getOpposite(); } return block.getDefaultState().with(HorizontalFacingBlock.FACING, facing); } else if (block instanceof ObserverBlock) { return block.getDefaultState() .with(FacingBlock.FACING, Direction.byId(code)) .with(ObserverBlock.POWERED, true); } else if (block instanceof RepeaterBlock) { facing = Direction.byId(code % 16); if(facing == Direction.UP || facing == Direction.DOWN) { facing = placer.getHorizontalFacing().getOpposite(); } return block.getDefaultState() .with(HorizontalFacingBlock.FACING, facing) .with(RepeaterBlock.DELAY, MathHelper.clamp(code / 16, 1, 4)) .with(RepeaterBlock.LOCKED, Boolean.FALSE); } else if (block instanceof TrapdoorBlock) { return block.getDefaultState() .with(TrapdoorBlock.FACING, Direction.byId(code % 16)) .with(TrapdoorBlock.OPEN, Boolean.FALSE) .with(TrapdoorBlock.HALF, (code >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM) .with(TrapdoorBlock.OPEN, world.isReceivingRedstonePower(pos)); } else if (block instanceof ComparatorBlock) { facing = Direction.byId(code % 16); if((facing == Direction.UP) || (facing == Direction.DOWN)) { facing = placer.getHorizontalFacing().getOpposite(); } ComparatorMode m = (hitX >= 16)?ComparatorMode.SUBTRACT: ComparatorMode.COMPARE; return block.getDefaultState() .with(HorizontalFacingBlock.FACING, facing) .with(ComparatorBlock.POWERED, Boolean.FALSE) .with(ComparatorBlock.MODE, m); } else if (block instanceof DispenserBlock) { return block.getDefaultState() .with(DispenserBlock.FACING, Direction.byId(code)) .with(DispenserBlock.TRIGGERED, Boolean.FALSE); } else if (block instanceof PistonBlock) { return block.getDefaultState() .with(FacingBlock.FACING, Direction.byId(code)) .with(PistonBlock.EXTENDED, Boolean.FALSE); } else if (block instanceof StairsBlock) { return block.getPlacementState(context)//worldIn, pos, facing, hitX, hitY, hitZ, meta, placer) .with(StairsBlock.FACING, Direction.byId(code % 16)) .with(StairsBlock.HALF, ( hitX >= 16)?BlockHalf.TOP : BlockHalf.BOTTOM); } return null; }
Example #23
Source File: HallowedTreasureChestBlock.java From the-hallow with MIT License | 4 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()); }
Example #24
Source File: BlockWrapper.java From Sandbox with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean canReplace(BlockState blockState_1, ItemPlacementContext itemPlacementContext_1) { return block.canReplace((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1); }
Example #25
Source File: BlockWrapper.java From Sandbox with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean canReplace(BlockState blockState_1, ItemPlacementContext itemPlacementContext_1) { return block.canReplace((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1); }
Example #26
Source File: AbstractHorizontalDirectionalBlock.java From Galacticraft-Rewoven with MIT License | 4 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite()); }
Example #27
Source File: BlockRotator.java From fabric-carpet with MIT License | 4 votes |
public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { //actual alternative block placement code // if (true) throw new UnsupportedOperationException("Alternative Block Placement / client controlled / is not implemnted"); Direction facing; Vec3d vec3d = context.getHitPos(); float hitX = (float) vec3d.x; if (hitX<2) // vanilla 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? // PlayerEntity placer = context.getPlayer(); BlockPos pos = context.getBlockPos(); World world = context.getWorld(); if (block instanceof GlazedTerracottaBlock) { facing = Direction.byId(code); if(facing == Direction.UP || facing == Direction.DOWN) { facing = placer.getHorizontalFacing().getOpposite(); } return block.getDefaultState().with(HorizontalFacingBlock.FACING, facing); } else if (block instanceof ObserverBlock) { return block.getDefaultState() .with(FacingBlock.FACING, Direction.byId(code)) .with(ObserverBlock.POWERED, true); } else if (block instanceof RepeaterBlock) { facing = Direction.byId(code % 16); if(facing == Direction.UP || facing == Direction.DOWN) { facing = placer.getHorizontalFacing().getOpposite(); } return block.getDefaultState() .with(HorizontalFacingBlock.FACING, facing) .with(RepeaterBlock.DELAY, MathHelper.clamp(code / 16, 1, 4)) .with(RepeaterBlock.LOCKED, Boolean.FALSE); } else if (block instanceof TrapdoorBlock) { return block.getDefaultState() .with(TrapdoorBlock.FACING, Direction.byId(code % 16)) .with(TrapdoorBlock.OPEN, Boolean.FALSE) .with(TrapdoorBlock.HALF, (code >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM) .with(TrapdoorBlock.OPEN, world.isReceivingRedstonePower(pos)); } else if (block instanceof ComparatorBlock) { facing = Direction.byId(code % 16); if((facing == Direction.UP) || (facing == Direction.DOWN)) { facing = placer.getHorizontalFacing().getOpposite(); } ComparatorMode m = (hitX >= 16)?ComparatorMode.SUBTRACT: ComparatorMode.COMPARE; return block.getDefaultState() .with(HorizontalFacingBlock.FACING, facing) .with(ComparatorBlock.POWERED, Boolean.FALSE) .with(ComparatorBlock.MODE, m); } else if (block instanceof DispenserBlock) { return block.getDefaultState() .with(DispenserBlock.FACING, Direction.byId(code)) .with(DispenserBlock.TRIGGERED, Boolean.FALSE); } else if (block instanceof PistonBlock) { return block.getDefaultState() .with(FacingBlock.FACING, Direction.byId(code)) .with(PistonBlock.EXTENDED, Boolean.FALSE); } else if (block instanceof StairsBlock) { return block.getPlacementState(context)//worldIn, pos, facing, hitX, hitY, hitZ, meta, placer) .with(StairsBlock.FACING, Direction.byId(code % 16)) .with(StairsBlock.HALF, ( hitX >= 16)?BlockHalf.TOP : BlockHalf.BOTTOM); } return null; }
Example #28
Source File: CavernousVineBlock.java From Galacticraft-Rewoven with MIT License | 4 votes |
@Override public BlockState getPlacementState(ItemPlacementContext context) { FluidState fluidState = context.getWorld().getFluidState(context.getBlockPos()); return super.getPlacementState(context).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(VINES, VineTypes.VINE_0); }
Example #29
Source File: FluidLoggableBlock.java From Galacticraft-Rewoven with MIT License | votes |
BlockState getPlacementState(ItemPlacementContext context);