net.minecraft.util.shape.VoxelShape#net.minecraft.item.ItemPlacementContext源码实例Demo

下面列出了net.minecraft.util.shape.VoxelShape#net.minecraft.item.ItemPlacementContext 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Galacticraft-Rewoven   文件: AluminumWireBlock.java
@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;
}
 
源代码2 项目: multiconnect   文件: MixinBlockItem.java
@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;
                    }
                }
            }
        }
    }
}
 
源代码3 项目: Sandbox   文件: MixinBlockItem.java
@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));
    }
}
 
@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);
}
 
源代码5 项目: Galacticraft-Rewoven   文件: GratingBlock.java
@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);
}
 
源代码6 项目: Galacticraft-Rewoven   文件: FluidPipeBlock.java
@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;
}
 
源代码7 项目: Galacticraft-Rewoven   文件: Walkway.java
@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));
}
 
@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);
}
 
@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);
}
 
@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);
}
 
@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);
}
 
源代码12 项目: Galacticraft-Rewoven   文件: RefineryBlock.java
@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);
}
 
@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);
}
 
源代码14 项目: Galacticraft-Rewoven   文件: CoalGeneratorBlock.java
@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);
}
 
源代码15 项目: the-hallow   文件: TinyPumpkinBlock.java
@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;
}
 
@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);
}
 
@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());
}
 
源代码18 项目: fabric-carpet   文件: CarpetBlockMixin.java
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;
}
 
源代码19 项目: fabric-carpet   文件: HopperBlock_cactusMixin.java
@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();
}
 
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
    return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite());
}
 
源代码21 项目: Galacticraft-Rewoven   文件: CavernousVineBlock.java
@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);
}
 
源代码22 项目: the-hallow   文件: HallowedTreasureChestBlock.java
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
	return this.getDefaultState().with(FACING, context.getPlayerFacing().getOpposite());
}
 
源代码23 项目: the-hallow   文件: HallowedGateBlock.java
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
	return getDefaultState().with(FACING, context.getPlayerFacing().getOpposite());
}
 
源代码24 项目: the-hallow   文件: TombstoneBlock.java
@Override
public BlockState getPlacementState(ItemPlacementContext placementContext) {
	return this.getDefaultState().with(FACING, placementContext.getPlayerFacing().getOpposite());
}
 
源代码25 项目: carpet-extra   文件: BlockPlacer.java
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;
}
 
源代码26 项目: Sandbox   文件: BlockWrapper.java
@Override
public boolean canReplace(BlockState blockState_1, ItemPlacementContext itemPlacementContext_1) {
    return block.canReplace((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1);
}
 
源代码27 项目: Sandbox   文件: BlockWrapper.java
@Override
public boolean canReplace(BlockState blockState_1, ItemPlacementContext itemPlacementContext_1) {
    return block.canReplace((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1);
}
 
源代码28 项目: fabric-carpet   文件: BlockRotator.java
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;
}
 
源代码29 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
BlockState getPlacementState(ItemPlacementContext context);