Search in sources :

Example 1 with Snapshot

use of buildcraft.builders.snapshot.Snapshot 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 Snapshot

use of buildcraft.builders.snapshot.Snapshot 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 Snapshot

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

the class TileReplacer method update.

@Override
public void update() {
    if (world.isRemote) {
        return;
    }
    if (!invSnapshot.getStackInSlot(0).isEmpty() && !invSchematicFrom.getStackInSlot(0).isEmpty() && !invSchematicTo.getStackInSlot(0).isEmpty()) {
        Header header = BCBuildersItems.snapshot.getHeader(invSnapshot.getStackInSlot(0));
        if (header != null) {
            Snapshot snapshot = GlobalSavedDataSnapshots.get(world).getSnapshot(header.key);
            if (snapshot instanceof Blueprint) {
                Blueprint blueprint = (Blueprint) snapshot;
                try {
                    ISchematicBlock from = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicFrom.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
                    ISchematicBlock to = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicTo.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
                    Blueprint newBlueprint = blueprint.copy();
                    newBlueprint.replace(from, to);
                    newBlueprint.computeKey();
                    GlobalSavedDataSnapshots.get(world).addSnapshot(newBlueprint);
                    invSnapshot.setStackInSlot(0, BCBuildersItems.snapshot.getUsed(EnumSnapshotType.BLUEPRINT, new Header(blueprint.key, getOwner().getId(), new Date(), header.name)));
                    invSchematicFrom.setStackInSlot(0, ItemStack.EMPTY);
                    invSchematicTo.setStackInSlot(0, ItemStack.EMPTY);
                } catch (InvalidInputDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ISchematicBlock(buildcraft.api.schematics.ISchematicBlock) ItemSnapshot(buildcraft.builders.item.ItemSnapshot) Snapshot(buildcraft.builders.snapshot.Snapshot) InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) Header(buildcraft.builders.snapshot.Snapshot.Header) Blueprint(buildcraft.builders.snapshot.Blueprint) Date(java.util.Date)

Example 4 with Snapshot

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

the class GuiElectronicLibrary method onDelButtonClick.

private void onDelButtonClick(IButtonClickEventTrigger button, int buttonKey) {
    if (container.tile.selected != null) {
        Snapshot snapshot = getSnapshots().getSnapshot(container.tile.selected);
        if (snapshot != null) {
            container.sendSelectedToServer(null);
            getSnapshots().removeSnapshot(snapshot.key);
        }
    }
}
Also used : Snapshot(buildcraft.builders.snapshot.Snapshot)

Example 5 with Snapshot

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

the class TileArchitectTable method finishScanning.

private void finishScanning() {
    IBlockState thisState = getCurrentStateForBlock(BCBuildersBlocks.architect);
    if (thisState == null) {
        return;
    }
    EnumFacing facing = thisState.getValue(BlockArchitectTable.PROP_FACING);
    Snapshot snapshot = Snapshot.create(snapshotType);
    snapshot.size = box.size();
    snapshot.facing = facing;
    snapshot.offset = box.min().subtract(pos.offset(facing.getOpposite()));
    if (snapshot instanceof Template) {
        ((Template) snapshot).data = templateScannedBlocks;
    }
    if (snapshot instanceof Blueprint) {
        ((Blueprint) snapshot).palette.addAll(blueprintScannedPalette);
        ((Blueprint) snapshot).data = blueprintScannedData;
        ((Blueprint) snapshot).entities.addAll(blueprintScannedEntities);
    }
    snapshot.computeKey();
    GlobalSavedDataSnapshots.get(world).addSnapshot(snapshot);
    ItemStack stackIn = invSnapshotIn.getStackInSlot(0);
    stackIn.setCount(stackIn.getCount() - 1);
    if (stackIn.getCount() == 0) {
        stackIn = ItemStack.EMPTY;
    }
    invSnapshotIn.setStackInSlot(0, stackIn);
    invSnapshotOut.setStackInSlot(0, BCBuildersItems.snapshot.getUsed(snapshotType, new Header(snapshot.key, getOwner().getId(), new Date(), name)));
    templateScannedBlocks = null;
    blueprintScannedData = null;
    blueprintScannedEntities.clear();
    boxIterator = null;
    sendNetworkUpdate(NET_RENDER_DATA);
    AdvancementUtil.unlockAdvancement(getOwner().getId(), ADVANCEMENT);
}
Also used : ItemSnapshot(buildcraft.builders.item.ItemSnapshot) Snapshot(buildcraft.builders.snapshot.Snapshot) IBlockState(net.minecraft.block.state.IBlockState) Header(buildcraft.builders.snapshot.Snapshot.Header) Blueprint(buildcraft.builders.snapshot.Blueprint) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack) Date(java.util.Date) Template(buildcraft.builders.snapshot.Template)

Aggregations

Snapshot (buildcraft.builders.snapshot.Snapshot)7 ItemSnapshot (buildcraft.builders.item.ItemSnapshot)6 Blueprint (buildcraft.builders.snapshot.Blueprint)3 ItemStack (net.minecraft.item.ItemStack)3 EnumPipePart (buildcraft.api.core.EnumPipePart)2 BCBuildersItems (buildcraft.builders.BCBuildersItems)2 GlobalSavedDataSnapshots (buildcraft.builders.snapshot.GlobalSavedDataSnapshots)2 Header (buildcraft.builders.snapshot.Snapshot.Header)2 SnapshotBuilder (buildcraft.builders.snapshot.SnapshotBuilder)2 Template (buildcraft.builders.snapshot.Template)2 IdAllocator (buildcraft.lib.misc.data.IdAllocator)2 MessageManager (buildcraft.lib.net.MessageManager)2 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 Date (java.util.Date)2 EnumFacing (net.minecraft.util.EnumFacing)2 IPathProvider (buildcraft.api.core.IPathProvider)1 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)1 NbtSquishConstants (buildcraft.api.data.NbtSquishConstants)1 EnumOptionalSnapshotType (buildcraft.api.enums.EnumOptionalSnapshotType)1 EnumSnapshotType (buildcraft.api.enums.EnumSnapshotType)1