Search in sources :

Example 41 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class TikiTorchBlock method playerDestroy.

@Override
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
    TorchSection section = state.getValue(SECTION);
    BlockPos base = pos.below(section.height);
    for (TorchSection otherSection : TorchSection.values()) {
        BlockPos pos2 = base.above(otherSection.height);
        BlockState state2 = world.getBlockState(pos2);
        if (state2.getBlock() == this && state2.getValue(SECTION) == otherSection) {
            super.playerDestroy(world, player, pos2, state2, te, stack);
            world.setBlock(pos2, world.getFluidState(pos2).createLegacyBlock(), world.isClientSide ? 11 : 3);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos)

Example 42 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class HugePlantBlock method placeAt.

public void placeAt(LevelAccessor world, BlockPos pos, int flags) {
    Shape shape = Shape.fromSeed(this, pos);
    for (BlockPos plantPos : shape) {
        BlockState plantState = shape.blockAt(plantPos);
        world.setBlock(plantPos, plantState, flags);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos)

Example 43 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class HugePlantBlock method setPlacedBy.

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
    Shape shape = Shape.fromSeed(this, pos);
    for (BlockPos plantPos : shape) {
        if (!plantPos.equals(pos)) {
            BlockState plantState = shape.blockAt(plantPos);
            world.setBlock(plantPos, plantState, Constants.BlockFlags.DEFAULT);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos)

Example 44 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class JigarbovTorchPlacement method onPlaceBlock.

@SubscribeEvent
public static void onPlaceBlock(BlockEvent.EntityPlaceEvent event) {
    BlockState placedState = event.getPlacedBlock();
    Block placedBlock = placedState.getBlock();
    if (placedBlock == Blocks.REDSTONE_WALL_TORCH) {
        RegistryObject<RedstoneWallTorchBlock> jigarbovTorchBlock = getJigarbovTorchFor(event.getPlacedAgainst().getBlock());
        if (jigarbovTorchBlock != null) {
            BlockState jigarbovTorch = jigarbovTorchBlock.get().defaultBlockState();
            jigarbovTorch = copyPropertiesTo(jigarbovTorch, placedState);
            event.getWorld().setBlock(event.getPos(), jigarbovTorch, Block.UPDATE_ALL);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) RedstoneWallTorchBlock(net.minecraft.world.level.block.RedstoneWallTorchBlock) Block(net.minecraft.world.level.block.Block) RedstoneWallTorchBlock(net.minecraft.world.level.block.RedstoneWallTorchBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 45 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class PineappleBlock method tick.

@Override
public void tick(final BlockState state, final ServerLevel world, final BlockPos pos, final Random random) {
    if (pos.getY() > world.getMaxBuildHeight() - 2) {
        return;
    }
    // Current metadata
    int growth = state.getValue(STAGE);
    if (state.getBlock() == this && growth <= TOTAL_GROW_TICKS && world.isEmptyBlock(pos.above()) && state.getValue(HALF) == DoubleBlockHalf.LOWER) {
        if (growth >= TOTAL_GROW_TICKS - 1) {
            // Set current state
            BlockState growthState = state.setValue(STAGE, TOTAL_GROW_TICKS);
            world.setBlock(pos, growthState, Constants.BlockFlags.DEFAULT | Constants.BlockFlags.NO_RERENDER);
            // Place actual pineapple plant above stem
            BlockState fullGrowth = growthState.setValue(HALF, DoubleBlockHalf.UPPER);
            world.setBlock(pos.above(), fullGrowth, Constants.BlockFlags.DEFAULT);
        } else {
            BlockState growthState = state.setValue(STAGE, growth + 1);
            world.setBlock(pos, growthState, Constants.BlockFlags.DEFAULT | Constants.BlockFlags.NO_RERENDER);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState)

Aggregations

BlockState (net.minecraft.world.level.block.state.BlockState)141 BlockPos (net.minecraft.core.BlockPos)75 Direction (net.minecraft.core.Direction)18 Level (net.minecraft.world.level.Level)14 Block (net.minecraft.world.level.block.Block)14 ArrayList (java.util.ArrayList)10 ServerLevel (net.minecraft.server.level.ServerLevel)10 SoundType (net.minecraft.world.level.block.SoundType)10 Vec3 (net.minecraft.world.phys.Vec3)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 Random (java.util.Random)8 ItemStack (net.minecraft.world.item.ItemStack)7 FluidState (net.minecraft.world.level.material.FluidState)7 AABB (net.minecraft.world.phys.AABB)6 BuildBlock (com.wuest.prefab.structures.base.BuildBlock)5 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 HashMap (java.util.HashMap)4