net.minecraft.block.FallingBlock Java Examples

The following examples show how to use net.minecraft.block.FallingBlock. 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: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private boolean equipSolidBlock(BlockPos pos)
{
	for(int slot = 0; slot < 9; slot++)
	{
		// filter out non-block items
		ItemStack stack = MC.player.inventory.getStack(slot);
		if(stack.isEmpty() || !(stack.getItem() instanceof BlockItem))
			continue;
		
		Block block = Block.getBlockFromItem(stack.getItem());
		
		// filter out non-solid blocks
		BlockState state = block.getDefaultState();
		if(!state.isFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN))
			continue;
		
		// filter out blocks that would fall
		if(block instanceof FallingBlock && FallingBlock
			.canFallThrough(BlockUtils.getState(pos.down())))
			continue;
		
		MC.player.inventory.selectedSlot = slot;
		return true;
	}
	
	return false;
}
 
Example #2
Source File: MixinFallingBlockEntity.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FallingBlock;onLanding(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V"))
public void onLand(FallingBlock block, World world_1, BlockPos blockPos_1, BlockState blockState_1, BlockState blockState_2) {
    EventDispatcher.publish(new BlockEvent.Fall(
            (org.sandboxpowered.sandbox.api.world.World) world_1,
            WrappingUtil.convert(blockPos_1),
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            fallDistance));
    block.onLanding(world_1, blockPos_1, blockState_1, blockState_2);
}
 
Example #3
Source File: ScaffoldWalkHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onUpdate()
{
	BlockPos belowPlayer = new BlockPos(MC.player.getPos()).down();
	
	// check if block is already placed
	if(!BlockUtils.getState(belowPlayer).getMaterial().isReplaceable())
		return;
	
	// search blocks in hotbar
	int newSlot = -1;
	for(int i = 0; i < 9; i++)
	{
		// filter out non-block items
		ItemStack stack = MC.player.inventory.getStack(i);
		if(stack.isEmpty() || !(stack.getItem() instanceof BlockItem))
			continue;
		
		// filter out non-solid blocks
		Block block = Block.getBlockFromItem(stack.getItem());
		BlockState state = block.getDefaultState();
		if(!state.isFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN))
			continue;
		
		// filter out blocks that would fall
		if(block instanceof FallingBlock && FallingBlock
			.canFallThrough(BlockUtils.getState(belowPlayer.down())))
			continue;
		
		newSlot = i;
		break;
	}
	
	// check if any blocks were found
	if(newSlot == -1)
		return;
	
	// set slot
	int oldSlot = MC.player.inventory.selectedSlot;
	MC.player.inventory.selectedSlot = newSlot;
	
	placeBlock(belowPlayer);
	
	// reset slot
	MC.player.inventory.selectedSlot = oldSlot;
}
 
Example #4
Source File: FallingBlockMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true)
private void onTryStartFalling(BlockState blockState_1, ServerWorld serverWorld_1, BlockPos blockPos_1, Random random_1, CallbackInfo ci)
{
    if (CarpetExtraSettings.dragonEggBedrockBreaking && (FallingBlock)(Object)this instanceof DragonEggBlock)
    {
        if (canFallThrough(serverWorld_1.getBlockState(blockPos_1.down(1))) && blockPos_1.getY() >= 0)
        {
            if (!DragonEggBedrockBreaking.fallInstantly &&
                    serverWorld_1.getChunkManager().shouldTickChunk(new ChunkPos(blockPos_1)))
            {
                if (!serverWorld_1.isClient)
                {
                    FallingBlockEntity fallingBlockEntity_1 = new FallingBlockEntity(serverWorld_1, (double) blockPos_1.getX() + 0.5D, (double) blockPos_1.getY(), (double) blockPos_1.getZ() + 0.5D, serverWorld_1.getBlockState(blockPos_1));
                    this.configureFallingBlockEntity(fallingBlockEntity_1);
                    serverWorld_1.spawnEntity(fallingBlockEntity_1);
                }
            }
            else
            {
                if (serverWorld_1.getBlockState(blockPos_1).getBlock() == this)
                {
                    serverWorld_1.removeBlock(blockPos_1, false);
                }

                BlockPos blockPos;
                
                int minY = CarpetExtraSettings.y0DragonEggBedrockBreaking ? -1 : 0;
                
                for (blockPos = blockPos_1.down(1); canFallThrough(serverWorld_1.getBlockState(blockPos)) && blockPos.getY() > minY; blockPos = blockPos.down(1))
                {
                    ;
                }
                
                if (blockPos.getY() > minY)
                {
                    serverWorld_1.setBlockState(blockPos, this.getDefaultState());
                }
            }
        }
        ci.cancel();
    }
}