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);
}
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;
}
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());
}
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();
}
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();
}
Aggregations