use of buildcraft.lib.misc.data.Box in project BuildCraft by BuildCraft.
the class TileMarkerVolume method isValidFromLocation.
@Override
public boolean isValidFromLocation(BlockPos pos) {
VolumeConnection connection = getCurrentConnection();
if (connection == null) {
return false;
}
Box box = connection.getBox();
if (box.contains(pos)) {
return false;
}
for (BlockPos p : PositionUtil.getCorners(box.min(), box.max())) {
if (PositionUtil.isNextTo(p, pos)) {
return true;
}
}
return false;
}
use of buildcraft.lib.misc.data.Box in project BuildCraft by BuildCraft.
the class TileBuilder method updateSnapshot.
private void updateSnapshot(boolean canGetFacing) {
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::cancel);
if (snapshot != null && getCurrentBasePos() != null) {
snapshotType = snapshot.getType();
if (canGetFacing) {
rotation = Arrays.stream(Rotation.values()).filter(r -> r.rotate(snapshot.facing) == world.getBlockState(pos).getValue(BlockBCBase_Neptune.PROP_FACING)).findFirst().orElse(null);
}
if (snapshot.getType() == EnumSnapshotType.TEMPLATE) {
templateBuildingInfo = ((Template) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
if (snapshot.getType() == EnumSnapshotType.BLUEPRINT) {
blueprintBuildingInfo = ((Blueprint) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
currentBox = Optional.ofNullable(getBuildingInfo()).map(buildingInfo -> buildingInfo.box).orElse(null);
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::updateSnapshot);
} else {
snapshotType = null;
rotation = null;
templateBuildingInfo = null;
blueprintBuildingInfo = null;
currentBox = null;
}
if (currentBox == null) {
currentBox = new Box();
}
}
use of buildcraft.lib.misc.data.Box in project BuildCraft by BuildCraft.
the class RenderBuilder method renderTileEntityFast.
@Override
public void renderTileEntityFast(@Nonnull TileBuilder tile, double x, double y, double z, float partialTicks, int destroyStage, float partial, @Nonnull BufferBuilder buffer) {
Minecraft.getMinecraft().mcProfiler.startSection("bc");
Minecraft.getMinecraft().mcProfiler.startSection("builder");
buffer.setTranslation(x - tile.getPos().getX(), y - tile.getPos().getY(), z - tile.getPos().getZ());
Minecraft.getMinecraft().mcProfiler.startSection("box");
Box box = tile.getBox();
LaserBoxRenderer.renderLaserBoxDynamic(box, BuildCraftLaserManager.STRIPES_WRITE, buffer, true);
Minecraft.getMinecraft().mcProfiler.endStartSection("path");
List<BlockPos> path = tile.path;
if (path != null) {
BlockPos last = null;
for (BlockPos p : path) {
if (last != null) {
Vec3d from = new Vec3d(last).add(VecUtil.VEC_HALF);
Vec3d to = new Vec3d(p).add(VecUtil.VEC_HALF);
Vec3d one = offset(from, to);
Vec3d two = offset(to, from);
LaserData_BC8 data = new LaserData_BC8(BuildCraftLaserManager.STRIPES_WRITE_DIRECTION, one, two, 1 / 16.1);
LaserRenderer_BC8.renderLaserDynamic(data, buffer);
}
last = p;
}
}
Minecraft.getMinecraft().mcProfiler.endSection();
buffer.setTranslation(0, 0, 0);
if (tile.getBuilder() != null) {
RenderSnapshotBuilder.render(tile.getBuilder(), tile.getWorld(), tile.getPos(), x, y, z, partialTicks, buffer);
}
Minecraft.getMinecraft().mcProfiler.endSection();
Minecraft.getMinecraft().mcProfiler.endSection();
}
use of buildcraft.lib.misc.data.Box in project BuildCraft by BuildCraft.
the class ItemMapLocation method getAreaBox.
public static IBox getAreaBox(@Nonnull ItemStack item) {
NBTTagCompound cpt = NBTUtilBC.getItemData(item);
int xMin = cpt.getInteger("xMin");
int yMin = cpt.getInteger("yMin");
int zMin = cpt.getInteger("zMin");
BlockPos min = new BlockPos(xMin, yMin, zMin);
int xMax = cpt.getInteger("xMax");
int yMax = cpt.getInteger("yMax");
int zMax = cpt.getInteger("zMax");
BlockPos max = new BlockPos(xMax, yMax, zMax);
return new Box(min, max);
}
use of buildcraft.lib.misc.data.Box in project BuildCraft by BuildCraft.
the class VolumeBox method fromBytes.
public void fromBytes(PacketBufferBC buf) throws IOException {
id = buf.readUniqueId();
box = new Box();
box.readData(buf);
player = buf.readBoolean() ? buf.readUniqueId() : null;
Map<EnumAddonSlot, Addon> newAddons = new EnumMap<>(EnumAddonSlot.class);
int count = buf.readInt();
for (int i = 0; i < count; i++) {
EnumAddonSlot slot = buf.readEnumValue(EnumAddonSlot.class);
ResourceLocation rl = new ResourceLocation(buf.readString(1024));
Class<? extends Addon> addonClass = AddonsRegistry.INSTANCE.getClassByName(rl);
try {
if (addonClass == null) {
throw new IOException("Unknown addon class " + rl);
}
Addon addon = addonClass.newInstance();
addon.volumeBox = this;
addon.onAdded();
addon.fromBytes(buf);
newAddons.put(slot, addon);
} catch (InstantiationException | IllegalAccessException e) {
throw new IOException("Failed to deserialize addon!", e);
}
}
addons.keySet().removeIf(slot -> !newAddons.containsKey(slot));
newAddons.entrySet().stream().filter(slotAddon -> !addons.containsKey(slotAddon.getKey())).forEach(slotAddon -> addons.put(slotAddon.getKey(), slotAddon.getValue()));
for (Map.Entry<EnumAddonSlot, Addon> slotAddon : newAddons.entrySet()) {
PacketBufferBC buffer = new PacketBufferBC(Unpooled.buffer());
slotAddon.getValue().toBytes(buffer);
addons.get(slotAddon.getKey()).fromBytes(buffer);
}
locks.clear();
IntStream.range(0, buf.readInt()).mapToObj(i -> {
Lock lock = new Lock();
lock.fromBytes(buf);
return lock;
}).forEach(locks::add);
}
Aggregations