Search in sources :

Example 6 with Box

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;
}
Also used : VolumeConnection(buildcraft.core.marker.VolumeConnection) Box(buildcraft.lib.misc.data.Box) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with Box

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();
    }
}
Also used : EnumAccess(buildcraft.lib.tile.item.ItemHandlerManager.EnumAccess) Blueprint(buildcraft.builders.snapshot.Blueprint) Arrays(java.util.Arrays) ItemSnapshot(buildcraft.builders.item.ItemSnapshot) Snapshot(buildcraft.builders.snapshot.Snapshot) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) IPathProvider(buildcraft.api.core.IPathProvider) Side(net.minecraftforge.fml.relauncher.Side) MessageUtil(buildcraft.lib.misc.MessageUtil) Fluid(net.minecraftforge.fluids.Fluid) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Template(buildcraft.builders.snapshot.Template) TankManager(buildcraft.lib.fluid.TankManager) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumSnapshotType(buildcraft.api.enums.EnumSnapshotType) BCBuildersItems(buildcraft.builders.BCBuildersItems) TileBC_Neptune(buildcraft.lib.tile.TileBC_Neptune) EnumOptionalSnapshotType(buildcraft.api.enums.EnumOptionalSnapshotType) Collectors(java.util.stream.Collectors) List(java.util.List) BlockBCBase_Neptune(buildcraft.lib.block.BlockBCBase_Neptune) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) MjBattery(buildcraft.api.mj.MjBattery) Optional(java.util.Optional) NBTUtil(net.minecraft.nbt.NBTUtil) MjAPI(buildcraft.api.mj.MjAPI) EnumPipePart(buildcraft.api.core.EnumPipePart) Box(buildcraft.lib.misc.data.Box) TemplateBuilder(buildcraft.builders.snapshot.TemplateBuilder) PositionUtil(buildcraft.lib.misc.PositionUtil) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ITileForTemplateBuilder(buildcraft.builders.snapshot.ITileForTemplateBuilder) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) MjBatteryReceiver(buildcraft.lib.mj.MjBatteryReceiver) BoundingBoxUtil(buildcraft.lib.misc.BoundingBoxUtil) ImmutableList(com.google.common.collect.ImmutableList) ITickable(net.minecraft.util.ITickable) CapUtil(buildcraft.lib.misc.CapUtil) MessageManager(buildcraft.lib.net.MessageManager) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) IdAllocator(buildcraft.lib.misc.data.IdAllocator) World(net.minecraft.world.World) IDebuggable(buildcraft.api.tiles.IDebuggable) EnumFacing(net.minecraft.util.EnumFacing) MjCapabilityHelper(buildcraft.api.mj.MjCapabilityHelper) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) BlueprintBuilder(buildcraft.builders.snapshot.BlueprintBuilder) Tank(buildcraft.lib.fluid.Tank) EntityLivingBase(net.minecraft.entity.EntityLivingBase) GlobalSavedDataSnapshots(buildcraft.builders.snapshot.GlobalSavedDataSnapshots) Rotation(net.minecraft.util.Rotation) ResourceLocation(net.minecraft.util.ResourceLocation) ITileForBlueprintBuilder(buildcraft.builders.snapshot.ITileForBlueprintBuilder) TileEntity(net.minecraft.tileentity.TileEntity) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) AdvancementUtil(buildcraft.lib.misc.AdvancementUtil) IItemTransactor(buildcraft.api.inventory.IItemTransactor) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) Box(buildcraft.lib.misc.data.Box)

Example 8 with 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();
}
Also used : Box(buildcraft.lib.misc.data.Box) BlockPos(net.minecraft.util.math.BlockPos) LaserData_BC8(buildcraft.lib.client.render.laser.LaserData_BC8) Vec3d(net.minecraft.util.math.Vec3d)

Example 9 with Box

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) Box(buildcraft.lib.misc.data.Box) IBox(buildcraft.api.core.IBox)

Example 10 with Box

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);
}
Also used : IntStream(java.util.stream.IntStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Box(buildcraft.lib.misc.data.Box) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumMap(java.util.EnumMap) World(net.minecraft.world.World) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) ArrayList(java.util.ArrayList) Unpooled(io.netty.buffer.Unpooled) Objects(java.util.Objects) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) List(java.util.List) Stream(java.util.stream.Stream) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) NBTUtil(net.minecraft.nbt.NBTUtil) Box(buildcraft.lib.misc.data.Box) IOException(java.io.IOException) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) ResourceLocation(net.minecraft.util.ResourceLocation) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map)

Aggregations

Box (buildcraft.lib.misc.data.Box)19 BlockPos (net.minecraft.util.math.BlockPos)10 Test (org.junit.Test)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 IBox (buildcraft.api.core.IBox)2 VolumeConnection (buildcraft.core.marker.VolumeConnection)2 NBTUtilBC (buildcraft.lib.misc.NBTUtilBC)2 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Vec3d (net.minecraft.util.math.Vec3d)2 World (net.minecraft.world.World)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IAreaProvider (buildcraft.api.core.IAreaProvider)1 IPathProvider (buildcraft.api.core.IPathProvider)1 EnumOptionalSnapshotType (buildcraft.api.enums.EnumOptionalSnapshotType)1 EnumSnapshotType (buildcraft.api.enums.EnumSnapshotType)1