Search in sources :

Example 1 with SnapshotBuilder

use of buildcraft.builders.snapshot.SnapshotBuilder in project BuildCraft by BuildCraft.

the class TileBuilder method onSlotChange.

@Override
protected void onSlotChange(IItemHandlerModifiable handler, int slot, @Nonnull ItemStack before, @Nonnull ItemStack after) {
    if (!world.isRemote) {
        if (handler == invSnapshot) {
            currentBasePosIndex = 0;
            snapshot = null;
            if (after.getItem() instanceof ItemSnapshot) {
                Snapshot.Header header = BCBuildersItems.snapshot.getHeader(after);
                if (header != null) {
                    Snapshot newSnapshot = GlobalSavedDataSnapshots.get(world).getSnapshot(header.key);
                    if (newSnapshot != null) {
                        snapshot = newSnapshot;
                    }
                }
            }
            updateSnapshot(true);
            sendNetworkUpdate(NET_SNAPSHOT_TYPE);
        }
        if (handler == invResources) {
            Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::resourcesChanged);
        }
    }
    super.onSlotChange(handler, slot, before, after);
}
Also used : ItemSnapshot(buildcraft.builders.item.ItemSnapshot) Snapshot(buildcraft.builders.snapshot.Snapshot) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) ItemSnapshot(buildcraft.builders.item.ItemSnapshot)

Example 2 with SnapshotBuilder

use of buildcraft.builders.snapshot.SnapshotBuilder 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 3 with SnapshotBuilder

use of buildcraft.builders.snapshot.SnapshotBuilder in project BuildCraft by BuildCraft.

the class RenderSnapshotBuilder method render.

public static <T extends ITileForSnapshotBuilder> void render(SnapshotBuilder<T> snapshotBuilder, World world, BlockPos tilePos, double x, double y, double z, float partialTicks, BufferBuilder bb) {
    for (SnapshotBuilder<T>.PlaceTask placeTask : snapshotBuilder.clientPlaceTasks) {
        Vec3d prevPos = snapshotBuilder.prevClientPlaceTasks.stream().filter(renderTaskLocal -> renderTaskLocal.pos.equals(placeTask.pos)).map(snapshotBuilder::getPlaceTaskItemPos).findFirst().orElse(snapshotBuilder.getPlaceTaskItemPos(snapshotBuilder.new PlaceTask(tilePos, Collections.emptyList(), 0L)));
        Vec3d pos = prevPos.add(snapshotBuilder.getPlaceTaskItemPos(placeTask).subtract(prevPos).scale(partialTicks));
        for (ItemStack item : placeTask.items) {
            ItemRenderUtil.renderItemStack(x - tilePos.getX() + pos.x, y - tilePos.getY() + pos.y, z - tilePos.getZ() + pos.z, item, world.getCombinedLight(new BlockPos(pos), 0), EnumFacing.SOUTH, bb);
        }
        ItemRenderUtil.endItemBatch();
    }
    Vec3d robotPos = snapshotBuilder.robotPos;
    if (robotPos != null) {
        if (snapshotBuilder.prevRobotPos != null) {
            robotPos = snapshotBuilder.prevRobotPos.add(robotPos.subtract(snapshotBuilder.prevRobotPos).scale(partialTicks));
        }
        bb.setTranslation(x - tilePos.getX(), y - tilePos.getY(), z - tilePos.getZ());
        int i = 0;
        for (EnumFacing face : EnumFacing.VALUES) {
            ModelUtil.createFace(face, new Point3f((float) robotPos.x, (float) robotPos.y, (float) robotPos.z), new Point3f(4 / 16F, 4 / 16F, 4 / 16F), new ModelUtil.UvFaceData(BCBuildersSprites.ROBOT.getInterpU((i * 8) / 64D), BCBuildersSprites.ROBOT.getInterpV(0 / 64D), BCBuildersSprites.ROBOT.getInterpU(((i + 1) * 8) / 64D), BCBuildersSprites.ROBOT.getInterpV(8 / 64D))).lighti(world.getCombinedLight(new BlockPos(robotPos), 0)).render(bb);
            i++;
        }
        for (SnapshotBuilder.BreakTask breakTask : snapshotBuilder.clientBreakTasks) {
            LaserRenderer_BC8.renderLaserDynamic(new LaserData_BC8(BuildCraftLaserManager.POWERS[(int) Math.round(MathUtil.clamp(breakTask.power * 1D / breakTask.getTarget(), 0D, 1D) * (BuildCraftLaserManager.POWERS.length - 1))], robotPos.subtract(new Vec3d(0, 0.27, 0)), new Vec3d(breakTask.pos).add(VecUtil.VEC_HALF), 1 / 16D), bb);
        }
    }
    bb.setTranslation(0, 0, 0);
}
Also used : ModelUtil(buildcraft.lib.client.model.ModelUtil) World(net.minecraft.world.World) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) LaserData_BC8(buildcraft.lib.client.render.laser.LaserData_BC8) EnumFacing(net.minecraft.util.EnumFacing) BCBuildersSprites(buildcraft.builders.BCBuildersSprites) BlockPos(net.minecraft.util.math.BlockPos) LaserRenderer_BC8(buildcraft.lib.client.render.laser.LaserRenderer_BC8) BuildCraftLaserManager(buildcraft.core.client.BuildCraftLaserManager) Point3f(javax.vecmath.Point3f) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) ITileForSnapshotBuilder(buildcraft.builders.snapshot.ITileForSnapshotBuilder) ItemRenderUtil(buildcraft.lib.client.render.ItemRenderUtil) MathUtil(buildcraft.lib.misc.MathUtil) VecUtil(buildcraft.lib.misc.VecUtil) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Collections(java.util.Collections) ITileForSnapshotBuilder(buildcraft.builders.snapshot.ITileForSnapshotBuilder) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) EnumFacing(net.minecraft.util.EnumFacing) LaserData_BC8(buildcraft.lib.client.render.laser.LaserData_BC8) Vec3d(net.minecraft.util.math.Vec3d) ModelUtil(buildcraft.lib.client.model.ModelUtil) Point3f(javax.vecmath.Point3f) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SnapshotBuilder (buildcraft.builders.snapshot.SnapshotBuilder)3 ItemSnapshot (buildcraft.builders.item.ItemSnapshot)2 Snapshot (buildcraft.builders.snapshot.Snapshot)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IPathProvider (buildcraft.api.core.IPathProvider)1 EnumOptionalSnapshotType (buildcraft.api.enums.EnumOptionalSnapshotType)1 EnumSnapshotType (buildcraft.api.enums.EnumSnapshotType)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 MjAPI (buildcraft.api.mj.MjAPI)1 MjBattery (buildcraft.api.mj.MjBattery)1 MjCapabilityHelper (buildcraft.api.mj.MjCapabilityHelper)1 IDebuggable (buildcraft.api.tiles.IDebuggable)1 BCBuildersItems (buildcraft.builders.BCBuildersItems)1 BCBuildersSprites (buildcraft.builders.BCBuildersSprites)1 Blueprint (buildcraft.builders.snapshot.Blueprint)1 BlueprintBuilder (buildcraft.builders.snapshot.BlueprintBuilder)1 GlobalSavedDataSnapshots (buildcraft.builders.snapshot.GlobalSavedDataSnapshots)1 ITileForBlueprintBuilder (buildcraft.builders.snapshot.ITileForBlueprintBuilder)1 ITileForSnapshotBuilder (buildcraft.builders.snapshot.ITileForSnapshotBuilder)1 ITileForTemplateBuilder (buildcraft.builders.snapshot.ITileForTemplateBuilder)1