net.minecraft.util.DefaultedList#net.minecraft.block.HorizontalFacingBlock源码实例Demo

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

源代码1 项目: the-hallow   文件: TinyPumpkinRenderer.java
@Override
public void render(TinyPumpkinBlockEntity pumpkin, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
	ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
	
	matrixStack.push();
	matrixStack.translate(0.5, 0.275, 0.5);
	matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(360 - pumpkin.getCachedState().get(HorizontalFacingBlock.FACING).asRotation()));
	matrixStack.multiply(NINETY_DEG_X);
	matrixStack.scale(0.75f, 0.75f, 0.75f);
	
	matrixStack.push();
	matrixStack.translate(0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getLeftItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.push();
	matrixStack.translate(-0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getRightItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.pop();
}
 
源代码2 项目: the-hallow   文件: TinyPumpkinBlock.java
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
	builder.add(HorizontalFacingBlock.FACING);
	
	if (HallowedConfig.TinyPumpkin.waterloggable) {
		builder.add(Properties.WATERLOGGED);
	}
}
 
源代码3 项目: the-hallow   文件: TinyPumpkinBlockEntity.java
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
源代码4 项目: the-hallow   文件: InfusionPillarBlock.java
public InfusionAltarBlockEntity getAltar(World world, BlockPos blockPos) {
	for (Direction direction : HorizontalFacingBlock.FACING.getValues()) {
		BlockPos offsetPos = blockPos.offset(direction, 3);
		if (world.getBlockState(offsetPos).getBlock() == HallowedBlocks.INFUSION_ALTAR_BLOCK) {
			InfusionAltarBlockEntity altarEntity = (InfusionAltarBlockEntity) world.getBlockEntity(offsetPos);
			if (altarEntity != null) {
				return altarEntity;
			}
		}
	}
	return null;
}
 
源代码5 项目: the-hallow   文件: InfusionAltarBlock.java
public void getLinkedPillars(InfusionAltarBlockEntity altarEntity) {
	Map<BlockPos, InfusionPillarBlockEntity> pillars = new HashMap<BlockPos, InfusionPillarBlockEntity>();
	for (Direction direction : HorizontalFacingBlock.FACING.getValues()) {
		BlockPos offsetPos = altarEntity.getPos().offset(direction, 3);
		if (altarEntity.getWorld().getBlockState(offsetPos).getBlock() == HallowedBlocks.INFUSION_PILLAR_BLOCK) {
			InfusionPillarBlockEntity pillarEntity = (InfusionPillarBlockEntity) altarEntity.getWorld().getBlockEntity(offsetPos);
			if (pillarEntity != null) {
				pillars.put(offsetPos, pillarEntity);
			}
		}
	}
	altarEntity.linkedPillars = pillars;
}
 
源代码6 项目: the-hallow   文件: TombstoneBlock.java
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
	builder.add(HorizontalFacingBlock.FACING);
	builder.add(Properties.AGE_1);
}
 
源代码7 项目: 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;
}
 
源代码8 项目: 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;
}
 
源代码9 项目: patchwork-api   文件: IForgeBlock.java
/**
 * Returns the direction of the block. Same values that
 * are returned by {@link net.minecraft.block.FacingBlock}. Called every frame tick for every living entity. Be VERY fast.
 *
 * @param state The current state
 * @param world The current world
 * @param pos   Block position in world
 * @return Bed direction
 */
default Direction getBedDirection(BlockState state, CollisionView world, BlockPos pos) {
	return state.get(HorizontalFacingBlock.FACING);
}