net.minecraft.util.math.Direction#DOWN源码实例Demo

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

源代码1 项目: fabric-carpet   文件: BlockRotator.java
private static Direction rotateClockwise(Direction direction, Direction.Axis direction$Axis_1) {
    switch(direction$Axis_1) {
        case X:
            if (direction != Direction.WEST && direction != Direction.EAST) {
                return rotateXClockwise(direction);
            }

            return direction;
        case Y:
            if (direction != Direction.UP && direction != Direction.DOWN) {
                return rotateYClockwise(direction);
            }

            return direction;
        case Z:
            if (direction != Direction.NORTH && direction != Direction.SOUTH) {
                return rotateZClockwise(direction);
            }

            return direction;
        default:
            throw new IllegalStateException("Unable to get CW facing for axis " + direction$Axis_1);
    }
}
 
源代码2 项目: fabric-carpet   文件: BlockRotator.java
private static Direction rotateXClockwise(Direction dir) {
    switch(dir) {
        case NORTH:
            return Direction.DOWN;
        case EAST:
        case WEST:
        default:
            throw new IllegalStateException("Unable to get X-rotated facing of " + dir);
        case SOUTH:
            return Direction.UP;
        case UP:
            return Direction.NORTH;
        case DOWN:
            return Direction.SOUTH;
    }
}
 
源代码3 项目: fabric-carpet   文件: BlockValue.java
@Override
public Direction[] getPlacementDirections() {
    switch(this.facing) {
        case DOWN:
        default:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
        case UP:
            return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
        case NORTH:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
        case SOUTH:
            return new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
        case WEST:
            return new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
        case EAST:
            return new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
    }
}
 
源代码4 项目: 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);
}
 
源代码5 项目: the-hallow   文件: WitchWaterBubbleColumnBlock.java
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction dir, BlockState state2, IWorld world, BlockPos pos, BlockPos pos2) {
	if (!state.canPlaceAt(world, pos)) {
		return HallowedBlocks.WITCH_WATER_BLOCK.getDefaultState();
	} else {
		if (dir == Direction.DOWN) {
			world.setBlockState(pos, HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN.getDefaultState().with(DRAG, calculateDrag(world, pos2)), 2);
		} else if (dir == Direction.UP && state2.getBlock() != HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN && isStillWater(world, pos2)) {
			world.getBlockTickScheduler().schedule(pos, this, this.getTickRate(world));
		}
		world.getFluidTickScheduler().schedule(pos, HallowedFluids.WITCH_WATER, HallowedFluids.WITCH_WATER.getTickRate(world));
		return super.getStateForNeighborUpdate(state, dir, state2, world, pos, pos2);
	}
}
 
private Inventory getOutputInventory() {
    Vec3d offsetToInventory = getBlockBelowCartOffset();
    //The visual rotation point of the minecart is roughly 0.5 above its feet (determined visually ingame)
    //Search 0.5 Blocks below the feet for an inventory
    Inventory inv =  HopperBlockEntity.getInventoryAt(this.world, this.getX() + offsetToInventory.x, this.getY() + 0.5 + offsetToInventory.y, this.getZ() + offsetToInventory.z);

    //There is probably a way nicer way to determine the access side of the target inventory
    if(inv instanceof BlockEntity){
        BlockPos pos = ((BlockEntity) inv).getPos();
        if(pos.getY() < MathHelper.floor(this.getY()))
            outputDirection = Direction.DOWN;
        else if(pos.getX() > MathHelper.floor(this.getX()))
            outputDirection = Direction.EAST;
        else if(pos.getX() < MathHelper.floor(this.getX()))
            outputDirection = Direction.WEST;
        else if(pos.getZ() > MathHelper.floor(this.getZ()))
            outputDirection = Direction.SOUTH;
        else if(pos.getZ() < MathHelper.floor(this.getZ()))
            outputDirection = Direction.NORTH;
        else outputDirection = Direction.DOWN;
    }else
        outputDirection = Direction.DOWN;



    return inv;
}
 
