Skip to content

Commit

Permalink
Merge pull request #10 from mist475/master
Browse files Browse the repository at this point in the history
Save Schematic Location
  • Loading branch information
Dream-Master authored Jun 10, 2022
2 parents 324bed0 + 64db8c6 commit 51fb4d6
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 86 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
## Welcome to Schematica!
Planned future additions:
- Add compatibility with the Lord of the Rings mod (fix a few edge cases with the printer)
- Add the [Fairplay mode](https://www.planetminecraft.com/mod/schematica-fairplay/) to the base build script

Changes from Original:
- Store Coordinates per world/server. No more re-entering coordinates for large builds!
- README update

[Compiling Schematica](#compile-schematica) - for those that want the latest unreleased features

[Contributing](#contributing) - for those that want to help out
Expand All @@ -18,19 +26,14 @@
The Java JDK is used to compile Schematica.

1. Download and install the Java JDK.
* [Windows/Mac download link](http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html). Scroll down, accept the `Oracle Binary Code License Agreement for Java SE`, and download it (if you have a 64-bit OS, please download the 64-bit version).
* Linux: Installation methods for certain popular flavors of Linux are listed below. If your distribution is not listed, follow the instructions specific to your package manager or install it manually [here](http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html).
* Gentoo: `emerge dev-java/oracle-jdk-bin`
* Archlinux: `pacman -S jdk7-openjdk`
* Ubuntu/Debian: `apt-get install openjdk-7-jdk`
* Fedora: `yum install java-1.7.0-openjdk`
* [Download link](https://adoptium.net/temurin/releases/?version=8). Select the appropriate version for your OS
2. Set up the environment.
* Windows: Set environment variables for the JDK.
1. Go to `Control Panel\System and Security\System`, and click on `Advanced System Settings` on the left-hand side.
2. Click on `Environment Variables`.
3. Under `System Variables`, click `New`.
4. For `Variable Name`, input `JAVA_HOME`.
5. For `Variable Value`, input something similar to `C:\Program Files\Java\jdk1.7.0_45` exactly as shown (or wherever your Java JDK installation is), and click `Ok`.
5. For `Variable Value`, input something similar to `C:\Program Files\Java\8u332` exactly as shown (or wherever your Java JDK installation is), and click `Ok`.
6. Scroll down to a variable named `Path`, and double-click on it.
7. Append `;%JAVA_HOME%\bin` EXACTLY AS SHOWN and click `Ok`. Make sure the location is correct; double-check just to make sure.
3. Open up your command line and run `javac`. If it spews out a bunch of possible options and the usage, then you're good to go. If not try the steps again.
Expand All @@ -42,6 +45,11 @@ Git is used to clone Schematica and update your local copy.
2. *Optional* Download and install a Git GUI client, such as Github for Windows/Mac, SmartGitHg, TortoiseGit, etc. A nice list is available [here](http://git-scm.com/downloads/guis).

#### Setup Schematica

##### IntelliJ
Import this repository. or, if you're planning modifications, a fork. IntelliJ will automatically execute the `gradlew setupDevWorkspace` task. After that there's a high chance the following error is thrown: `Could not find :forgeBin:1.7.10-10.13.4.1614-1.7.10.` or something similar. If that happens, execute `./gradlew setupDecompWorkspace` in your terminal. After this refresh gradle, and you should be ready to go.

##### Command line
This section assumes that you're using the command-line version of Git.

1. Open up your command line.
Expand All @@ -56,6 +64,8 @@ This section assumes that you're using the command-line version of Git.
***

#### Compile Schematica

If you use IntelliJ IDEA you can skip step one
1. Execute `gradlew setupDevWorkspace`. This sets up Forge and downloads the necessary libraries to build Schematica. This might take some time, be patient.
* You will generally only have to do this once until the Forge version in `build.properties` changes.
2. Execute `gradlew build`. If you did everything right, `BUILD SUCCESSFUL` will be displayed after it finishes. This should be relatively quick.
Expand Down Expand Up @@ -97,7 +107,7 @@ When you finish up your PR you'll want to [squash](http://davidwalsh.name/squash
2. Execute `git rebase -i HEAD~X` where `X` is the amount of your commits. This will make sure you squash only your own commits.
3. You should now see a list of all your commits, prefixed with `pick`. Change all instances of `pick` (excluding the first!) into `squash` or simply `s`. Then save/quit the editor once.
4. A second screen should show up, displaying all the commit messages (you may edit them, delete or add some). After your done save/quit the editor again.
5. If git successfuly rebased things simply push your cleaned up commits by executing `git push -f`.
5. If git successfully rebased things simply push your cleaned up commits by executing `git push -f`.

#### Creating an Issue
Crashing? Have a suggestion? Found a bug? Create an issue now!
Expand All @@ -112,4 +122,4 @@ Crashing? Have a suggestion? Found a bug? Create an issue now!
* Detailed description of the bug
5. Click `Submit new issue`, and wait for feedback!

Shamelessly based this README off [pahimar's version](https://github.com/pahimar/Equivalent-Exchange-3).
Shamelessly based off this README off [pahimar's version](https://github.com/pahimar/Equivalent-Exchange-3).
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import com.github.lunatrius.schematica.proxy.ClientProxy;
import com.github.lunatrius.schematica.reference.Constants;
import com.github.lunatrius.schematica.reference.Names;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatComponentText;

import static com.github.lunatrius.schematica.client.util.WorldServerName.worldServerName;

public class GuiSchematicControl extends GuiScreenBase {
private final SchematicWorld schematic;
Expand All @@ -37,6 +41,11 @@ public class GuiSchematicControl extends GuiScreenBase {
private GuiButton btnMaterials = null;
private GuiButton btnPrint = null;

private GuiButton btnSaveCoordinates = null;

private final String strSaveCoordinatesSuccess = I18n.format(Names.Chat.SAVE_COORDINATES_SUCCESS);
private final String strSaveCoordinatesFail = I18n.format(Names.Chat.SAVE_COORDINATES_FAIL);
private final String strSaveCoordinates = I18n.format(Names.Gui.Control.SAVE_COORDINATES);
private final String strMoveSchematic = I18n.format(Names.Gui.Control.MOVE_SCHEMATIC);
private final String strOperations = I18n.format(Names.Gui.Control.OPERATIONS);
private final String strUnload = I18n.format(Names.Gui.Control.UNLOAD);
Expand Down Expand Up @@ -103,6 +112,9 @@ public void initGui() {
this.btnPrint = new GuiButton(id++, 10, this.height - 30, 80, 20, this.printer.isPrinting() ? this.strOn : this.strOff);
this.buttonList.add(this.btnPrint);

this.btnSaveCoordinates = new GuiButton(id++, this.centerX - 50, this.centerY + 45, 100, 20, this.strSaveCoordinates);
this.buttonList.add(this.btnSaveCoordinates);

this.numericX.setEnabled(this.schematic != null);
this.numericY.setEnabled(this.schematic != null);
this.numericZ.setEnabled(this.schematic != null);
Expand All @@ -119,6 +131,8 @@ public void initGui() {
this.btnMaterials.enabled = this.schematic != null;
this.btnPrint.enabled = this.schematic != null && this.printer.isEnabled();

this.btnSaveCoordinates.enabled = this.schematic != null;

setMinMax(this.numericX);
setMinMax(this.numericY);
setMinMax(this.numericZ);
Expand Down Expand Up @@ -191,6 +205,17 @@ protected void actionPerformed(GuiButton guiButton) {
} else if (guiButton.id == this.btnPrint.id && this.printer.isEnabled()) {
boolean isPrinting = this.printer.togglePrinting();
this.btnPrint.displayString = isPrinting ? this.strOn : this.strOff;
} else if (guiButton.id == this.btnSaveCoordinates.id) {
String worldServerName = worldServerName(this.mc);
//Reference.logger.info("Saved coordinates, stored data:\nCoordinates: {} {} {}\nSchematic Name: {}\nWorld Name/server Name: {}", this.numericX.getValue(), this.numericY.getValue(), this.numericZ.getValue(), this.schematic.name, worldServerName);
EntityPlayerSP player = mc.thePlayer;
if (player != null) {
if (ClientProxy.addCoordinates(worldServerName, this.schematic.name, this.numericX.getValue(), this.numericY.getValue(), this.numericZ.getValue())) {
mc.thePlayer.addChatMessage(new ChatComponentText(strSaveCoordinatesSuccess));
} else {
mc.thePlayer.addChatMessage(new ChatComponentText(strSaveCoordinatesFail));
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.Sys;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import static com.github.lunatrius.schematica.client.util.WorldServerName.worldServerName;

public class GuiSchematicLoad extends GuiScreenBase {
private static final FileFilterSchematic FILE_FILTER_FOLDER = new FileFilterSchematic(true);
private static final FileFilterSchematic FILE_FILTER_SCHEMATIC = new FileFilterSchematic(false);

private GuiSchematicLoadSlot guiSchematicLoadSlot;

private GuiButton btnOpenDir = null;
private GuiButton btnDone = null;

protected final List<GuiSchematicEntry> schematicFiles = new ArrayList<GuiSchematicEntry>();
private final String strTitle = I18n.format(Names.Gui.Load.TITLE);
private final String strFolderInfo = I18n.format(Names.Gui.Load.FOLDER_INFO);

protected File currentDirectory = ConfigurationHandler.schematicDirectory;
protected final List<GuiSchematicEntry> schematicFiles = new ArrayList<GuiSchematicEntry>();
private GuiSchematicLoadSlot guiSchematicLoadSlot;
private GuiButton btnOpenDir = null;
private GuiButton btnDone = null;

public GuiSchematicLoad(GuiScreen guiScreen) {
super(guiScreen);
Expand Down Expand Up @@ -114,7 +113,8 @@ protected void reloadSchematics() {
this.schematicFiles.clear();

try {
if (!this.currentDirectory.getCanonicalPath().equals(ConfigurationHandler.schematicDirectory.getCanonicalPath())) {
if (!this.currentDirectory.getCanonicalPath()
.equals(ConfigurationHandler.schematicDirectory.getCanonicalPath())) {
this.schematicFiles.add(new GuiSchematicEntry("..", Items.lava_bucket, 0, true));
}
} catch (IOException e) {
Expand Down Expand Up @@ -160,7 +160,12 @@ private void loadSchematic() {
if (Schematica.proxy.loadSchematic(null, this.currentDirectory, schematicEntry.getName())) {
SchematicWorld schematic = ClientProxy.schematic;
if (schematic != null) {
ClientProxy.moveSchematicToPlayer(schematic);
ImmutablePair<Boolean, ImmutableTriple<Integer, Integer, Integer>> schematicCoordinate = ClientProxy.getCoordinates(worldServerName(this.mc), schematic.name);
if (schematicCoordinate.left) {
ClientProxy.moveSchematic(schematic, schematicCoordinate.right.left, schematicCoordinate.right.middle, schematicCoordinate.right.right);
} else {
ClientProxy.moveSchematicToPlayer(schematic);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ private boolean isBlacklisted(Block block, ItemStack itemStack) {
return true;
}

//TODO: LOTR mod chisel, plates, weapon racks

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.lunatrius.schematica.client.util;

import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.client.Minecraft;

public class WorldServerName {
/**
* Gets the world name if in singleplayer, or the name in server list when in multiplayer
* @param mc {@link Minecraft}
* @return {@link String} world name or server name
*/
public static String worldServerName(Minecraft mc) {
String WorldOrServerName;
if (mc.isSingleplayer()) {
WorldOrServerName = FMLCommonHandler.instance().getMinecraftServerInstance().getWorldName();
} else {
//Gets the server data, only works if you're playing on a server. if you're using direct connect the name will be "Minecraft Server". Crashes if singleplayer
WorldOrServerName = mc.func_147104_D().serverName;
}
return WorldOrServerName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class SchematicWorld extends World {
private static final WorldSettings WORLD_SETTINGS = new WorldSettings(0, WorldSettings.GameType.CREATIVE, false, false, WorldType.FLAT);

public String name = "";
public static final ItemStack DEFAULT_ICON = new ItemStack(Blocks.grass);

private ISchematic schematic;
Expand All @@ -50,6 +51,10 @@ public SchematicWorld(ISchematic schematic) {
this.isRenderingLayer = false;
this.renderingLayer = 0;
}
public SchematicWorld(ISchematic schematic, String filename) {
this(schematic);
this.name = filename.replace(".schematic","");
}

@Override
public Block getBlock(int x, int y, int z) {
Expand Down
Loading

0 comments on commit 51fb4d6

Please sign in to comment.