net.minecraft.util.math.Vec3i Java Examples
The following examples show how to use
net.minecraft.util.math.Vec3i.
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: CarpetDispenserBehaviours.java From carpet-extra with GNU Lesser General Public License v3.0 | 7 votes |
@Override protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) { if(!CarpetExtraSettings.dispensersToggleThings) { return super.dispenseSilently(source, stack); } World world = source.getWorld(); Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING); BlockPos pos = source.getBlockPos().offset(direction); BlockState state = world.getBlockState(pos); if(toggleable.contains(state.getBlock())) { ActionResult result = state.onUse( world, null, Hand.MAIN_HAND, new BlockHitResult( new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())), direction, pos, false ) ); if(result.isAccepted()) return stack; // success or consume } return super.dispenseSilently(source, stack); }
Example #2
Source File: SchematicBase.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
protected void copyContainerContents(ILitematicaBlockStateContainer from, ILitematicaBlockStateContainer to) { Vec3i sizeFrom = from.getSize(); Vec3i sizeTo = to.getSize(); final int sizeX = Math.min(sizeFrom.getX(), sizeTo.getX()); final int sizeY = Math.min(sizeFrom.getY(), sizeTo.getY()); final int sizeZ = Math.min(sizeFrom.getZ(), sizeTo.getZ()); for (int y = 0; y < sizeY; ++y) { for (int z = 0; z < sizeZ; ++z) { for (int x = 0; x < sizeX; ++x) { IBlockState state = from.getBlockState(x, y, z); to.setBlockState(x, y, z, state); } } } }
Example #3
Source File: MetaTileEntityTank.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void receiveCustomData(int dataId, PacketBuffer buf) { super.receiveCustomData(dataId, buf); if (dataId == 1) { this.controllerPos = buf.readBlockPos(); this.controllerCache = new WeakReference<>(null); this.multiblockFluidTank.setFluid(null); } else if (dataId == 2) { this.controllerPos = null; this.controllerCache = new WeakReference<>(null); this.multiblockFluidTank.setFluid(null); this.connectedTanks.clear(); this.multiblockSize = new Vec3i(1, 1, 1); } else if (dataId == 3) { if (controllerPos == null) { FluidStack fluidStack = ByteBufUtils.readFluidStackDelta(buf, multiblockFluidTank.getFluid()); this.multiblockFluidTank.setFluid(fluidStack); } } else if (dataId == 4) { this.connectedTanks = ByteBufUtils.readRelativeBlockList(buf, getPos()); this.multiblockSize = buf.readBlockPos(); recomputeTankSizeNow(true); } }
Example #4
Source File: MetaTileEntityTank.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
private void setTankController(MetaTileEntityTank controller) { if (controller == this) { return; } MetaTileEntityTank oldController = getControllerEntity(); if (oldController == controller) { return; //do not pointlessly update controller } if (oldController != null) { oldController.removeTankFromMultiblock(this); } if (controller != null) { //we are controlled by somebody now, remove our own controlled tanks clearConnectedTanks(); controller.addTankToMultiblock(this); } else { //we are controller ourselves now setTankControllerInternal(null); //reset multiblock size anyway this.multiblockSize = new Vec3i(1, 1, 1); } }
Example #5
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static Vec3i getOffsetToMoveBoxInfrontOfEntityPos(BlockPos entityPos, EnumFacing entityHorizontalFacing, BlockPos corner1, BlockPos corner2) { BlockPos minPos = fi.dy.masa.malilib.util.PositionUtils.getMinCorner(corner1, corner2); BlockPos maxPos = fi.dy.masa.malilib.util.PositionUtils.getMaxCorner(corner1, corner2); int offX = 0; int offZ = 0; switch (entityHorizontalFacing) { case EAST: offX = entityPos.getX() - minPos.getX() + 1; break; case WEST: offX = entityPos.getX() - maxPos.getX() - 1; break; case SOUTH: offZ = entityPos.getZ() - minPos.getZ() + 1; break; case NORTH: offZ = entityPos.getZ() - maxPos.getZ() - 1; break; default: } return new Vec3i(offX, 0, offZ); }
Example #6
Source File: GuiPlacementGridSettings.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
private void addSizeInputElements(int x, int y, int width, CoordinateType type) { String label = StringUtils.translate(this.getSizeTranslationKey(type)) + ":"; this.addLabel(x, y + 5, 0xFFFFFFFF, label); int offset = this.getStringWidth(label) + 4; Vec3i size = this.placement.getGridSettings().getSize(); String text = String.valueOf(PositionUtils.getCoordinate(size, type)); x += offset; int defaultSize = PositionUtils.getCoordinate(this.placement.getGridSettings().getDefaultSize(), type); WidgetTextFieldBase textField = new WidgetTextFieldBase(x, y + 2, width, 14, text); textField.setTextValidator(new WidgetTextFieldInteger.IntValidator(defaultSize, Integer.MAX_VALUE)); textField.setUpdateListenerAlways(true); this.addTextField(textField, new TextFieldListenerSize(type, this.placement, this)); x += width + 4; String hover = StringUtils.translate("litematica.gui.button.hover.plus_minus_tip"); ButtonGeneric button = new ButtonGeneric(x, y + 1, LitematicaGuiIcons.BUTTON_PLUS_MINUS_16, hover); this.addButton(button, new ButtonListenerSize(type, this.placement, this)); }
Example #7
Source File: LitematicaBlockStateContainerFull.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
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 #8
Source File: SingleRegionSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
protected void setSize(@Nullable Vec3i size, boolean createBlockContainer) { this.regionSize = size; if (size != null) { if (isSizeValid(size) == false) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.invalid_or_missing_size_value", size.getX(), size.getY(), size.getZ()); return; } if (createBlockContainer) { this.createEmptyContainer(size); } this.getMetadata().setEnclosingSize(size); this.getMetadata().setTotalVolume(PositionUtils.getAreaVolume(size)); } }
Example #9
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
/** * Removes the grid placements of the provided normal placement * from the requested grid points, if they exist * @param basePlacement * @param gridPoints * @return true if some placements were removed */ private boolean removeGridPlacements(SchematicPlacement basePlacement, Collection<Vec3i> gridPoints) { HashMap<Vec3i, SchematicPlacement> map = this.gridPlacementsPerPlacement.get(basePlacement); boolean modified = false; if (gridPoints.isEmpty() == false && map != null) { for (Vec3i point : gridPoints) { SchematicPlacement placement = map.get(point); if (placement != null) { this.schematicPlacementManager.removeTouchedChunksFor(placement); this.schematicPlacementManager.removeVisiblePlacement(placement); map.remove(point); modified = true; } } } return modified; }
Example #10
Source File: WorldUtils.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static void loadChunksClientWorld(WorldClient world, BlockPos origin, Vec3i areaSize) { BlockPos posEnd = origin.add(PositionUtils.getRelativeEndPositionFromAreaSize(areaSize)); BlockPos posMin = fi.dy.masa.malilib.util.PositionUtils.getMinCorner(origin, posEnd); BlockPos posMax = fi.dy.masa.malilib.util.PositionUtils.getMaxCorner(origin, posEnd); final int cxMin = posMin.getX() >> 4; final int czMin = posMin.getZ() >> 4; final int cxMax = posMax.getX() >> 4; final int czMax = posMax.getZ() >> 4; for (int cz = czMin; cz <= czMax; ++cz) { for (int cx = cxMin; cx <= cxMax; ++cx) { world.getChunkProvider().loadChunk(cx, cz); } } }
Example #11
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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 #12
Source File: SchematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
@Override @Nullable protected Vec3i readSizeFromTag(NBTTagCompound tag) { if (isValidSchematic(tag)) { return readSizeFromTagImpl(tag); } return null; }
Example #13
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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 #14
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates and adds all the grid placements within the loaded area * for the provided normal placement * @param basePlacement * @return true if some placements were added */ private boolean addGridPlacementsWithinLoadedAreaFor(SchematicPlacement basePlacement) { HashMap<Vec3i, SchematicPlacement> placements = this.createGridPlacementsWithinLoadedAreaFor(basePlacement); if (placements.isEmpty() == false) { return this.addGridPlacements(basePlacement, placements); } return false; }
Example #15
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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 #16
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public static Vec3i[] getEdgeNeighborOffsets(EnumFacing.Axis axis, int cornerIndex) { switch (axis) { case X: return EDGE_NEIGHBOR_OFFSETS_X[cornerIndex]; case Y: return EDGE_NEIGHBOR_OFFSETS_Y[cornerIndex]; case Z: return EDGE_NEIGHBOR_OFFSETS_Z[cornerIndex]; } return null; }
Example #17
Source File: RenderUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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 #18
Source File: Box.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
private void updateSize() { if (this.pos1 != null && this.pos2 != null) { this.size = PositionUtils.getAreaSizeFromRelativeEndPosition(this.pos2.subtract(this.pos1)); } else if (this.pos1 == null && this.pos2 == null) { this.size = new Vec3i(0, 0, 0); } else { this.size = new Vec3i(1, 1, 1); } }
Example #19
Source File: PositionUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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 #20
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Updates the grid placements for the provided normal placement, * adding or removing placements as needed so that the current * loaded area has all the required grid placements. * @return true if some placements were added or removed */ boolean createOrRemoveGridPlacementsForLoadedArea() { Box currentArea = this.getCurrentLoadedArea(1); boolean modified = false; if (currentArea != null) { for (SchematicPlacement basePlacement : this.basePlacements) { HashSet<Vec3i> currentGridPoints = this.getGridPointsWithinAreaFor(basePlacement, currentArea); HashSet<Vec3i> outOfRangePoints = this.getExistingOutOfRangeGridPointsFor(basePlacement, currentGridPoints); HashSet<Vec3i> newPoints = this.getNewGridPointsFor(basePlacement, currentGridPoints); //System.out.printf("c: %d, o: %d, n: %d\n", currentGridPoints.size(), outOfRangePoints.size(), newPoints.size()); if (outOfRangePoints.isEmpty() == false) { modified |= this.removeGridPlacements(basePlacement, outOfRangePoints); } if (newPoints.isEmpty() == false) { HashMap<Vec3i, SchematicPlacement> placements = this.createGridPlacementsForPoints(basePlacement, newPoints); modified |= this.addGridPlacements(basePlacement, placements); } } } if (modified) { OverlayRenderer.getInstance().updatePlacementCache(); } return modified; }
Example #21
Source File: SchematicUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable public static Pair<Vec3i, Vec3i> getLayerRangeClampedSubRegion(LayerRange range, SchematicPlacement schematicPlacement, SubRegionPlacement placement, Vec3i regionSize) { int minX = range.getClampedValue(LayerRange.getWorldMinValueForAxis(EnumFacing.Axis.X), EnumFacing.Axis.X); int minY = range.getClampedValue(LayerRange.getWorldMinValueForAxis(EnumFacing.Axis.Y), EnumFacing.Axis.Y); int minZ = range.getClampedValue(LayerRange.getWorldMinValueForAxis(EnumFacing.Axis.Z), EnumFacing.Axis.Z); int maxX = range.getClampedValue(LayerRange.getWorldMaxValueForAxis(EnumFacing.Axis.X), EnumFacing.Axis.X); int maxY = range.getClampedValue(LayerRange.getWorldMaxValueForAxis(EnumFacing.Axis.Y), EnumFacing.Axis.Y); int maxZ = range.getClampedValue(LayerRange.getWorldMaxValueForAxis(EnumFacing.Axis.Z), EnumFacing.Axis.Z); BlockPos posMinRange = new BlockPos(minX, minY, minZ); BlockPos posMaxRange = new BlockPos(maxX, maxY, maxZ); ISchematic schematic = schematicPlacement.getSchematic(); BlockPos pos1 = getReverseTransformedWorldPosition(posMinRange, schematic, schematicPlacement, placement, regionSize); BlockPos pos2 = getReverseTransformedWorldPosition(posMaxRange, schematic, schematicPlacement, placement, regionSize); if (pos1 == null || pos2 == null) { return null; } BlockPos posMinReversed = fi.dy.masa.malilib.util.PositionUtils.getMinCorner(pos1, pos2); BlockPos posMaxReversed = fi.dy.masa.malilib.util.PositionUtils.getMaxCorner(pos1, pos2); final int startX = Math.max(posMinReversed.getX(), 0); final int startY = Math.max(posMinReversed.getY(), 0); final int startZ = Math.max(posMinReversed.getZ(), 0); final int endX = Math.min(posMaxReversed.getX(), Math.abs(regionSize.getX()) - 1); final int endY = Math.min(posMaxReversed.getY(), Math.abs(regionSize.getY()) - 1); final int endZ = Math.min(posMaxReversed.getZ(), Math.abs(regionSize.getZ()) - 1); return Pair.of(new Vec3i(startX, startY, startZ), new Vec3i(endX, endY, endZ)); }
Example #22
Source File: SingleRegionSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void readFrom(ISchematic other) { ImmutableMap<String, ISchematicRegion> regions = other.getRegions(); if (regions.isEmpty() == false) { this.clear(); Vec3i size = other.getEnclosingSize(); if (size != null) { try { this.setSize(size, regions.size() > 1); this.readFrom(regions); this.getMetadata().copyFrom(other.getMetadata()); this.getMetadata().setRegionCount(1); } catch (Exception e) { Litematica.logger.warn("Exception while reading schematic contents from another schematic", e); } } } }
Example #23
Source File: SingleRegionSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
protected Vec3i getRegionOffset(ISchematicRegion region, BlockPos minCorner) { // Get the offset from the region's block state container origin // (the minimum corner of the region) to the enclosing area's origin/minimum corner. BlockPos regionPos = region.getPosition(); Vec3i endRel = PositionUtils.getRelativeEndPositionFromAreaSize(region.getSize()); BlockPos regionEnd = regionPos.add(endRel); BlockPos regionMin = fi.dy.masa.malilib.util.PositionUtils.getMinCorner(regionPos, regionEnd); BlockPos regionOffset = regionMin.subtract(minCorner); return regionOffset; }
Example #24
Source File: LitematicaBlockStateContainerSparse.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public LitematicaBlockStateContainerSparse(Vec3i size) { super(size); this.palette = new VanillaStructurePalette(); this.blockCounts = new long[256]; }
Example #25
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds the provided grid placements for the provided normal placement, * if there are no grid placements yet for those grid points. * @param basePlacement * @param placements * @return true if some placements were added */ private boolean addGridPlacements(SchematicPlacement basePlacement, HashMap<Vec3i, SchematicPlacement> placements) { boolean modified = false; if (placements.isEmpty() == false) { HashMap<Vec3i, SchematicPlacement> map = this.gridPlacementsPerPlacement.get(basePlacement); if (map == null) { map = new HashMap<>(); this.gridPlacementsPerPlacement.put(basePlacement, map); } for (Map.Entry<Vec3i, SchematicPlacement> entry : placements.entrySet()) { Vec3i point = entry.getKey(); SchematicPlacement placement = entry.getValue(); if (map.containsKey(point) == false) { map.put(point, placement); this.schematicPlacementManager.addVisiblePlacement(placement); this.schematicPlacementManager.addTouchedChunksFor(placement, false); modified = true; } } } return modified; }
Example #26
Source File: GridSettings.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public void setSize(CoordinateType coord, int value) { Vec3i oldSize = this.getSize(); int defaultValue = PositionUtils.getCoordinate(this.defaultSize, coord); // Don't allow shrinking the grid size smaller than the placement enclosing box int newValue = Math.max(defaultValue, value); this.setSize(PositionUtils.getModifiedPosition(oldSize, newValue, coord)); this.initialized = true; }
Example #27
Source File: GridSettings.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public void modifySize(CoordinateType coord, int amount) { Vec3i oldSize = this.getSize(); int oldValue = PositionUtils.getCoordinate(oldSize, coord); int newValue = Math.max(1, oldValue + amount); this.setSize(coord, newValue); }
Example #28
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
private HashMap<Vec3i, SchematicPlacement> createGridPlacementsWithinLoadedAreaFor(SchematicPlacement basePlacement) { Box currentArea = this.getCurrentLoadedArea(1); if (currentArea != null) { return this.createGridPlacementsWithinAreaFor(basePlacement, currentArea); } return new HashMap<>(); }
Example #29
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
private HashSet<Vec3i> getExistingOutOfRangeGridPointsFor(SchematicPlacement basePlacement, HashSet<Vec3i> currentGridPoints) { HashMap<Vec3i, SchematicPlacement> placements = this.gridPlacementsPerPlacement.get(basePlacement); if (placements != null) { HashSet<Vec3i> outOfRangePoints = new HashSet<>(placements.keySet()); outOfRangePoints.removeAll(currentGridPoints); return outOfRangePoints; } return new HashSet<>(); }
Example #30
Source File: GridPlacementManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
private HashSet<Vec3i> getNewGridPointsFor(SchematicPlacement basePlacement, HashSet<Vec3i> currentGridPoints) { HashMap<Vec3i, SchematicPlacement> placements = this.gridPlacementsPerPlacement.get(basePlacement); if (placements != null) { HashSet<Vec3i> newPoints = new HashSet<>(currentGridPoints); newPoints.removeAll(placements.keySet()); return newPoints; } else { return currentGridPoints; } }