Search in sources :

Example 81 with BlockState

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

the class SetBlockToChunkSectionEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final LevelChunkSection chunkSection = pipeline.getAffectedSection();
    final int x = oldState.pos.getX() & 15;
    final int y = oldState.pos.getY() & 15;
    final int z = oldState.pos.getZ() & 15;
    final BlockState oldStateReturned = chunkSection.setBlockState(x, y, z, newState);
    if (oldStateReturned == newState) {
        return EffectResult.NULL_RETURN;
    }
    return EffectResult.NULL_PASS;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection)

Example 82 with BlockState

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

the class PortalHelper method generateNetherPortal.

// see Teleporter#createPortal
public static void generateNetherPortal(final ServerLevel world, final int x, final int y, final int z, final Direction.Axis axis, final boolean placePortalBlocks) {
    final BlockPos portalPos = new BlockPos(x, y, z);
    final Direction direction = Direction.get(Direction.AxisDirection.POSITIVE, axis);
    double d0 = -1.0D;
    BlockPos blockpos = null;
    double d1 = -1.0D;
    BlockPos blockpos1 = null;
    final WorldBorder worldborder = world.getWorldBorder();
    final int i = world.getHeight() - 1;
    final BlockPos.MutableBlockPos blockpos$mutable = portalPos.mutable();
    for (final BlockPos.MutableBlockPos blockpos$mutable1 : BlockPos.spiralAround(portalPos, 16, Direction.EAST, Direction.SOUTH)) {
        final int j = Math.min(i, world.getHeight(Heightmap.Types.MOTION_BLOCKING, blockpos$mutable1.getX(), blockpos$mutable1.getZ()));
        final int k = 1;
        if (worldborder.isWithinBounds(blockpos$mutable1) && worldborder.isWithinBounds(blockpos$mutable1.move(direction, 1))) {
            blockpos$mutable1.move(direction.getOpposite(), 1);
            for (int l = j; l >= 0; --l) {
                blockpos$mutable1.setY(l);
                if (world.isEmptyBlock(blockpos$mutable1)) {
                    final int i1;
                    for (i1 = l; l > 0 && world.isEmptyBlock(blockpos$mutable1.move(Direction.DOWN)); --l) {
                    }
                    if (l + 4 <= i) {
                        final int j1 = i1 - l;
                        if (j1 <= 0 || j1 >= 3) {
                            blockpos$mutable1.setY(l);
                            if (PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, 0)) {
                                final double d2 = portalPos.distSqr(blockpos$mutable1);
                                if (PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, -1) && PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, 1) && (d0 == -1.0D || d0 > d2)) {
                                    d0 = d2;
                                    blockpos = blockpos$mutable1.immutable();
                                }
                                if (d0 == -1.0D && (d1 == -1.0D || d1 > d2)) {
                                    d1 = d2;
                                    blockpos1 = blockpos$mutable1.immutable();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (d0 == -1.0D && d1 != -1.0D) {
        blockpos = blockpos1;
        d0 = d1;
    }
    if (d0 == -1.0D) {
        blockpos = (new BlockPos(portalPos.getX(), Mth.clamp(portalPos.getY(), 70, world.getHeight() - 10), portalPos.getZ())).immutable();
        final Direction direction1 = direction.getClockWise();
        if (!worldborder.isWithinBounds(blockpos)) {
            return;
        }
        for (int l1 = -1; l1 < 2; ++l1) {
            for (int k2 = 0; k2 < 2; ++k2) {
                for (int i3 = -1; i3 < 3; ++i3) {
                    final BlockState blockstate1 = i3 < 0 ? Blocks.OBSIDIAN.defaultBlockState() : Blocks.AIR.defaultBlockState();
                    blockpos$mutable.setWithOffset(blockpos, k2 * direction.getStepX() + l1 * direction1.getStepX(), i3, k2 * direction.getStepZ() + l1 * direction1.getStepZ());
                    world.setBlockAndUpdate(blockpos$mutable, blockstate1);
                }
            }
        }
    }
    for (int k1 = -1; k1 < 3; ++k1) {
        for (int i2 = -1; i2 < 4; ++i2) {
            if (k1 == -1 || k1 == 2 || i2 == -1 || i2 == 3) {
                blockpos$mutable.setWithOffset(blockpos, k1 * direction.getStepX(), i2, k1 * direction.getStepZ());
                world.setBlock(blockpos$mutable, Blocks.OBSIDIAN.defaultBlockState(), 3);
            }
        }
    }
    if (placePortalBlocks) {
        final BlockState blockstate = Blocks.NETHER_PORTAL.defaultBlockState().setValue(NetherPortalBlock.AXIS, axis);
        for (int j2 = 0; j2 < 2; ++j2) {
            for (int l2 = 0; l2 < 3; ++l2) {
                blockpos$mutable.setWithOffset(blockpos, j2 * direction.getStepX(), l2, j2 * direction.getStepZ());
                world.setBlock(blockpos$mutable, blockstate, 18);
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) WorldBorder(net.minecraft.world.level.border.WorldBorder) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 83 with BlockState

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

the class JukeboxBlockEntityMixin_API method insert.

@Override
public void insert(final ItemStack record) {
    final net.minecraft.world.item.ItemStack itemStack = ItemStackUtil.toNative(record);
    if (!(itemStack.getItem() instanceof RecordItem)) {
        return;
    }
    final BlockState block = this.level.getBlockState(this.shadow$getBlockPos());
    if (block.getBlock() == Blocks.JUKEBOX) {
        // Don't use BlockJukebox#insertRecord - it looses item data
        this.shadow$setRecord(itemStack);
        this.level.setBlock(this.shadow$getBlockPos(), block.setValue(JukeboxBlock.HAS_RECORD, true), Constants.BlockChangeFlags.NOTIFY_CLIENTS);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) RecordItem(net.minecraft.world.item.RecordItem)

Example 84 with BlockState

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

the class JukeboxBlockEntityMixin_API method eject.

@SuppressWarnings("deprecation")
@Override
public void eject() {
    final BlockState block = this.level.getBlockState(this.shadow$getBlockPos());
    if (block.getBlock() == Blocks.JUKEBOX) {
        ((JukeboxBlockAccessor) block.getBlock()).invoker$dropRecording(this.level, this.shadow$getBlockPos());
        this.level.setBlock(this.shadow$getBlockPos(), block.setValue(JukeboxBlock.HAS_RECORD, false), Constants.BlockChangeFlags.NOTIFY_CLIENTS);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) JukeboxBlockAccessor(org.spongepowered.common.accessor.world.level.block.JukeboxBlockAccessor)

Example 85 with BlockState

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

the class EntityMixin method impl$getEntityPositionInPotentialExitPortal.

/**
 * This is from Entity#findDimensionEntryPoint, for determining the destination position before
 * a portal is created (lambda in the return statement after getExitPortal)
 *
 * This is only fired if a portal exists, thus the blockstate checks are okay.
 */
private Vector3d impl$getEntityPositionInPotentialExitPortal(final BlockUtil.FoundRectangle result) {
    final BlockState blockstate = this.level.getBlockState(this.portalEntrancePos);
    final Direction.Axis direction$axis;
    final net.minecraft.world.phys.Vec3 vector3d;
    if (blockstate.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) {
        direction$axis = blockstate.getValue(BlockStateProperties.HORIZONTAL_AXIS);
        final BlockUtil.FoundRectangle teleportationrepositioner$result = BlockUtil.getLargestRectangleAround(this.portalEntrancePos, direction$axis, 21, Direction.Axis.Y, 21, (p_242276_2_) -> {
            return this.level.getBlockState(p_242276_2_) == blockstate;
        });
        vector3d = this.shadow$getRelativePortalPosition(direction$axis, teleportationrepositioner$result);
    } else {
        vector3d = new net.minecraft.world.phys.Vec3(0.5D, 0.0D, 0.0D);
    }
    return VecHelper.toVector3d(vector3d);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) BlockUtil(net.minecraft.BlockUtil) Direction(net.minecraft.core.Direction)

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