Search in sources :

Example 1 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WorkOrderBuildDecoration method readFromNBT.

/**
 * Read the WorkOrder data from the NBTTagCompound.
 *
 * @param compound NBT Tag compound.
 */
@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
    super.readFromNBT(compound);
    buildingLocation = BlockPosUtil.readFromNBT(compound, TAG_BUILDING);
    final StructureName sn = new StructureName(compound.getString(TAG_SCHEMATIC_NAME));
    structureName = sn.toString();
    workOrderName = compound.getString(TAG_WORKORDER_NAME);
    cleared = compound.getBoolean(TAG_IS_CLEARED);
    md5 = compound.getString(TAG_SCHEMATIC_MD5);
    if (!Structures.hasMD5(structureName)) {
        // If the schematic move we can use the MD5 hash to find it
        final StructureName newSN = Structures.getStructureNameByMD5(md5);
        if (newSN == null) {
            Log.getLogger().error("WorkOrderBuildDecoration.readFromNBT: Could not find " + structureName);
        } else {
            Log.getLogger().warn("WorkOrderBuildDecoration.readFromNBT: replace " + sn + " by " + newSN);
            structureName = newSN.toString();
        }
    }
    buildingRotation = compound.getInteger(TAG_BUILDING_ROTATION);
    requested = compound.getBoolean(TAG_IS_REQUESTED);
    isBuildingMirrored = compound.getBoolean(TAG_IS_MIRRORED);
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName)

Example 2 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class Structure method getStream.

/**
 * get a InputStream for a give structureName.
 * <p>
 * Look into the following director (in order):
 * - scan
 * - cache
 * - schematics folder
 * - jar
 * It should be the exact opposite that the way used to build the list.
 * <p>
 * Suppressing Sonar Rule squid:S2095
 * This rule enforces "Close this InputStream"
 * But in this case the rule does not apply because
 * We are returning the stream and that is reasonable
 *
 * @param structureName name of the structure to load
 * @return the input stream or null
 */
@SuppressWarnings(RESOURCES_SHOULD_BE_CLOSED)
@Nullable
public static InputStream getStream(final String structureName) {
    final StructureName sn = new StructureName(structureName);
    InputStream inputstream = null;
    if (Structures.SCHEMATICS_CACHE.equals(sn.getPrefix())) {
        return Structure.getStreamFromFolder(Structure.getCachedSchematicsFolder(), structureName);
    } else if (Structures.SCHEMATICS_SCAN.equals(sn.getPrefix())) {
        return Structure.getStreamFromFolder(Structure.getClientSchematicsFolder(), structureName);
    } else if (!Structures.SCHEMATICS_PREFIX.equals(sn.getPrefix())) {
        return null;
    } else {
        // Look in the folder first
        inputstream = Structure.getStreamFromFolder(MineColonies.proxy.getSchematicsFolder(), structureName);
        if (inputstream == null && !Configurations.gameplay.ignoreSchematicsFromJar) {
            inputstream = Structure.getStreamFromJar(structureName);
        }
    }
    if (inputstream == null) {
        Log.getLogger().warn("Structure: Couldn't find any structure with this name " + structureName);
    }
    return inputstream;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) StructureName(com.minecolonies.coremod.colony.StructureName) Nullable(javax.annotation.Nullable)

Example 3 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class ClientStructureWrapper method handleSaveScanMessage.

/**
 * Handles the save message of scans.
 *
 * @param nbttagcompound compound to store.
 * @param fileName  milli seconds for fileName.
 */
