Skip to content

Commit fc90a88

Browse files
authored
merge
Dev
2 parents d33664a + a5c3128 commit fc90a88

75 files changed

Lines changed: 693 additions & 1130 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
# sourcecraft
1+
# sourcecraft
2+
3+
an easy to use Minecraft to Source Engine Converter.
4+
5+
### getting started:
6+
```
7+
git clone git@github.com:Garten/sourcecraft.git
8+
cd sourcecraft
9+
mvn install
10+
cd target
11+
java -jar sourcecraft-x.y.jar
12+
```

src/gui/Gui.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public String getMincraftPath() {
148148
}
149149

150150
public void setSourcePath(File file) {
151+
if (file == null) {
152+
return;
153+
}
151154
this.setupPanel.setSourcePath(file.toString());
152155
}
153156

@@ -361,6 +364,9 @@ private void initialize() {
361364
// input Panel
362365
this.inputPanel = new InputPanel();
363366
this.inputPanel.setUponContinue(() -> {
367+
if (this.inputPanel.getWorld() == null) {
368+
return;
369+
}
364370
if (this.validatePlaceIntern.run(this.inputPanel.getPlaceFromCoordinates())) {
365371
tabbedPaneFinal.setSelectedIndex(2);
366372
}

src/gui/WorldComboboxRenderer.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import java.awt.Color;
44
import java.awt.Component;
5-
import java.awt.Font;
65

7-
import javax.swing.ImageIcon;
86
import javax.swing.JLabel;
97
import javax.swing.JList;
108
import javax.swing.ListCellRenderer;
@@ -20,8 +18,6 @@ public class WorldComboboxRenderer extends JLabel implements ListCellRenderer<Ob
2018

2119
private static final Color NIMBUS_FOCUS = new Color(51, 98, 140);
2220

23-
private Font uhOhFont;
24-
2521
public WorldComboboxRenderer() {
2622
// setOpaque(true);
2723
this.setVerticalAlignment(CENTER);
@@ -33,12 +29,7 @@ public WorldComboboxRenderer() {
3329
*/
3430
@Override
3531
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
36-
// int selectedIndex = ((Integer) value).intValue();
37-
38-
// Set the icon and text. If icon was null, say so.
39-
// ImageIcon icon = images[selectedIndex];
40-
// String pet = petStrings[selectedIndex];
41-
this.setText("<no world found>");
32+
this.setText("<No Minecraft World Found>");
4233
if (value instanceof World) {
4334
World world = (World) value;
4435
this.setIcon(world.getIcon());
@@ -54,20 +45,4 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
5445

5546
return this;
5647
}
57-
58-
// Set the font and text when no image was found.
59-
protected void setUhOhText(String uhOhText, Font normalFont) {
60-
if (this.uhOhFont == null) { // lazily create this font
61-
this.uhOhFont = normalFont.deriveFont(Font.ITALIC);
62-
}
63-
this.setFont(this.uhOhFont);
64-
this.setText(uhOhText);
65-
}
66-
67-
protected static ImageIcon createImageIcon() { // TODO
68-
String path = "images//test.jpg";
69-
ImageIcon icon = new ImageIcon(path);
70-
return icon = new ImageIcon(icon.getImage()
71-
.getScaledInstance(25, 25, 0));
72-
}
7348
}

src/gui/panel/InputPanel.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ public World getWorld() {
129129
public Place getPlaceFromCoordinates() {
130130
String placeName = this.getSaveLocation();
131131
Place place = new Place(placeName);
132-
place.setWorld(this.comboBox_World.getSelectedItem()
133-
.toString());
132+
Object object = this.comboBox_World.getSelectedItem();
133+
if (object == null) {
134+
return null;
135+
}
136+
place.setWorld(object.toString());
134137
try {
135138
Position start = new Position(Integer.valueOf(this.textField_FromX.getText()), Integer.valueOf(this.textField_FromY.getText()),
136139
Integer.valueOf(this.textField_FromZ.getText()));

src/main/Converter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void convertMap(ConverterData converterData, File file) {
2727
DefaultMinecraftMapConverter map = this.getMinecraftMap(converterData);
2828
Loggger.log("Saving to " + file);
2929
try {
30-
map.write(file);
30+
map.write(file, converterData.getGame());
3131
} catch (IOException e) {
3232
Loggger.error(e.toString());
3333
}

src/main/GuiLogic.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ private void updateContinueButton() {
227227
}
228228

229229
private void informAboutTexturePack(String texturePackName) {
230-
Loggger.log(texturePackName);
231230
TexturePack texturePack = TexturePack.getTexturePack(texturePackName);
232231
boolean upToDate = Steam.areTexturesUpToDate(this.gui.getSourceGame(), texturePack);
233232
this.gui.setVisibleTextTexturesUpToDate(upToDate);

src/main/Main.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
public class Main {
1717

18-
public static final String TITLE = "Sourcecraft - Minecraft to Source converter";
19-
public static final String VERSION = "3.0";
18+
public static final String TITLE = "Sourcecraft - Minecraft to VMF converter";
19+
public static final String VERSION = "3.1";
2020
public static final String AUTHOR = "garten";
2121
public static final String LICENSE = "GNU General Public License v3.0";
2222
public static final String LICENSE_INFO = "https://www.gnu.org/licenses/gpl-3.0.html";
@@ -54,12 +54,29 @@ public Main() {
5454

5555
File output = new File(this.gui.getOutputFile());
5656
ConverterData data = this.getConverterData();
57+
if (data == null) {
58+
return;
59+
}
5760
this.converter.convert(data, output);
5861
if (data.getUpdateTextures()) {
5962
final TexturePack pack = data.getTexturePack();
6063
if (!Steam.areTexturesUpToDate(data.getGame(), pack)) {
61-
TextureFolderMover.copyFolder(pack.getFolder(), data.getGame()
62-
.getMatriealPath(pack));
64+
File targetDirectory = data.getGame()
65+
.getMatriealPath(pack);
66+
if (targetDirectory.exists()) {
67+
TextureFolderMover.copyFolder(pack.getFolder(), data.getGame()
68+
.getMatriealPath(pack));
69+
} else if (targetDirectory.getParentFile()
70+
.getParentFile()
71+
.exists()) {
72+
targetDirectory.getParentFile()
73+
.mkdir(); // Garrysmod comes without material folder
74+
TextureFolderMover.copyFolder(pack.getFolder(), data.getGame()
75+
.getMatriealPath(pack));
76+
} else {
77+
Loggger.log("Not copying textures. The directory " + targetDirectory + " does not exist. Have you launched " + data.getGame()
78+
.getLongName() + " at least once?");
79+
}
6380
}
6481
}
6582

@@ -80,6 +97,9 @@ public Main() {
8097
});
8198
}
8299

100+
/**
101+
* returns true if place has been found.
102+
*/
83103
private void saveNewPlace() {
84104
if (this.gui.getRememberPlaceSelected()) {
85105
String name = this.gui.getSaveLocation();
@@ -113,8 +133,11 @@ public ConverterData getConverterData() {
113133
ConverterData converterData = new ConverterData();
114134

115135
Place place = this.gui.getPlaceFromCoordinates();
116-
String worldName = this.gui.getWorld()
117-
.toString();
136+
World world = this.gui.getWorld();
137+
if (world == null) {
138+
return null;
139+
}
140+
String worldName = world.toString();
118141
Loggger.log("world = " + worldName);
119142
if (place == null) {
120143
Loggger.warn("Place not found");

src/main/Steam.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@
1313
public class Steam {
1414

1515
private static final String STEAM_NAME = "Steam";
16-
17-
private static final String STEAM_GAME_PATH = "SteamApps" + File.separator + "common";
16+
private static final String STEAM_NAME_UNIX = ".steam" + File.separator + "steam";
1817

1918
public static final String STEAM_GAME_PATH() {
2019
if (Main.isUnix()) {
21-
return STEAM_GAME_PATH.toLowerCase();
20+
return "steamapps" + File.separator + "common";
2221
}
23-
return STEAM_GAME_PATH;
24-
}
22+
return "SteamApps" + File.separator + "common";
23+
};
2524

2625
public static final String STEAM_SDK_PATH = "sourcesdk_content";
2726
public static final String STEAM_MAP_SRC_PATH = "mapsrc";
2827

29-
private static final String[] POTENTIAL_STEAM_PATH_GRAND_PARENTS = { "C:", "D:", "E:", "D:", "F:", File.separator };
30-
private static final String[] POTENTIAL_STEAM_PATH_PARENTS = { "Program Files", "Program Files (x86)", "Programme", };
28+
private static final String[] POTENTIAL_STEAM_PATH_GRAND_PARENTS = { "C:", "D:", "E:", File.separator };
29+
private static final String[] POTENTIAL_STEAM_PATH_PARENTS = { "Program Files", "Program Files (x86)", "Programs", "Programme" };
3130

3231
public static File getSteamPath() {
3332
File steamPath = Periphery.CONFIG.getSteamPath();
@@ -43,6 +42,12 @@ public static File getSteamPath() {
4342
}
4443

4544
private static File guessSteamPath() {
45+
if (Main.isUnix()) {
46+
File potentialPath = new File(System.getProperty("user.home") + File.separator + STEAM_NAME_UNIX);
47+
if (isSteamPath(potentialPath)) {
48+
return potentialPath;
49+
}
50+
}
4651
for (String first : POTENTIAL_STEAM_PATH_GRAND_PARENTS) {
4752
for (String second : POTENTIAL_STEAM_PATH_PARENTS) {
4853
File potentialPath = new File(first + File.separator + second + File.separator + STEAM_NAME);
@@ -92,6 +97,9 @@ public static String getHammerPath(SourceGame game) {
9297

9398
public static boolean areTexturesUpToDate(SourceGame game, TexturePack pack) {
9499
File materiaPath = game.getMatriealPath(pack);
100+
if (materiaPath == null) {
101+
return false;
102+
}
95103
Loggger.log("checking textures in " + materiaPath.toString());
96104
if (materiaPath == null || materiaPath.getParentFile()
97105
.exists() == false) {

src/minecraft/Minecraft.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ private static File getNewMinecraftPath() {
5959
return minecraftPath;
6060
}
6161

62+
public static final int MAXIMUM_HEIGHT = 256;
63+
6264
public Vector<LabeledCoordinates> getPlayerCoordinates(World world) {
6365
File file = new File(Periphery.CONFIG.getWorldPath(world), "level.dat");
6466
Vector<LabeledCoordinates> vector = new Vector<>();
@@ -78,6 +80,14 @@ public Vector<LabeledCoordinates> getPlayerCoordinates(World world) {
7880
return vector;
7981
}
8082

83+
public static File getFileOfChunk(File fileFolder, WorldPiece source) {
84+
int fileX = source.getFilePosition()
85+
.getX();
86+
int fileZ = source.getFilePosition()
87+
.getZ();
88+
return new File(fileFolder, "r." + fileX + "." + fileZ + "." + ANVIL_ENDING);
89+
}
90+
8191
public static Vector<World> getPossibleWorlds() {
8292
File file = Periphery.CONFIG.getMinceraftSavePath();
8393
String[] list = file.list();

src/minecraft/WorldPiece.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public WorldPiece(Position position, Position end, Position vmfStart) {
2424

2525
this.higher = Position.subtract(end, chunkStart);
2626
this.higher.y = end.y;
27-
// this.higher = Position.capBy(this.higher, new Position(15, 256, 15));
2827
this.higher = Position.capBelow(this.higher, new Position(Minecraft.CHUNK_SIZE_X, Minecraft.MAX_Y, Minecraft.CHUNK_SIZE_Z));
2928

3029
// local chunk position
@@ -48,13 +47,18 @@ private static final int getLowerLocalCoordinate(int value) {
4847
}
4948

5049
private ChunkPosition getFileOfChunk(ChunkPosition global) {
51-
int fileX = global.getX() / (Minecraft.MAX_CHUNK_IN_FILE_X);
52-
if (global.getX() < 0) {
53-
fileX = fileX - 1;
50+
int globalX = global.getX();
51+
int fileX, fileZ;
52+
if (globalX >= 0) {
53+
fileX = globalX / Minecraft.MAX_CHUNK_IN_FILE_X;
54+
} else {
55+
fileX = ((globalX + 1) / Minecraft.MAX_CHUNK_IN_FILE_X) - 1;
5456
}
55-
int fileZ = global.getZ() / (Minecraft.MAX_CHUNK_IN_FILE_Z);
56-
if (global.getZ() < 0) {
57-
fileZ = fileZ - 1;
57+
int globalZ = global.getZ();
58+
if (globalZ >= 0) {
59+
fileZ = globalZ / Minecraft.MAX_CHUNK_IN_FILE_Z;
60+
} else {
61+
fileZ = ((globalZ + 1) / Minecraft.MAX_CHUNK_IN_FILE_Z) - 1;
5862
}
5963
return new ChunkPosition(fileX, fileZ);
6064
}

0 commit comments

Comments
 (0)