Java Code Examples for net.minecraft.util.math.Vec3i#getY()

The following examples show how to use net.minecraft.util.math.Vec3i#getY() . 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: LitematicaBlockStateContainerFull.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static SpongeBlockstateConverterResults convertVarintByteArrayToPackedLongArray(Vec3i size, int bits, byte[] blockStates)
{
    int volume = size.getX() * size.getY() * size.getZ();
    LitematicaBitArray bitArray = new LitematicaBitArray(bits, volume);
    PacketBuffer buf = new PacketBuffer(Unpooled.wrappedBuffer(blockStates));
    long[] blockCounts = new long[1 << bits];

    for (int i = 0; i < volume; ++i)
    {
        int id = buf.readVarInt();
        bitArray.setAt(i, id);
        ++blockCounts[id];
    }

    return new SpongeBlockstateConverterResults(bitArray.getBackingLongArray(), blockCounts);
}
 
Example 2
Source File: GridPlacementManager.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
private HashMap<Vec3i, SchematicPlacement> createGridPlacementsForPoints(SchematicPlacement basePlacement, HashSet<Vec3i> gridPoints)
{
    HashMap<Vec3i, SchematicPlacement> placements = new HashMap<>();

    if (gridPoints.isEmpty() == false)
    {
        BlockPos baseOrigin = basePlacement.getOrigin();
        Vec3i size = basePlacement.getGridSettings().getSize();
        int sizeX = size.getX();
        int sizeY = size.getY();
        int sizeZ = size.getZ();

        for (Vec3i point : gridPoints)
        {
            SchematicPlacement placement = basePlacement.copyAsFullyLoaded(true);
            placement.setOrigin(baseOrigin.add(point.getX() * sizeX, point.getY() * sizeY, point.getZ() * sizeZ));
            placement.updateEnclosingBox();
            placements.put(point, placement);
            //System.out.printf("repeat placement @ %s [%d, %d, %d]\n", placement.getOrigin(), point.getX(), point.getY(), point.getZ());
        }
    }

    return placements;
}
 
Example 3
Source File: BlockAntCoveredCake.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a velocity vector for an ant particle that will spawn on the given face
 * @param face The face of the block that the particle spawns on
 * @param rand An RNG, generally the world's rand
 * @param vScale The factor to scale the velocity by (if vScale = 1D, velocity values will be between -0.5D and 0.5D)
 * @return A vec3D containing the (x,y,z) initial velocities of an ant particle
 */
public static Vec3d getParticleInitVelocityForFace(EnumFacing face, Random rand, double vScale)
{
	Vec3i faceVec = face.getDirectionVec();
	return new Vec3d(
			faceVec.getX() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale,
			faceVec.getY() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale,
			faceVec.getZ() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale);
}
 
Example 4
Source File: LitematicaBlockStateContainerBase.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected LitematicaBlockStateContainerBase(Vec3i size, int bits)
{
    this.size = size;
    this.sizeX = size.getX();
    this.sizeY = size.getY();
    this.sizeZ = size.getZ();
    this.totalVolume = (long) this.sizeX * (long) this.sizeY * (long) this.sizeZ;
    this.sizeLayer = (long) this.sizeX * (long) this.sizeZ;

    this.setBits(bits);
}
 
Example 5
Source File: GridSettings.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setDefaultSize(Vec3i size)
{
    this.defaultSize = size;

    if (size.getX() > this.size.getX() ||
        size.getY() > this.size.getY() ||
        size.getZ() > this.size.getZ())
    {
        int x = Math.max(size.getX(), this.size.getX());
        int y = Math.max(size.getY(), this.size.getY());
        int z = Math.max(size.getZ(), this.size.getZ());
        this.setSize(new Vec3i(x, y, z));
    }
}
 
Example 6
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int getCoordinate(Vec3i pos, CoordinateType type)
{
    switch (type)
    {
        case X: return pos.getX();
        case Y: return pos.getY();
        case Z: return pos.getZ();
    }

    return 0;
}
 
Example 7
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Vec3i getRelativeEndPositionFromAreaSize(Vec3i size)
{
    int x = size.getX();
    int y = size.getY();
    int z = size.getZ();

    x = x >= 0 ? x - 1 : x + 1;
    y = y >= 0 ? y - 1 : y + 1;
    z = z >= 0 ? z - 1 : z + 1;

    return new Vec3i(x, y, z);
}
 
Example 8
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Vec3i getAreaSizeFromRelativeEndPositionAbs(Vec3i posEndRelative)
{
    int x = posEndRelative.getX();
    int y = posEndRelative.getY();
    int z = posEndRelative.getZ();

    x = x >= 0 ? x + 1 : x - 1;
    y = y >= 0 ? y + 1 : y - 1;
    z = z >= 0 ? z + 1 : z - 1;

    return new Vec3i(Math.abs(x), Math.abs(y), Math.abs(z));
}
 
