Skip to content

Commit

Permalink
adjusting package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Garten committed May 14, 2020
1 parent 96a2da4 commit fca42c7
Show file tree
Hide file tree
Showing 98 changed files with 751 additions and 1,091 deletions.
3 changes: 1 addition & 2 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
eclipse.preferences.version=1
encoding//src/source/MaterialCodeGenerator.java=UTF-8
encoding//src/source/MaterialLegacy.java=UTF-8
encoding//src/minecraft/MaterialLegacy.java=UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.IOException;

public interface RunnableThrowing {
public interface IORunnable {

public abstract void run() throws IOException;
}
4 changes: 4 additions & 0 deletions src/basic/Loggger.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ private static void addTabs(StringBuilder stringBuilder) {
stringBuilder.append("\t");
}
}

public static void breakk() {
Loggger.log("broken");
}
}
32 changes: 16 additions & 16 deletions src/basic/RunnableWith.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package basic;

import periphery.Place;

public interface RunnableWith<Argument> {

public static final RunnableWith<String> INSTANCE = argument -> {
// do nothing
};

public static final RunnableWith<Place> INSTANCE_PLACE = argument -> {
// do nothing
};

public abstract void run(Argument argument);
}
//package basic;
//
//import periphery.Place;
//
//public interface RunnableWith<Argument> {
//
// public static final RunnableWith<String> INSTANCE = argument -> {
// // do nothing
// };
//
// public static final RunnableWith<Place> INSTANCE_PLACE = argument -> {
// // do nothing
// };
//
// public abstract void run(Argument argument);
//}
32 changes: 16 additions & 16 deletions src/main/Converter.java → src/converter/Converter.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main;
package converter;

import java.io.DataInputStream;
import java.io.File;
Expand All @@ -8,32 +8,32 @@

import basic.Loggger;
import basic.Tuple;
import converter.mapper.BlockMapper;
import main.ConvertTask;
import minecraft.Area;
import minecraft.ChunkPosition;
import minecraft.McaSection;
import minecraft.Minecraft;
import minecraft.Position;
import minecraft.WorldPiece;
import minecraft.map.BlockConverterContext;
import minecraft.map.DefaultSourceMap;
import minecraft.reader.RegionFile;
import minecraft.reader.nbt.McaReader;
import minecraft.reader.nbt.PlayerInLevelReader;
import minecraft.reader.nbt.PlayerReader;
import nbtReader.ChunkPosition;
import nbtReader.ChunkReader;
import nbtReader.Section;
import nbtReader.PlayerInLevelReader;
import nbtReader.PlayerReader;
import nbtReader.RegionFile;
import nbtReader.WorldPiece;
import periphery.Minecraft;
import periphery.Place;
import source.SkinManager;
import vmfWriter.DefaultSourceMap;

