use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.
the class EnokiCapBlock method isValidPosition.
@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
BlockState upState = world.getBlockState(pos.up());
Block upBlock = upState.getBlock();
if (upBlock != NetherExBlocks.ENOKI_MUSHROOM_STEM.get() && upBlock != NetherExBlocks.LIVELY_NETHERRACK.get()) {
if (!upState.isAir(world, pos.up())) {
return false;
} else {
boolean foundStem = false;
for (Direction direction : Direction.Plane.HORIZONTAL) {
BlockState offsetState = world.getBlockState(pos.offset(direction));
if (offsetState.getBlock() == NetherExBlocks.ENOKI_MUSHROOM_STEM.get()) {
if (foundStem) {
return false;
}
foundStem = true;
} else if (!offsetState.isAir(world, pos.offset(direction))) {
return false;
}
}
return foundStem;
}
} else {
return true;
}
}
use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.
the class EnokiCapBlock method tick.
@Override
public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!state.isValidPosition(world, pos)) {
world.destroyBlock(pos, true);
} else {
BlockPos downPos = pos.down();
if (world.isAirBlock(downPos) && downPos.getY() < world.getDimension().getHeight()) {
int age = state.get(AGE);
if (age < 5 && ForgeHooks.onCropsGrowPre(world, downPos, state, true)) {
boolean validPosition = false;
boolean foundNetherrack = false;
BlockState upState = world.getBlockState(pos.up());
Block upBlock = upState.getBlock();
if (upBlock == NetherExBlocks.LIVELY_NETHERRACK.get()) {
validPosition = true;
} else if (upBlock == NetherExBlocks.ENOKI_MUSHROOM_STEM.get()) {
int height = 1;
for (int k = 0; k < 4; k++) {
Block block1 = world.getBlockState(pos.up(height + 1)).getBlock();
if (block1 != NetherExBlocks.ENOKI_MUSHROOM_STEM.get()) {
if (block1 == NetherExBlocks.LIVELY_NETHERRACK.get()) {
foundNetherrack = true;
}
break;
}
height++;
}
if (height < 2 || height <= random.nextInt(foundNetherrack ? 5 : 4)) {
validPosition = true;
}
} else if (upState.isAir(world, pos.down())) {
validPosition = true;
}
if (validPosition && areAllNeighborsEmpty(world, downPos, null) && world.isAirBlock(pos.up(2))) {
world.setBlockState(pos, ((EnokiStemBlock) NetherExBlocks.ENOKI_MUSHROOM_STEM.get()).makeConnections(world, pos), 2);
this.placeCap(world, downPos, age);
} else if (age < 4) {
int randomHeight = random.nextInt(4);
if (foundNetherrack) {
randomHeight++;
}
boolean placedCap = false;
for (int i1 = 0; i1 < randomHeight; ++i1) {
Direction direction = Direction.Plane.HORIZONTAL.random(random);
BlockPos offsetPos = pos.offset(direction);
if (world.isAirBlock(offsetPos) && world.isAirBlock(offsetPos.down()) && areAllNeighborsEmpty(world, offsetPos, direction.getOpposite())) {
this.placeCap(world, offsetPos, age + 1);
placedCap = true;
}
}
if (placedCap) {
world.setBlockState(pos, ((EnokiStemBlock) NetherExBlocks.ENOKI_MUSHROOM_STEM.get()).makeConnections(world, pos), 2);
} else {
this.placeDeadCap(world, pos);
}
} else {
this.placeDeadCap(world, pos);
}
ForgeHooks.onCropsGrowPost(world, pos, state);
}
}
}
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class AgriApiConnector method getSoil.
@Nonnull
@Override
public Optional<IAgriSoil> getSoil(IBlockReader world, BlockPos pos) {
BlockState state = world.getBlockState(pos);
IAgriSoilRegistry registry = this.connectSoilRegistry();
Optional<IAgriSoil> soil = registry.valueOf(state);
return soil.isPresent() ? soil : registry.getProvider(state.getBlock()).getSoil(world, pos, state);
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class BlockSprinkler method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos().up();
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockIrrigationChannelAbstract) {
return this.getDefaultState();
}
return null;
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class TileEntitySprinkler method irrigateColumn.
/**
* This method will search through a vertical column of positions, starting from the top. It
* will stop searching any lower once it hits anything other than air or plants. Any plant found
* has an independent chance for a growth tick. That percentage is controlled by
* AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
* if it isn't already. The lowest position is special: a plant this far away is not helped.
* Only farmland is currently.
*/
@SuppressWarnings("deprecation")
protected void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
if (this.getWorld() == null || !(this.getWorld() instanceof ServerWorld)) {
return;
}
for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
BlockPos target = new BlockPos(targetX, targetY, targetZ);
BlockState state = this.getWorld().getBlockState(target);
Block block = state.getBlock();
// Option A: Skip empty/air blocks.
if (block.isAir(state, this.getWorld(), target)) {
continue;
}
// Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
if (this.getRandom().nextDouble() < AgriCraft.instance.getConfig().sprinkleGrowthChance()) {
block.randomTick(state, (ServerWorld) this.getWorld(), target, this.getRandom());
}
continue;
}
// Option C: Dry farmland gets set as moist.
if (block instanceof FarmlandBlock) {
if (state.get(FarmlandBlock.MOISTURE) < 7) {
this.getWorld().setBlockState(target, state.with(FarmlandBlock.MOISTURE, 7), 2);
}
// Explicitly expresses the intent to stop.
break;
}
// Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
break;
}
}
Aggregations