Java Code Examples for net.minecraft.block.BlockState#isAir()

The following examples show how to use net.minecraft.block.BlockState#isAir() . 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: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 7 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
	BlockState state2 = world.getBlockState(pos.up());
	if (state2.isAir()) {
		entity.onBubbleColumnSurfaceCollision(state.get(DRAG));
		if (!world.isClient) {
			ServerWorld serverworld = (ServerWorld) world;
			
			for (int i = 0; i < 2; i++) {
				serverworld.spawnParticles(ParticleTypes.SPLASH, (float) pos.getX() + world.random.nextFloat(), pos.getY() + 1, (float) pos.getZ() + world.random.nextFloat(), 1, 0.0D, 0.0D, 0.0D, 1.0D);
				serverworld.spawnParticles(ParticleTypes.BUBBLE, (float) pos.getX() + world.random.nextFloat(), pos.getY() + 1, (float) pos.getZ() + world.random.nextFloat(), 1, 0.0D, 0.01D, 0.0D, 0.2D);
			}
		}
	} else {
		entity.onBubbleColumnCollision(state.get(DRAG));
	}
}
 
Example 2
Source File: OxygenCollectorBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private int collectOxygen(BlockPos center) {
    Optional<CelestialBodyType> celestialBodyType = CelestialBodyType.getByDimType(world.getRegistryKey());

    if (celestialBodyType.isPresent()) {
        if (celestialBodyType.get().getAtmosphere().getComposition().containsKey(AtmosphericGas.OXYGEN)) {
            int minX = center.getX() - 5;
            int minY = center.getY() - 5;
            int minZ = center.getZ() - 5;
            int maxX = center.getX() + 5;
            int maxY = center.getY() + 5;
            int maxZ = center.getZ() + 5;

            float leafBlocks = 0;

            for (BlockPos pos : BlockPos.iterate(minX, minY, minZ, maxX, maxY, maxZ)) {
                BlockState blockState = world.getBlockState(pos);
                if (blockState.isAir()) {
                    continue;
                }
                if (blockState.getBlock() instanceof LeavesBlock && !blockState.get(LeavesBlock.PERSISTENT)) {
                    leafBlocks++;
                } else if (blockState.getBlock() instanceof CropBlock) {
                    leafBlocks += 0.75F;
                }
            }

            if (leafBlocks < 2) return 0;

            double oxyCount = 20 * (leafBlocks / 14.0F);
            return (int) Math.ceil(oxyCount) / 20; //every tick
        } else {
            return 183 / 20;
        }
    } else {
        return 183 / 20;
    }
}
 
Example 3
Source File: BaseFluidMixin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Redirect(method = "onScheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean onScheduledTickGC(World world, BlockPos pos, BlockState state, int flags) {
    if (world.getBlockState(pos).getBlock() instanceof FluidDrainable && world.getBlockState(pos).getBlock() instanceof FluidFillable) {
        if (state.isAir()) {
            ((FluidDrainable) world.getBlockState(pos).getBlock()).tryDrainFluid(world, pos, world.getBlockState(pos));
            return true;
        } else {
            ((FluidDrainable) world.getBlockState(pos).getBlock()).tryDrainFluid(world, pos, world.getBlockState(pos));
            ((FluidFillable) world.getBlockState(pos).getBlock()).tryFillWithFluid(world, pos, world.getBlockState(pos), state.getFluidState());
            return true;
        }
    }
    return world.setBlockState(pos, state, flags);
}
 
Example 4
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 5
Source File: MoonSurfaceBuilder.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, int seaLevel, long seed, TernarySurfaceConfig ternarySurfaceConfig) {
    BlockState blockState = ternarySurfaceConfig.getTopMaterial();
    BlockState blockState2 = ternarySurfaceConfig.getUnderMaterial();
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    int i = -1;
    int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D);
    int k = x & 15;
    int l = z & 15;

    for (int m = height; m >= 0; --m) {
        mutable.set(k, m, l);
        BlockState blockState3 = chunk.getBlockState(mutable);
        if (blockState3.isAir()) {
            i = -1;
        } else if (blockState3.isOf(defaultBlock.getBlock())) {
            if (i == -1) {
                if (j <= 0) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = defaultBlock;
                } else if (m >= seaLevel - 4 && m <= seaLevel + 1) {
                    blockState = ternarySurfaceConfig.getTopMaterial();
                    blockState2 = ternarySurfaceConfig.getUnderMaterial();
                }

                if (m < seaLevel && (blockState == null || blockState.isAir())) {
                    if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) {
                        blockState = Blocks.ICE.getDefaultState();
                    } else {
                        blockState = fluidBlock;
                    }

                    mutable.set(k, m, l);
                }

                i = j;
                if (m >= seaLevel - 1) {
                    chunk.setBlockState(mutable, blockState, false);
                } else if (m < seaLevel - 7 - j) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = defaultBlock;
                    chunk.setBlockState(mutable, ternarySurfaceConfig.getUnderwaterMaterial(), false);
                } else {
                    chunk.setBlockState(mutable, blockState2, false);
                }
            } else if (i > 0) {
                --i;
                chunk.setBlockState(mutable, blockState2, false);
                if (i == 0 && blockState2.isOf(GalacticraftBlocks.MOON_TURF) && j > 1) {
                    i = random.nextInt(4) + Math.max(0, m - 63);
                    blockState2 = GalacticraftBlocks.MOON_ROCK.getDefaultState();
                }
            }
        }
    }
}
 