public static void handleSaveScanMessage(final NBTTagCompound nbttagcompound, final String fileName) {
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_SCAN, "new", fileName);
    final File file = new File(Structure.getClientSchematicsFolder(), structureName.toString() + Structures.SCHEMATIC_EXTENSION);
    Utils.checkDirectory(file.getParentFile());
    try (OutputStream outputstream = new FileOutputStream(file)) {
        CompressedStreamTools.writeCompressed(nbttagcompound, outputstream);
    } catch (final IOException e) {
        LanguageHandler.sendPlayerMessage(Minecraft.getMinecraft().player, "item.scepterSteel.scanFailure");
        Log.getLogger().warn("Exception while trying to scan.", e);
        return;
    }
    LanguageHandler.sendPlayerMessage(Minecraft.getMinecraft().player, "item.scepterSteel.scanSuccess", file);
    Settings.instance.setStructureName(structureName.toString());
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) StructureName(com.minecolonies.coremod.colony.StructureName) IOException(java.io.IOException) File(java.io.File)

Example 4 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildBuilding method updateResources.

/**
 * Clears and resets/updates all resources.
 */
private void updateResources() {
    final World world = Minecraft.getMinecraft().world;
    resources.clear();
    final int nextLevel = building.getBuildingLevel() == building.getBuildingMaxLevel() ? building.getBuildingMaxLevel() : (building.getBuildingLevel() + 1);
    final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), building.getSchematicName() + nextLevel);
    final StructureWrapper wrapper = new StructureWrapper(world, sn.toString());
    wrapper.setPosition(building.getLocation());
    wrapper.rotate(building.getRotation(), world, building.getLocation(), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE);
    while (wrapper.findNextBlock()) {
        @Nullable final Template.BlockInfo blockInfo = wrapper.getBlockInfo();
        @Nullable final Template.EntityInfo entityInfo = wrapper.getEntityinfo();
        if (entityInfo != null) {
            for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, Minecraft.getMinecraft().player)) {
                if (!ItemStackUtils.isEmpty(stack)) {
                    addNeededResource(stack, 1);
                }
            }
        }
        if (blockInfo == null) {
            continue;
        }
        @Nullable final IBlockState blockState = blockInfo.blockState;
        @Nullable final Block block = blockState.getBlock();
        if (wrapper.isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
            continue;
        }
        if (block != null && block != Blocks.AIR && !AbstractEntityAIStructure.isBlockFree(block, 0) && block != ModBlocks.blockSolidSubstitution && block != ModBlocks.blockSubstitution) {
            if (wrapper.getBlockInfo().tileentityData != null) {
                final List<ItemStack> itemList = new ArrayList<>();
                if (wrapper.getBlockInfo() != null && wrapper.getBlockInfo().tileentityData != null) {
                    itemList.addAll(ItemStackUtils.getItemStacksOfTileEntity(wrapper.getBlockInfo().tileentityData, world));
                }
                for (final ItemStack stack : itemList) {
                    addNeededResource(stack, 1);
                }
            }
            addNeededResource(BlockUtils.getItemStackFromBlockState(blockState), 1);
        }
    }
    window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
    updateResourceList();
}
Also used : StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) StructureName(com.minecolonies.coremod.colony.StructureName) BlockBed(net.minecraft.block.BlockBed) World(net.minecraft.world.World) Template(net.minecraft.world.gen.structure.template.Template) BlockDoor(net.minecraft.block.BlockDoor) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method renameClicked.

/**
 * Action performed when rename button is clicked.
 */
private void renameClicked() {
    final StructureName structureName = new StructureName(schematics.get(schematicsDropDownList.getSelectedIndex()));
    @NotNull final WindowStructureNameEntry window = new WindowStructureNameEntry(structureName);
    window.open();
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StructureName (com.minecolonies.coremod.colony.StructureName)16 DropDownList (com.minecolonies.blockout.views.DropDownList)2 BuildToolPasteMessage (com.minecolonies.coremod.network.messages.BuildToolPasteMessage)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 Nullable (org.jetbrains.annotations.Nullable)2 Button (com.minecolonies.blockout.controls.Button)1 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)1 BuildToolPlaceMessage (com.minecolonies.coremod.network.messages.BuildToolPlaceMessage)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 SchematicSaveMessage (com.minecolonies.coremod.network.messages.SchematicSaveMessage)1 StructureWrapper (com.minecolonies.coremod.util.StructureWrapper)1 Structure (com.minecolonies.structures.helpers.Structure)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1