Example 9
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Vec3i getAreaSizeFromRelativeEndPosition(Vec3i posEndRelative)
{
    int x = posEndRelative.getX();
    int y = posEndRelative.getY();
    int z = posEndRelative.getZ();

    x = x >= 0 ? x + 1 : x - 1;
    y = y >= 0 ? y + 1 : y - 1;
    z = z >= 0 ? z + 1 : z - 1;

    return new Vec3i(x, y, z);
}
 
Example 10
Source File: RenderUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawBlockBoxEdgeBatchedLines(BlockPos pos, EnumFacing.Axis axis, int cornerIndex, Color4f color, BufferBuilder buffer)
{
    Vec3i offset = PositionUtils.getEdgeNeighborOffsets(axis, cornerIndex)[cornerIndex];

    double minX = pos.getX() + offset.getX();
    double minY = pos.getY() + offset.getY();
    double minZ = pos.getZ() + offset.getZ();
    double maxX = pos.getX() + offset.getX() + (axis == EnumFacing.Axis.X ? 1 : 0);
    double maxY = pos.getY() + offset.getY() + (axis == EnumFacing.Axis.Y ? 1 : 0);
    double maxZ = pos.getZ() + offset.getZ() + (axis == EnumFacing.Axis.Z ? 1 : 0);

    //System.out.printf("pos: %s, axis: %s, ind: %d\n", pos, axis, cornerIndex);
    buffer.pos(minX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex();
    buffer.pos(maxX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex();
}
 
Example 11
Source File: HolesModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    final Minecraft mc = Minecraft.getMinecraft();

    if (mc.player == null)
        return;

    this.holes.clear();

    final Vec3i playerPos = new Vec3i(mc.player.posX, mc.player.posY, mc.player.posZ);

    for (int x = playerPos.getX() - radius.getValue(); x < playerPos.getX() + radius.getValue(); x++) {
        for (int z = playerPos.getZ() - radius.getValue(); z < playerPos.getZ() + radius.getValue(); z++) {
            for (int y = playerPos.getY(); y > playerPos.getY() - 4; y--) {
                final BlockPos blockPos = new BlockPos(x, y, z);
                final IBlockState blockState = mc.world.getBlockState(blockPos);
                if (this.isBlockValid(blockState, blockPos)) {
                    final IBlockState downBlockState = mc.world.getBlockState(blockPos.down());
                    if (downBlockState.getBlock() == Blocks.AIR) {
                        final BlockPos downPos = blockPos.down();
                        if (this.isBlockValid(downBlockState, downPos)) {
                            this.holes.add(new Hole(downPos.getX(), downPos.getY(), downPos.getZ(), true));
                        }
                    } else {
                        this.holes.add(new Hole(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
                    }
                }
            }
        }
    }
}
 
Example 12
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean areAllCoordinatesAtLeast(Vec3i vec, int threshold)
{
    return vec.getX() >= threshold && vec.getY() >= threshold && vec.getZ() >= threshold;
}
 
Example 13
Source File: RenderChunkSchematicVbo.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void renderOverlayReducedEdges(BlockPos pos, OverlayType[][][] adjTypes, OverlayType typeSelf, Color4f overlayColor, BufferBuilder bufferOverlayOutlines)
{
    OverlayType[] neighborTypes = new OverlayType[4];
    Vec3i[] neighborPositions = new Vec3i[4];
    int lines = 0;

    for (EnumFacing.Axis axis : PositionUtils.AXES_ALL)
    {
        for (int corner = 0; corner < 4; ++corner)
        {
            Vec3i[] offsets = PositionUtils.getEdgeNeighborOffsets(axis, corner);
            int index = -1;
            boolean hasCurrent = false;

            // Find the position(s) around a given edge line that have the shared greatest rendering priority
            for (int i = 0; i < 4; ++i)
            {
                Vec3i offset = offsets[i];
                OverlayType type = adjTypes[offset.getX() + 1][offset.getY() + 1][offset.getZ() + 1];

                // type NONE
                if (type == OverlayType.NONE)
                {
                    continue;
                }

                // First entry, or sharing at least the current highest found priority
                if (index == -1 || type.getRenderPriority() >= neighborTypes[index - 1].getRenderPriority())
                {
                    // Actually a new highest priority, add it as the first entry and rewind the index
                    if (index < 0 || type.getRenderPriority() > neighborTypes[index - 1].getRenderPriority())
                    {
                        index = 0;
                    }
                    // else: Same priority as a previous entry, append this position

                    //System.out.printf("plop 0 axis: %s, corner: %d, i: %d, index: %d, type: %s\n", axis, corner, i, index, type);
                    neighborPositions[index] = new Vec3i(pos.getX() + offset.getX(), pos.getY() + offset.getY(), pos.getZ() + offset.getZ());
                    neighborTypes[index] = type;
                    // The self position is the first (offset = [0, 0, 0]) in the arrays
                    hasCurrent |= (i == 0);
                    ++index;
                }
            }

            //System.out.printf("plop 1 index: %d, pos: %s\n", index, pos);
            // Found something to render, and the current block is among the highest priority for this edge
            if (index > 0 && hasCurrent)
            {
                Vec3i posTmp = new Vec3i(pos.getX(), pos.getY(), pos.getZ());
                int ind = -1;

                for (int i = 0; i < index; ++i)
                {
                    Vec3i tmp = neighborPositions[i];
                    //System.out.printf("posTmp: %s, tmp: %s\n", posTmp, tmp);

                    // Just prioritize the position to render a shared highest priority edge by the coordinates
                    if (tmp.getX() <= posTmp.getX() && tmp.getY() <= posTmp.getY() && tmp.getZ() <= posTmp.getZ())
                    {
                        posTmp = tmp;
                        ind = i;
                    }
                }

                // The current position is the one that should render this edge
                if (posTmp.getX() == pos.getX() && posTmp.getY() == pos.getY() && posTmp.getZ() == pos.getZ())
                {
                    //System.out.printf("plop 2 index: %d, ind: %d, pos: %s, off: %s\n", index, ind, pos, posTmp);
                    RenderUtils.drawBlockBoxEdgeBatchedLines(pos, axis, corner, overlayColor, bufferOverlayOutlines);
                    lines++;
                }
            }
        }
    }
    //System.out.printf("typeSelf: %s, pos: %s, lines: %d\n", typeSelf, pos, lines);
}
 
Example 14
Source File: PositionUtils.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static long getAreaVolume(Vec3i size)
{
    return (long) size.getX() * (long) size.getY() * (long) size.getZ();
}
 
Example 15
Source File: MaterialListUtils.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static List<MaterialListEntry> createMaterialListFor(ISchematic schematic, Collection<String> subRegions)
{
    Object2LongOpenHashMap<IBlockState> countsTotal = new Object2LongOpenHashMap<>();

    for (String regionName : subRegions)
    {
        ISchematicRegion region = schematic.getSchematicRegion(regionName);
        ILitematicaBlockStateContainer container = region != null ? region.getBlockStateContainer() : null;

        if (container != null)
        {
            if (Configs.Generic.MATERIALS_FROM_CONTAINER.getBooleanValue())
            {
                for (Map.Entry<IBlockState, Long> entry : container.getBlockCountsMap().entrySet())
                {
                    long total = entry.getValue().longValue();

                    // Don't include stale entries from the palette due to Rebuild operations etc.
                    if (total > 0)
                    {
                        countsTotal.addTo(entry.getKey(), (int) total);
                    }
                }
            }
            else
            {
                Vec3i size = container.getSize();
                final int sizeX = size.getX();
                final int sizeY = size.getY();
                final int sizeZ = size.getZ();

                for (int y = 0; y < sizeY; ++y)
                {
                    for (int z = 0; z < sizeZ; ++z)
                    {
                        for (int x = 0; x < sizeX; ++x)
                        {
                            IBlockState state = container.getBlockState(x, y, z);
                            countsTotal.addTo(state, 1);
                        }
                    }
                }
            }
        }
    }

    Minecraft mc = Minecraft.getMinecraft();

    return getMaterialList(countsTotal, countsTotal, new Object2LongOpenHashMap<>(), mc.player);
}
 
Example 16
Source File: SchematicBase.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean isSizeValid(@Nullable Vec3i size)
{
    return size != null && size.getX() > 0 && size.getY() > 0 && size.getZ() > 0;
}
 
Example 17
Source File: BlockUtils.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public static boolean breakBlockSimple(BlockPos pos)
{
	EnumFacing side = null;
	EnumFacing[] sides = EnumFacing.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d relCenter = getState(pos)
		.getBoundingBox(WMinecraft.getWorld(), pos).getCenter();
	Vec3d center = new Vec3d(pos).add(relCenter);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
	{
		Vec3i dirVec = sides[i].getDirectionVec();
		Vec3d relHitVec = new Vec3d(WVec3d.getX(relCenter) * dirVec.getX(),
			WVec3d.getY(relCenter) * dirVec.getY(),
			WVec3d.getZ(relCenter) * dirVec.getZ());
		hitVecs[i] = center.add(relHitVec);
	}
	
	for(int i = 0; i < sides.length; i++)
	{
		// check line of sight
		if(WMinecraft.getWorld().rayTraceBlocks(eyesPos, hitVecs[i], false,
			true, false) != null)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
	{
		double distanceSqToCenter = eyesPos.squareDistanceTo(center);
		for(int i = 0; i < sides.length; i++)
		{
			// check if side is facing towards player
			if(eyesPos.squareDistanceTo(hitVecs[i]) >= distanceSqToCenter)
				continue;
			
			side = sides[i];
			break;
		}
	}
	
	// player is inside of block, side doesn't matter
	if(side == null)
		side = sides[0];
	
	// face block
	RotationUtils.faceVectorPacket(hitVecs[side.ordinal()]);
	
	// damage block
	if(!mc.playerController.onPlayerDamageBlock(pos, side))
		return false;
	
	// swing arm
	WMinecraft.getPlayer().connection
		.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
	
	return true;
}
 
Example 18
Source File: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean breakBlockSimple(BlockPos pos)
{
	Direction side = null;
	Direction[] sides = Direction.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d relCenter = BlockUtils.getBoundingBox(pos)
		.offset(-pos.getX(), -pos.getY(), -pos.getZ()).getCenter();
	Vec3d center = Vec3d.of(pos).add(relCenter);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
	{
		Vec3i dirVec = sides[i].getVector();
		Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(),
			relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ());
		hitVecs[i] = center.add(relHitVec);
	}
	
	for(int i = 0; i < sides.length; i++)
	{
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVecs[i],
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
	{
		double distanceSqToCenter = eyesPos.squaredDistanceTo(center);
		for(int i = 0; i < sides.length; i++)
		{
			// check if side is facing towards player
			if(eyesPos.squaredDistanceTo(hitVecs[i]) >= distanceSqToCenter)
				continue;
			
			side = sides[i];
			break;
		}
	}
	
	if(side == null)
		throw new RuntimeException(
			"How could none of the sides be facing towards the player?!");
	
	// face block
	WURST.getRotationFaker().faceVectorPacket(hitVecs[side.ordinal()]);
	
	// damage block
	if(!MC.interactionManager.updateBlockBreakingProgress(pos, side))
		return false;
	
	// swing arm
	MC.player.networkHandler
		.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
	
	return true;
}
 
Example 19
Source File: IterableVec3i.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** 
 * construct an IV3i from a regular V3i
 */
public IterableVec3i(Vec3i vec)
{
	this(vec.getX(), vec.getY(), vec.getZ());
}
 
Example 20
Source File: SchematicaSchematic.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected boolean readBlocksFromTag(NBTTagCompound tag)
{
    // This method was implemented based on
    // https://minecraft.gamepedia.com/Schematic_file_format
    // as it was on 2018-04-18.

    Vec3i size = this.getSize();
    final int sizeX = size.getX();
    final int sizeY = size.getY();
    final int sizeZ = size.getZ();
    final byte[] blockIdsByte = tag.getByteArray("Blocks");
    final byte[] metaArr = tag.getByteArray("Data");
    final int numBlocks = blockIdsByte.length;
    final int layerSize = sizeX * sizeZ;

    if (numBlocks != (sizeX * sizeY * sizeZ))
    {
        InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.schematic.invalid_block_array_size", numBlocks, sizeX, sizeY, sizeZ);
        return false;
    }

    if (numBlocks != metaArr.length)
    {
        InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.schematic.invalid_metadata_array_size", numBlocks, metaArr.length);
        return false;
    }

    if (this.readPaletteFromTag(tag) == false)
    {
        InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.palette.failed_to_read");
        return false;
    }

    if (tag.hasKey("AddBlocks", Constants.NBT.TAG_BYTE_ARRAY))
    {
        return this.readBlocks12Bit(tag, blockIdsByte, metaArr, sizeX, layerSize);
    }
    // Old Schematica format
    else if (tag.hasKey("Add", Constants.NBT.TAG_BYTE_ARRAY))
    {
        // FIXME is this array 4 or 8 bits per block?
        InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.old_schematica_format_not_supported");
        return false;
    }
    // No palette, use the registry IDs directly
    else
    {
        ILitematicaBlockStateContainer container = this.blockContainer;
        Block[] palette = this.palette;

        for (int i = 0; i < numBlocks; i++)
        {
            Block block = palette[blockIdsByte[i] & 0xFF];
            int x = i % sizeX;
            int y = i / layerSize;
            int z = (i % layerSize) / sizeX;
            container.setBlockState(x, y, z, block.getStateFromMeta(metaArr[i]));
        }
    }

    return true;
}