Java Code Examples for net.minecraft.server.world.ServerWorld#getBlockState()

The following examples show how to use net.minecraft.server.world.ServerWorld#getBlockState() . 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: CavernousVineBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
    for (int y2 = pos.getY() - 1; y2 >= pos.getY() - 2; y2--) {

        BlockPos pos1 = new BlockPos(pos.getX(), y2, pos.getZ());
        BlockState blockState = world.getBlockState(pos1);

        if (!blockState.isAir()) {
            return;
        }
    }
    world.setBlockState(pos.down(), this.getStateFromMeta(getVineLength(world, pos)), 2);
    world.updateNeighbors(pos, state.getBlock());
}
 
Example 2
Source File: DeceasedGrassBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void grow(ServerWorld world, Random random, BlockPos blockPos, BlockState blockState) {
	BlockPos upPos = blockPos.up();
	BlockState grassBlock = HallowedBlocks.DECEASED_GRASS_BLOCK.getDefaultState();
	
	label48:
	for (int i = 0; i < 128; ++i) {
		BlockPos randomPos = upPos;
		
		for (int j = 0; j < i / 16; ++j) {
			randomPos = randomPos.add(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, random.nextInt(3) - 1);
			if (world.getBlockState(randomPos.down()).getBlock() != this || world.getBlockState(randomPos).isFullCube(world, randomPos)) {
				continue label48;
			}
		}
		
		BlockState randomBlockState = world.getBlockState(randomPos);
		if (randomBlockState.getBlock() == grassBlock.getBlock() && random.nextInt(10) == 0) {
			((Fertilizable) grassBlock.getBlock()).grow(world, random, randomPos, randomBlockState);
		}
		
		if (randomBlockState.isAir()) {
			BlockState stateToPlace;
			if (random.nextInt(8) == 0) {
				List<ConfiguredFeature<?, ?>> list = world.getBiomeAccess().getBiome(randomPos).getFlowerFeatures();
				if (list.isEmpty()) {
					continue;
				}
				stateToPlace = ((FlowerFeature) ((DecoratedFeatureConfig) (list.get(0)).config).feature.feature).getFlowerToPlace(random, randomPos, list.get(0).config);
			} else {
				stateToPlace = grassBlock;
			}
			
			if (stateToPlace.canPlaceAt(world, randomPos)) {
				world.setBlockState(randomPos, stateToPlace, 3);
			}
		}
	}
}
 
Example 3
Source File: FarmerVillagerTask_wartFarmMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "isSuitableTarget", at = @At("HEAD"), cancellable = true)
private void isValidSoulSand(BlockPos blockPos, ServerWorld serverWorld, CallbackInfoReturnable<Boolean> cir)
{
    if (isFarmingCleric)
    {
        BlockState blockState = serverWorld.getBlockState(blockPos);
        Block block = blockState.getBlock();
        Block block2 = serverWorld.getBlockState(blockPos.down()).getBlock(); // down()
        cir.setReturnValue(
                block == Blocks.NETHER_WART && blockState.get(NetherWartBlock.AGE)== 3 && ableToPickUpSeed ||
                        blockState.isAir() && block2 == Blocks.SOUL_SAND && ableToPlant);

    }
}
 
Example 4
Source File: FarmerVillagerTask_wartFarmMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "keepRunning", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;",
        ordinal = 0
) )
private BlockState getWartBlockState(ServerWorld serverWorld, BlockPos pos)
{
    BlockState state = serverWorld.getBlockState(pos);
    if (isFarmingCleric && state.getBlock() == Blocks.NETHER_WART && state.get(NetherWartBlock.AGE) == 3)
    {
        return ((CropBlock)Blocks.WHEAT).withAge(((CropBlock)Blocks.WHEAT).getMaxAge());
    }
    return state;
}
 
Example 5
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();
    }
}