源代码7 项目: fabric-carpet   文件: BlockRotator.java
private static Direction rotateZClockwise(Direction dir) {
    switch(dir) {
        case EAST:
            return Direction.DOWN;
        case SOUTH:
        default:
            throw new IllegalStateException("Unable to get Z-rotated facing of " + dir);
        case WEST:
            return Direction.UP;
        case UP:
            return Direction.EAST;
        case DOWN:
            return Direction.WEST;
    }
}
 
源代码8 项目: Galacticraft-Rewoven   文件: CrudeOilFluid.java
@Override
public boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
    return direction == Direction.DOWN && !fluid.matchesType(GalacticraftFluids.CRUDE_OIL);
}
 
源代码9 项目: Galacticraft-Rewoven   文件: FuelFluid.java
@Override
public boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
    return direction == Direction.DOWN && !fluid.matchesType(GalacticraftFluids.FUEL);
}
 
源代码10 项目: the-hallow   文件: WitchWaterFluid.java
@Override
public boolean method_15777(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
	return direction == Direction.DOWN && !fluid.matches(HallowedTags.Fluids.WITCH_WATER);
}
 
源代码11 项目: the-hallow   文件: BloodFluid.java
@Override
public boolean method_15777(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
	return direction == Direction.DOWN && !fluid.matches(HallowedTags.Fluids.BLOOD);
}
 
源代码12 项目: the-hallow   文件: PumpkinPieBlock.java
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState state2, IWorld iWorld, BlockPos pos, BlockPos pos2) {
	return direction == Direction.DOWN && !state.canPlaceAt(iWorld, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, state2, iWorld, pos, pos2);
}
 
源代码13 项目: 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;
}
 
源代码14 项目: Sandbox   文件: FluidWrapper.java
@Override
protected boolean method_15777(FluidState var1, BlockView var2, BlockPos var3, net.minecraft.fluid.Fluid var4, Direction var5) {
    return var5 == Direction.DOWN && !var4.matchesType(this);
}
 
源代码15 项目: 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;
}
 
源代码16 项目: fabric-carpet   文件: BlockRotator.java
public static boolean flip_block(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
{
    Block block = state.getBlock();
    BlockPos pos = hit.getBlockPos();
    Vec3d hitVec = hit.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
    Direction facing = hit.getSide();
    BlockState newState = null;
    if ( (block instanceof GlazedTerracottaBlock) || (block instanceof AbstractRedstoneGateBlock) || (block instanceof RailBlock) ||
         (block instanceof TrapdoorBlock)         || (block instanceof LeverBlock)         || (block instanceof FenceGateBlock))
    {
        newState = state.rotate(BlockRotation.CLOCKWISE_90);
    }
    else if ((block instanceof ObserverBlock) || (block instanceof EndRodBlock))
    {
        newState = state.with(FacingBlock.FACING, (Direction) state.get(FacingBlock.FACING).getOpposite());
    }
    else if (block instanceof DispenserBlock)
    {
        newState = state.with(DispenserBlock.FACING, state.get(DispenserBlock.FACING).getOpposite());
    }
    else if (block instanceof PistonBlock)
    {
        if (!(state.get(PistonBlock.EXTENDED)))
            newState = state.with(FacingBlock.FACING, state.get(FacingBlock.FACING).getOpposite());
    }
    else if (block instanceof SlabBlock)
    {
        if (((SlabBlock) block).hasSidedTransparency(state))
        {
            newState =  state.with(SlabBlock.TYPE, state.get(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
        }
    }
    else if (block instanceof HopperBlock)
    {
        if ((Direction)state.get(HopperBlock.FACING) != Direction.DOWN)
        {
            newState =  state.with(HopperBlock.FACING, state.get(HopperBlock.FACING).rotateYClockwise());
        }
    }
    else if (block instanceof StairsBlock)
    {
        //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.with(StairsBlock.HALF, state.get(StairsBlock.HALF) == BlockHalf.TOP ? BlockHalf.BOTTOM : BlockHalf.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(BlockRotation.COUNTERCLOCKWISE_90);
            }
            else
            {
                newState = state.rotate(BlockRotation.CLOCKWISE_90);
            }
        }
    }
    else
    {
        return false;
    }
    if (newState != null)
    {
        world.setBlockState(pos, newState, 2 | 1024);
        world.checkBlockRerender(pos, state, newState);
        return true;
    }
    return false;
}