Example 6
Source File: MultiBlockSurfaceBuilder.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
protected void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, MultiBlockSurfaceConfig multiBlockSurfaceConfig, int seaLevel) {
    BlockState blockState = multiBlockSurfaceConfig.getTopMaterial();
    BlockState blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    int i = -1;
    int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D);
    int k = x & 15;
    int l = z & 15;

    for (int m = height; m >= 0; --m) {
        mutable.set(k, m, l);
        BlockState blockState3 = chunk.getBlockState(mutable);
        if (blockState3.isAir()) {
            i = -1;
        } else if (blockState3.getBlock() == defaultBlock.getBlock()) {
            if (i == -1) {
                if (j <= 0) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
                } else if (m >= seaLevel - 4 && m <= seaLevel + 1) {
                    blockState = multiBlockSurfaceConfig.getTopMaterial();
                    blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
                }

                if (m < seaLevel && (blockState == null || blockState.isAir())) {
                    if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) {
                        blockState = Blocks.ICE.getDefaultState();
                    } else {
                        blockState = fluidBlock;
                    }

                    mutable.set(k, m, l);
                }

                i = j;
                if (m >= seaLevel - 1) {
                    chunk.setBlockState(mutable, blockState, false);
                } else if (m < seaLevel - 7 - j) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = multiBlockSurfaceConfig.getTopMaterial();
                    chunk.setBlockState(mutable, multiBlockSurfaceConfig.getUnderwaterMaterial(), false);
                } else {
                    chunk.setBlockState(mutable, blockState2, false);
                }
            } else if (i > 0) {
                --i;
                chunk.setBlockState(mutable, blockState2, false);
                if (i == 0 && blockState2.getBlock() == Blocks.SAND && j > 1) {
                    i = random.nextInt(4) + Math.max(0, m - 63);
                    blockState2 = blockState2.getBlock() == Blocks.RED_SAND ? Blocks.RED_SANDSTONE.getDefaultState() : Blocks.SANDSTONE.getDefaultState();
                }
            }
        }
    }
}
 
Example 7
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Override
boolean execute(ServerPlayerEntity player, Action action) {
    HitResult hit = getTarget(player);
    switch (hit.getType()) {
        case ENTITY: {
            EntityHitResult entityHit = (EntityHitResult) hit;
            player.attack(entityHit.getEntity());
            player.resetLastAttackedTicks();
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return true;
        }
        case BLOCK: {
            EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
            if (ap.blockHitDelay > 0)
            {
                ap.blockHitDelay--;
                return false;
            }
            BlockHitResult blockHit = (BlockHitResult) hit;
            BlockPos pos = blockHit.getBlockPos();
            Direction side = blockHit.getSide();
            // rather should be canNotMine
            if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false;
            if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
            {
                ap.currentBlock = null;
                return false;
            }
            BlockState state = player.world.getBlockState(pos);
            boolean blockBroken = false;
            if (player.interactionManager.getGameMode().isCreative())
            {
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                ap.blockHitDelay = 5;
                blockBroken = true;
            }
            else  if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
            {
                if (ap.currentBlock != null)
                {
                    player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.server.getWorldHeight());
                }
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                boolean notAir = !state.isAir();
                if (notAir && ap.curBlockDamageMP == 0)
                {
                    state.onBlockBreakStart(player.world, pos, player);
                }
                if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
                {
                    ap.currentBlock = null;
                    //instamine??
                    blockBroken = true;
                }
                else
                {
                    ap.currentBlock = pos;
                    ap.curBlockDamageMP = 0;
                }
            }
            else
            {
                ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos);
                if (ap.curBlockDamageMP >= 1)
                {
                    player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight());
                    ap.currentBlock = null;
                    ap.blockHitDelay = 5;
                    blockBroken = true;
                }
                player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));

            }
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return blockBroken;
        }
    }
    return false;
}