diff options
author | Namikon <Namikon@users.noreply.github.com> | 2015-07-13 08:37:39 +0200 |
---|---|---|
committer | Namikon <Namikon@users.noreply.github.com> | 2015-07-13 08:37:39 +0200 |
commit | 8fdeea1adc6bdcbb6b97d7c828bb1f3be7854966 (patch) | |
tree | 05f80c669a86c1a661ee66abbfbc6616db391b40 /src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java | |
parent | fa1cfee96e2a1efd1e16a7a4c97137e68a5b97d6 (diff) | |
parent | a98f5609f94057d526ea889f428d46de4bd2f566 (diff) | |
download | GT5-Unofficial-8fdeea1adc6bdcbb6b97d7c828bb1f3be7854966.tar.gz GT5-Unofficial-8fdeea1adc6bdcbb6b97d7c828bb1f3be7854966.tar.bz2 GT5-Unofficial-8fdeea1adc6bdcbb6b97d7c828bb1f3be7854966.zip |
Merge pull request #1 from GTNewHorizons/dev
Diffstat (limited to 'src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java')
-rw-r--r-- | src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java b/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java new file mode 100644 index 0000000000..930b0d307c --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java @@ -0,0 +1,189 @@ +package bloodasp.galacticgreg.command; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import appeng.api.util.WorldCoord; +import appeng.items.storage.ItemSpatialStorageCell; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.auxiliary.PlayerChatHelper; +import bloodasp.galacticgreg.schematics.SpaceSchematic; +import bloodasp.galacticgreg.schematics.SpaceSchematicFactory; +import bloodasp.galacticgreg.schematics.SpaceSchematicHandler; + +/** + * This command allows to export any structure that has been stored inside a spatial storage cell + * to a xml file that can later be enabled for spawning in dimensions. + */ +public class AEStorageCommand implements ICommand { + private List aliases; + public AEStorageCommand() + { + this.aliases = new ArrayList(); + this.aliases.add("exportae"); + } + + @Override + public String getCommandName() + { + return "exportae"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) + { + return "exportae <structure name>"; + } + + @Override + public List getCommandAliases() + { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) + { + try + { + if (pCommandSender instanceof EntityPlayer) + { + if (pArgs.length < 1) + return; + + String tName = pArgs[0].toString(); + + EntityPlayer tEP = (EntityPlayer) pCommandSender; + // Check if item in hand is a spatial storage cell + ItemStack tIS = tEP.inventory.getCurrentItem(); + if (tIS.getItem() instanceof ItemSpatialStorageCell) + { + ItemSpatialStorageCell tCell = (ItemSpatialStorageCell) tIS.getItem(); + World tSpatialWorld = tCell.getWorld(tIS); + WorldCoord storedSize = tCell.getStoredSize(tIS); + + // Check if SSC is filled + if (storedSize.x == 0 || storedSize.y == 0 ||storedSize.z == 0) + { + PlayerChatHelper.SendError(pCommandSender, "Error: This spatial storage is empty"); + return; + } + + // Export structure + GalacticGreg.Logger.info("Creating Structure from Spatial AE drive. Dimensions: X [%d] Y [%d] Z [%d]", storedSize.x, storedSize.y, storedSize.z); + SpaceSchematic tSchematic = SpaceSchematicFactory.createSchematic(tName); + boolean tTEWarningSend = false; + + // Loop all 3 dimensions + for (int lX = 1; lX <= storedSize.x; lX++) { + for (int lY = 65; lY < 65 + storedSize.y; lY++) { + for (int lZ = 1; lZ <= storedSize.z; lZ++) { + + // Get the block + Block b = tSpatialWorld.getBlock(lX, lY, lZ); + // Get the meta + int bm = tSpatialWorld.getBlockMetadata(lX, lY, lZ); + + // Search for the blocks name + String tBlockName = Block.blockRegistry.getNameForObject(b); + + // Check if block is a tileentity + TileEntity bTE = tSpatialWorld.getTileEntity(lX, lY, lZ); + + String tMsg = String.format("[X-%d][Y-%d][Z-%d] ", lX, lY, lZ); + String nbtComp = ""; + // If block could be found... + if (b != null) + { + tMsg += tBlockName; + // If block is a TileEntity + if (bTE != null) + { + // Print a warning on the console + tMsg += " TE"; + GalacticGreg.Logger.warn("Warning: Found TileEntity at X[%d] Y[%d] Z[%d]. NBT States are not exported!", lX, lY, lZ); + if (!tTEWarningSend) + { + // Send a warning ingame, once per export command + tTEWarningSend = true; + PlayerChatHelper.SendWarn(pCommandSender, "TileEntity states are not exported!"); + } + + } + + // If the block is not air, add it to the structure + if (b != Blocks.air) + tSchematic.addStructureInfo(SpaceSchematicFactory.createStructureInfo(lX, lY, lZ, b, bm)); + } + } + } + } + + // Save structure to disk + if (!GalacticGreg.SchematicHandler.SaveSpaceStructure(tSchematic)) + { + // Something went wrong... + PlayerChatHelper.SendError(pCommandSender, "Something went wrong. Structure not saved"); + } + else + { + // All good, xml exported. Notify player that he needs to edit the file + PlayerChatHelper.SendInfo(pCommandSender, "Structure has been exported to " + tSchematic.getName() + ".xml. It contains " + tSchematic.coordInfo().size() + " Blocks"); + PlayerChatHelper.SendInfo(pCommandSender, "You have to edit the file before a reload will accept it!"); + } + } + else + PlayerChatHelper.SendError(pCommandSender, "Error: Item in your hand is not a spatial storage drive!"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) + { + // Command is only enabled for actual players and only if they are OP-ed + if(pCommandSender instanceof EntityPlayerMP) + { + EntityPlayerMP tEP = (EntityPlayerMP)pCommandSender; + return MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile()); + } + else + return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, + String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +}
\ No newline at end of file |