Search in sources :

Example 86 with Axis

use of net.minecraft.core.Direction.Axis in project CreativeCore by CreativeMD.

the class BlockUpdateLevelSystem method blockChanged.

public void blockChanged(BlockPos pos) {
    BlockState state = level.getBlockState(pos);
    if (state.isAir()) {
        // Shrinking
        if (allBlocks.remove(pos) && edgePositions.remove(pos)) {
            for (int i = 0; i < Facing.values().length; i++) {
                Facing facing = Facing.values()[i];
                Axis axis = facing.axis.toVanilla();
                int bound = getBound(facing);
                if (bound == pos.get(axis)) {
                    List<BlockPos> remaining = new ArrayList<>();
                    for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
                        remaining.add(edge);
                    if (remaining.isEmpty()) {
                        int newBound = facing.positive ? Integer.MIN_VALUE : Integer.MAX_VALUE;
                        for (BlockPos scan : allBlocks) newBound = facing.positive ? Math.max(newBound, scan.get(axis)) : Math.min(newBound, scan.get(axis));
                        for (BlockPos scan : allBlocks) if (scan.get(axis) == newBound) {
                            remaining.add(scan);
                            edgePositions.add(scan);
                        }
                        setBound(facing, newBound);
                    }
                    levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
                }
            }
        }
    } else if (allBlocks.add(pos) && !isWithinBoundsNoEdge(pos)) {
        // Expanding
        for (int i = 0; i < Facing.values().length; i++) {
            Facing facing = Facing.values()[i];
            Axis axis = facing.axis.toVanilla();
            int bound = getBound(facing);
            if (bound == pos.get(axis)) {
                List<BlockPos> remaining = new ArrayList<>();
                edgePositions.add(pos);
                for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
                    remaining.add(edge);
                levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
            } else if (bound > pos.get(axis)) {
                for (Iterator<BlockPos> itr = edgePositions.iterator(); itr.hasNext(); ) {
                    BlockPos edge = itr.next();
                    if (edge.get(axis) == bound && !isEdgeExcept(edge, facing))
                        itr.remove();
                }
                edgePositions.add(pos);
                levelBoundListeners.forEach(x -> x.rescan(level, this, facing, new SingletonList<>(pos), facing.positive ? bound + 1 : bound));
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Axis(net.minecraft.core.Direction.Axis) List(java.util.List) Facing(team.creative.creativecore.common.util.math.base.Facing) Iterator(java.util.Iterator) BlockPos(net.minecraft.core.BlockPos) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) BlockState(net.minecraft.world.level.block.state.BlockState) CreativeLevel(team.creative.creativecore.common.level.CreativeLevel) LevelBoundsListener(team.creative.creativecore.common.level.listener.LevelBoundsListener) ArrayList(java.util.ArrayList) Facing(team.creative.creativecore.common.util.math.base.Facing) BlockState(net.minecraft.world.level.block.state.BlockState) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) List(java.util.List) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) ArrayList(java.util.ArrayList) Axis(net.minecraft.core.Direction.Axis)

Example 87 with Axis

use of net.minecraft.core.Direction.Axis in project EdenRing by paulevsGitch.

the class PulseTreeBlock method getStateForPlacement.

@Override
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
    BlockState blockState = this.defaultBlockState();
    Axis axis = ctx.getClickedFace().getAxis();
    switch(axis) {
        case X:
            return blockState.setValue(PULSE_TREE, PulseTreeState.EAST_WEST);
        case Z:
            return blockState.setValue(PULSE_TREE, PulseTreeState.NORTH_SOUTH);
    }
    return blockState;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Axis(net.minecraft.core.Direction.Axis)

Aggregations

Axis (net.minecraft.core.Direction.Axis)87 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)37 AxisDirection (net.minecraft.core.Direction.AxisDirection)24 Vec3 (net.minecraft.world.phys.Vec3)14 Level (net.minecraft.world.level.Level)13 IRotate (com.simibubi.create.content.contraptions.base.IRotate)9 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)7 Block (net.minecraft.world.level.block.Block)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)6 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)5 Player (net.minecraft.world.entity.player.Player)5 HashSet (java.util.HashSet)4 ItemStack (net.minecraft.world.item.ItemStack)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 Part (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part)3 ArrayList (java.util.ArrayList)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)3