net.minecraft.block.HorizontalFacingBlock Java Examples

The following examples show how to use net.minecraft.block.HorizontalFacingBlock. 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: TinyPumpkinRenderer.java    From the-hallow with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
	builder.add(HorizontalFacingBlock.FACING);
	
	if (HallowedConfig.TinyPumpkin.waterloggable) {
		builder.add(Properties.WATERLOGGED);
	}
}
 
Example #3
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
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;
}
 
Example #4
Source File: InfusionPillarBlock.java    From the-hallow with MIT License 5 votes vote down vote up
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;
}
 
Example #5
Source File: InfusionAltarBlock.java    From the-hallow with MIT License 5 votes vote down vote up
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;
}
 
Example #6
Source File: TombstoneBlock.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
	builder.add(HorizontalFacingBlock.FACING);
	builder.add(Properties.AGE_1);
}
 
Example #7
Source File: BlockPlacer.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 #8
Source File: BlockRotator.java    From fabric-carpet with MIT License 4 votes vote down vote up
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 #9
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 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);
}