Java Code Examples for net.minecraft.block.Blocks#CHEST

The following examples show how to use net.minecraft.block.Blocks#CHEST . 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: MixinBlockItem.java    From multiconnect with MIT License 6 votes vote down vote up
@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 2
Source File: PistonHandler_movableTEMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
/**
 * Handles blocks besides the slimeblock that are sticky. Currently only supports blocks that are sticky on one side.
 * Currently the only additional sticky block is the double chest, which sticks to its other chest half.
 * @param blockPos_1 location of a block that moves and needs to stick other blocks to it
 * @author 2No2Name
 */
private boolean stickToStickySide(BlockPos blockPos_1){
    if(!CarpetSettings.movableBlockEntities)
        return true;

    BlockState blockState_1 = this.world.getBlockState(blockPos_1);
    Block block = blockState_1.getBlock();
    Direction stickyDirection  = null;
    if(block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
        stickyDirection = getDirectionToOtherChestHalf(blockState_1);
    }

    //example how you could make sticky pistons have a sticky side:
    //else if(block == Blocks.STICKY_PISTON){
    //    stickyDirection = blockState_1.get(FacingBlock.FACING);
    //}

    return stickyDirection == null || this.tryMove(blockPos_1.offset(stickyDirection), stickyDirection);
}
 
Example 3
Source File: CrashChestHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	if(!MC.player.inventory.getArmorStack(0).isEmpty())
	{
		ChatUtils.error("Please clear your shoes slot.");
		setEnabled(false);
		return;
	}
	
	// generate item
	ItemStack stack = new ItemStack(Blocks.CHEST);
	CompoundTag nbtCompound = new CompoundTag();
	ListTag nbtList = new ListTag();
	for(int i = 0; i < 40000; i++)
		nbtList.add(new ListTag());
	nbtCompound.put("www.wurstclient.net", nbtList);
	stack.setTag(nbtCompound);
	stack.setCustomName(new LiteralText("Copy Me"));
	
	// give item
	MC.player.inventory.armor.set(0, stack);
	ChatUtils.message("Item has been placed in your shoes slot.");
	setEnabled(false);
}
 
Example 4
Source File: PistonHandler_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
/**
 * Returns true if there is a modification making this blockState sticky on the given face. Vanilla stickyness of SLIME_BLOCK is not affected.
 * @param blockState BlockState to determine the stickyness of
 * @param direction Direction in which the stickyness is to be found
 * @return boolean whether block is not SLIME_BLOCK and is sticky in the given direction
 * @author 2No2Name
 */
private boolean isStickyOnSide(BlockState blockState, Direction direction) {
    Block block = blockState.getBlock();
    if(block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST)
        //Make chests be sticky on the side to
        return getDirectionToOtherChestHalf(blockState) == direction;

    //example how you could make sticky pistons have a sticky side:
    //if(block == Blocks.STICKY_PISTON)
    //    return blockState.get(FacingBlock.FACING) == direction.getOpposite();
    return false;
}