use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.
the class BuildToolPasteMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final BuildToolPasteMessage message, final EntityPlayerMP player) {
final StructureName sn = new StructureName(message.structureName);
if (!Structures.hasMD5(sn)) {
player.sendMessage(new TextComponentString("Can not build " + message.workOrderName + ": schematic missing!"));
return;
}
if (player.capabilities.isCreativeMode) {
if (message.isHut) {
handleHut(CompatibilityUtils.getWorld(player), player, sn, message.rotation, message.pos, message.mirror);
}
StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
if (message.isHut) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(CompatibilityUtils.getWorld(player), message.pos);
if (building != null) {
final WorkOrderBuild workOrder = new WorkOrderBuild(building, 1);
ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorld(player));
}
}
} else if (message.freeMode != null) {
if (player.getStatFile().readStat(StatList.getObjectUseStats(ModItems.supplyChest)) > 0) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.error.supplyChestAlreadyPlaced");
return;
}
final List<ItemStack> stacks = new ArrayList<>();
final int chestHeight;
if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYSHIP) {
stacks.add(new ItemStack(ModItems.supplyChest));
chestHeight = SUPPLY_SHIP_CHEST_HEIGHT;
} else if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYCAMP) {
stacks.add(new ItemStack(ModItems.supplyCamp));
chestHeight = 1;
} else {
chestHeight = 0;
}
player.addStat(StatList.getObjectUseStats(ModItems.supplyChest));
if (InventoryUtils.removeStacksFromItemHandler(new InvWrapper(player.inventory), stacks)) {
StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
player.getServerWorld().setBlockState(message.pos.up(chestHeight), Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, player.getHorizontalFacing()));
fillChest((TileEntityChest) player.getServerWorld().getTileEntity(message.pos.up(chestHeight)));
} else {
LanguageHandler.sendPlayerMessage(player, "item.supplyChestDeployer.missing");
}
}
}
use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.
the class WindowStructureNameEntry method onButtonClicked.
@Override
public void onButtonClicked(@NotNull final Button button) {
if (button.getID().equals(BUTTON_DONE)) {
final String name = inputName.getText();
if (!name.isEmpty()) {
final StructureName newStructureName = Structures.renameScannedStructure(structureName, name);
if (newStructureName != null) {
Settings.instance.setStructureName(newStructureName.toString());
}
}
} else if (!button.getID().equals(BUTTON_CANCEL)) {
return;
}
close();
MineColonies.proxy.openBuildToolWindow(null);
}
use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.
the class WindowBuildTool method requestScannedSchematic.
/**
* Request to build a player scan.
*
* @param paste if it should be pasted.
* @param complete if pasted, should it be complete.
* @param structureName of the scan to be built.
*/
private static void requestScannedSchematic(@NotNull final StructureName structureName, final boolean paste, final boolean complete) {
if (!Structures.isPlayerSchematicsAllowed()) {
return;
}
if (Structures.hasMD5(structureName)) {
final String md5 = Structures.getMD5(structureName.toString());
final String serverSideName = Structures.SCHEMATICS_CACHE + '/' + md5;
if (!Structures.hasMD5(new StructureName(serverSideName))) {
final InputStream stream = Structure.getStream(structureName.toString());
if (stream != null) {
final UUID id = UUID.randomUUID();
final byte[] structureAsByteArray = Structure.getStreamAsByteArray(stream);
if (structureAsByteArray.length <= MAX_MESSAGE_SIZE) {
MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(structureAsByteArray, id, 1, 1));
} else {
final int pieces = structureAsByteArray.length / MAX_MESSAGE_SIZE;
Log.getLogger().info("BuilderTool: sending: " + pieces + " pieces with the schematic " + structureName + "(md5:" + md5 + ") to the server");
for (int i = 1; i <= pieces; i++) {
final int start = (i - 1) * MAX_MESSAGE_SIZE;
final int size;
if (i == pieces) {
size = structureAsByteArray.length - (start);
} else {
size = MAX_MESSAGE_SIZE;
}
final byte[] bytes = new byte[size];
Array.copy(structureAsByteArray, start, bytes, 0, size);
MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(bytes, id, pieces, i));
}
}
} else {
Log.getLogger().warn("BuilderTool: Can not load " + structureName);
}
} else {
Log.getLogger().warn("BuilderTool: server does not have " + serverSideName);
}
if (paste) {
MineColonies.getNetwork().sendToServer(new BuildToolPasteMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror(), complete, null));
} else {
MineColonies.getNetwork().sendToServer(new BuildToolPlaceMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror()));
}
} else {
Log.getLogger().warn("BuilderTool: Can not send schematic without md5: " + structureName);
}
}
use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.
the class WindowBuildTool method paste.
/**
* Paste a schematic in the world.
* @param complete if complete paste or partial.
*/
private void paste(final boolean complete) {
final String sname;
if (Settings.instance.isStaticSchematicMode()) {
sname = Settings.instance.getStaticSchematicName();
} else {
sname = schematics.get(schematicsDropDownList.getSelectedIndex());
}
final StructureName structureName = new StructureName(sname);
if (structureName.getPrefix().equals(Structures.SCHEMATICS_SCAN) && FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
// We need to check that the server have it too using the md5
requestScannedSchematic(structureName, true, complete);
} else {
MineColonies.getNetwork().sendToServer(new BuildToolPasteMessage(structureName.toString(), structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), structureName.isHut(), Settings.instance.getMirror(), complete, Settings.instance.getFreeMode()));
}
Settings.instance.reset();
close();
}
use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.
the class WindowBuildTool method deleteClicked.
/**
* Action performed when rename button is clicked.
*/
private void deleteClicked() {
confirmDeleteDialog = new DialogDoneCancel(getWindow());
confirmDeleteDialog.setHandler(this::onDialogClosed);
final StructureName structureName = new StructureName(schematics.get(schematicsDropDownList.getSelectedIndex()));
confirmDeleteDialog.setTitle(LanguageHandler.format("com.minecolonies.coremod.gui.structure.delete.title"));
confirmDeleteDialog.setTextContent(LanguageHandler.format("com.minecolonies.coremod.gui.structure.delete.body", structureName.toString()));
confirmDeleteDialog.open();
}
Aggregations