public class Converter {

private ConvertTask converterData;

private BlockConverterContext blockContent;
private BlockMapper blockContent;

public Converter(ConvertTask converterData) {
this.converterData = converterData;
DefaultSourceMap target = new DefaultSourceMap(converterData.getTexturePack(), converterData.getOption()
.getScale());
this.blockContent = new BlockConverterContext(converterData, target);
this.blockContent = new BlockMapper(converterData, target);
}

public Converter open(File fileFolder, ConvertTask converterData) throws IOException {
Expand Down Expand Up @@ -77,13 +77,13 @@ public void readChunk(File fileFolder, WorldPiece worldPiece, Position writeTarg
Loggger.log("cannot find chunk file " + file.toString());
} else {
// Create NBTReader for chunk.
McaReader reader = new McaReader(inputStream, this, worldPiece);
ChunkReader reader = new ChunkReader(inputStream, this, worldPiece);
reader.readChunk();
inputStream.close();
}
}

public void addMcaSection(McaSection section) {
public void addMcaSection(Section section) {
// TODO sections occur that with negative volume
Tuple<Area, Position> toWrite = section.getBoundAndTarget();
Position target = toWrite.getSecond();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package minecraft;
package converter;

public class ConvertingReport {

Expand Down
63 changes: 37 additions & 26 deletions src/source/SkinManager.java → src/converter/SkinManager.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package source;
package converter;

import java.util.function.Supplier;

import basic.Loggger;
import converter.actions.BlockMap;
import minecraft.Block;
import minecraft.Blocks;
import minecraft.Material;
import minecraft.MaterialLegacy;
import minecraft.Texture;
import periphery.TexturePack;
import source.addable.BlockMap;
import vmfWriter.Orientation;
import vmfWriter.Skin;

Expand Down Expand Up @@ -39,12 +40,20 @@ public Skin setSourceSkin(String texture) {
return new Skin(texture, this.textureScale);
}

public Skin createSkin(String texture) {
return new Skin(this.folder + texture, this.textureScale);
public Skin createSkin(String main) {
return new Skin(this.folder + main, this.textureScale);
}

public Skin createSkin(String main, String topBottom) {
return new Skin(this.folder + main, this.folder + topBottom, this.textureScale);
public Skin createSkin(Texture main, Texture topBottom) {
return new Skin(this.folder + main.name(), this.folder + topBottom.name(), this.textureScale);
}

public Skin createSkin(String texture, String topBottom) {
return new Skin(this.folder + texture, this.folder + topBottom, this.textureScale);
}

private Skin createSkinTopBottom(Texture side, Texture top, Texture bottom) {
return this.createSkinTopBottom(side.name(), top.name(), bottom.name());
}

private Skin createSkinTopBottom(String main, String top, String bottom) {
Expand Down Expand Up @@ -131,25 +140,30 @@ public void init(String folder, int textureSizeNew, int scale) {
this.textureScale = ((double) scale) / ((double) textureSizeNew);
this.folder = folder + "/";
this.skins = new BlockMap<Skin>().setDefault(new Skin(DEFAULT_TEXTURE, this.textureScale));
// set based on matching texture name
for (Texture texture : Texture.values()) {
this.put(texture);
String name = texture.name();
}

// set based on common
for (Material material : Material.values()) {
String name = material.name();
if (name.endsWith("_log")) { // except dark oak
String textureName = "log_" + name.substring(0, name.length() - "_log".length()) + "_top";
this.put(material, textureName);
String textureName = "log_" + name.substring(0, name.length() - "_log".length());
this.put(material, this.createSkin(textureName, textureName + "_top"));
} else if (this.putPrefixMadeSuffix(material, Material._leaves)) {

} else if (this.putPrefixMadeSuffix(material, Material._planks)) {

} else if (this.putPrefixMadeSuffix(material, Material._wool)) {

} else if (this.putPrefixMadeSuffix(material, Material._stained_glass)) {

}
}
// exceptions
this.put(Material.dark_oak_log, this.createSkin(Texture.log_big_oak, Texture.log_big_oak_top));
this.put(Material.dark_oak_leaves, Texture.leaves_big_oak);
this.put(Material.dark_oak_planks, Texture.planks_big_oak);

// material-prefixe
this.put(Material.andesite, Texture.stone_andesite);
this.put(Material.diorite, Texture.stone_diorite);
this.put(Material.granite, Texture.stone_granite);
Expand All @@ -172,32 +186,29 @@ public void init(String folder, int textureSizeNew, int scale) {
this.put(Material.dark_oak_, Texture.planks_big_oak); // except log, door, ..
this.put(Material.spruce_, Texture.planks_spruce);
this.put(Material.acacia_, Texture.planks_acacia);
// exceptsion wood
// exceptions

// other material
this.put(Material.grass_block, this.createSkinTopBottom(Texture.grass_side, Texture.grass_top, Texture.dirt));

// special
this.skins.put(Blocks.get("sourcecraft:ramp"), PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._PLAYER_CLIP, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_NORTH, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_EAST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_SOUTH, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_WEST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_NORTH_EAST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_NORTH_WEST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_SOUTH_EAST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._RAMP_SOUTH_WEST, PLAYER_CLIP);
// this.setSourceSkinOld(MaterialLegacy._UNKOWN, DEFAULT_TEXTURE);
}

private void put(Texture block) {
this.put(block, block);
}

private void put(Supplier<Block> block, Texture texture) {
this.put(block, texture.name());
this.put(block, this.createSkin(texture.name()));
}

private void put(Supplier<Block> block, String texture) {
this.put(block, this.createSkin(texture));
}

private void put(Supplier<Block> block, String name) {
this.skins.put(block, this.createSkin(name));
private void put(Supplier<Block> block, Skin skin) {
this.skins.put(block, skin);
}

public void initLegacy(String folder, int textureSizeNew, int scale) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package source.addable;
package converter.actions;

import java.util.LinkedList;
import java.util.List;

import basic.Loggger;
import converter.mapper.Mapper;
import minecraft.Block;
import minecraft.Position;
import minecraft.map.ConverterContext;
import vmfWriter.Orientation;
import vmfWriter.entity.pointEntity.RotateablePointEntity;

public abstract class ConvertAction {
public abstract class Action {

protected int[] materialUsedFor = {};

public ConvertAction() {
public Action() {
}

public Iterable<ConvertAction> getInstances() {
List<ConvertAction> list = new LinkedList<>();
public Iterable<Action> getInstances() {
List<Action> list = new LinkedList<>();
try {
ConvertAction a = (ConvertAction) this.getClass()
Action a = (Action) this.getClass()
.getConstructors()[0].newInstance();
list.add(a);
} catch (Exception ex) {
Expand Down Expand Up @@ -60,18 +60,16 @@ public void setMaterialUsedFor(int material) {
* For a given position with given material, this method adds solids and
* entities to the resulting Source map.
*
* @param position
* @param material
*/
public void add(ConverterContext context, Position position, Block material) {
public void add(Mapper context, Position position, Block material) {

}

protected void addDebugMarker(ConverterContext context, Position position, Block material) {
protected void addDebugMarker(Mapper context, Position position, Block material) {
context.setPointToGrid(position);
context.movePointInGridDimension(0.5, 0, 0.5);
int verticalAngle = (int) (Math.random() * 360);
context.addPointEntity(new RotateablePointEntity().setName(material.getName())
context.addPointEntity(new RotateablePointEntity().setName(material.getName() + " at " + position.toString())
.setRotation(verticalAngle));
context.markAsConverted(position);
}
Expand Down
44 changes: 44 additions & 0 deletions src/converter/actions/ActionManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package converter.actions;

import basic.Tuple;
import converter.actions.actions.NoAction;
import converter.mapper.Mapper;
import minecraft.Block;
import minecraft.Position;

public class ActionManager {

protected BlockMap<Action> actions;

public ActionManager(Action fallBack) {
this.actions = new BlockMap<Action>().setDefault(fallBack);
}

public ActionManager setAction(Block block, Action addable) {
this.actions.put(block, addable);
return this;
}

public ActionManager setActions(Iterable<Tuple<Block, Action>> actions) {
actions.forEach(a -> this.setAction(a.getFirst(), a.getSecond()));
return this;
}

public Action getAction(Block block) {
return this.actions.getFallBackToSuffix(block);
}

public void add(Mapper context, Position position, Block block) {
Action action;
if (block == null) {
action = NoAction.INSTANCE;
} else {
action = this.getAction(block);
}
action.add(context, position, block);
}

public void print() {
actions.print();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package source.addable;
package converter.actions;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -55,6 +55,10 @@ public Value getFallBackToPrefix(Block key) {
}

public Value getFallBackToSuffix(Block key) {
if (key.getName()
.equals("minecraft:grindstone")) {
// Loggger.breakk();
}
Value result = this.getFallBackNoProperties(key);
if (result != null) {
return result;
Expand Down Expand Up @@ -109,4 +113,8 @@ public BlockMap<Value> setDefault(Value fallback) {
this.fallback = fallback;
return this;
}

public void print() {
this.map.forEach((key, value) -> Loggger.log(key.toString() + " mapsTo " + value.toString()));
}
}
Loading

0 comments on commit fca42c7

Please sign in to comment.