├── .classpath ├── .github └── workflows │ └── maven.yml ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs └── org.eclipse.m2e.core.prefs ├── LICENSE ├── README.md ├── pom.xml └── src ├── basic ├── IOConsumer.java ├── IORunnable.java ├── Loggger.java ├── NameSupplier.java ├── RunnableWith.java ├── Tuple.java ├── Validator.java └── Value.java ├── converter ├── Converter.java ├── ConvertingReport.java ├── Skins.java ├── actions │ ├── Action.java │ ├── ActionManager.java │ ├── BlockMap.java │ ├── ConvertEntity.java │ ├── CustomActionManager.java │ └── actions │ │ ├── Cactus.java │ │ ├── CenteredPointEntity.java │ │ ├── CssLamp.java │ │ ├── Debug.java │ │ ├── DetailBlock.java │ │ ├── EndPortalFrame.java │ │ ├── Fence.java │ │ ├── Fire.java │ │ ├── LilypadTf2.java │ │ ├── Liquid.java │ │ ├── NoAction.java │ │ ├── Pane.java │ │ ├── PlayerSpawnCss.java │ │ ├── PlayerSpawnTf2.java │ │ ├── SlabBottom.java │ │ ├── SlabTop.java │ │ ├── SnowBlock.java │ │ ├── Solid.java │ │ ├── Stairs.java │ │ ├── SupplyTf2.java │ │ ├── TallGrassTf2.java │ │ ├── Torch.java │ │ ├── TorchEast.java │ │ ├── TorchNorth.java │ │ ├── TorchSouth.java │ │ ├── TorchWest.java │ │ ├── VinesEast.java │ │ ├── VinesNorth.java │ │ ├── VinesSouth.java │ │ └── VinesWest.java ├── cuboidFinder │ ├── CuboidFinder.java │ └── DefaultCuboidFinder.java └── mapper │ ├── BlockMapper.java │ ├── Mapper.java │ ├── SourceMapper.java │ └── SubblockMapper.java ├── gui ├── Gui.java ├── SimpleTextFieldChangeListener.java ├── WorldComboboxRenderer.java └── panel │ ├── DetailsPanel.java │ ├── InputPanel.java │ ├── LabeledCoordinates.java │ ├── OutputPanel.java │ ├── ResultPanel.java │ └── SetupPanel.java ├── main ├── ConvertTask.java ├── GuiLogic.java ├── Main.java └── TextureFolderMover.java ├── minecraft ├── Area.java ├── Block.java ├── BlockTemplate.java ├── Blocks.java ├── Material.java ├── MaterialLegacy.java ├── MinecraftMap.java ├── Position.java ├── Property.java ├── SubBlockPosition.java ├── Texture.java └── World.java ├── nbtReader ├── BitNbtReader.java ├── ChunkPosition.java ├── ChunkReader.java ├── NamedTag.java ├── NbtReader.java ├── NbtTag.java ├── NbtTasks.java ├── PlayerInLevelReader.java ├── PlayerPositionReader.java ├── PlayerReader.java ├── RegionFile.java ├── Section.java └── WorldPiece.java ├── periphery ├── Config.java ├── ConfigIO.java ├── ConvertOption.java ├── DirectoryFilter.java ├── Minecraft.java ├── Periphery.java ├── Place.java ├── Places.java ├── SourceGame.java ├── Steam.java ├── TextureOptions.java └── TexturePack.java └── vmfWriter ├── Angles.java ├── Color.java ├── Counter.java ├── Cuboid.java ├── DefaultSourceMap.java ├── EightPoint.java ├── Free8Point.java ├── Orientation.java ├── Ramp.java ├── Skin.java ├── Solid.java ├── SourceMap.java ├── ValveElement.java ├── ValveWriter.java ├── entity ├── Entity.java ├── Tf2Team.java ├── pointEntity │ ├── NamedPointEntity.java │ ├── PointEntity.java │ ├── PointEntityNameException.java │ ├── RotateablePointEntity.java │ └── pointEntity │ │ ├── CustomPointEntity.java │ │ ├── EnvFire.java │ │ ├── InfoParticleSystem.java │ │ ├── InfoPlayerCT.java │ │ ├── InfoPlayerStart.java │ │ ├── InfoPlayerT.java │ │ ├── InfoPlayerTeamSpawn.java │ │ ├── Light.java │ │ ├── LightEnvironment.java │ │ ├── NamedRotateablePointEntity.java │ │ ├── PropDynamic.java │ │ ├── PropStatic.java │ │ └── ShadowControl.java └── solidEntity │ ├── BombTarget.java │ ├── Buyzone.java │ ├── FuncDetail.java │ ├── FuncIllusionary.java │ ├── FuncRegenerate.java │ └── SolidEntity.java └── texture ├── ValveTexture.java └── VmtGenerator.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - name: Build with Maven 24 | run: mvn -B package --file pom.xml 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | target/* 26 | textures/* 27 | *.json 28 | .metadata -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sourcecraft 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/minecraft/MaterialLegacy.java=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sourcecraft 2 | 3 | an easy to use Minecraft to Source Engine Converter. It converts a given piece of Minecraft World into a map in .vmf-format that can be opened by Hammer Editor. It still needs to be compiled by Hammer Editor (/the Source-Engine compile tools). Aim of this project though is that no further steps or Hammer-Editor editing skills are needed. That is sourcecraft createas a (after compiling) a runnable and playable map with spawn-points and so on. 4 | 5 | ### what is needed 6 | - Minecraft world of version 1.13 or newer (tested with 1.15) either created in singleplayer or by a Minecraft server. 7 | - Java Runtime Enviroment 1.8 or newer 8 | - Recommended: Steam with installed target Source-Engine game and installed 'Source SDK'. The latter includes the Hammer Editor and the compile tools. You should have launched your target game and 'Source SDK' for your target game at least once. Then sourcecraft suggets to create the output-map at the correct path for the Hammer Editor. It can also copy the required textures to the correct path. 9 | 10 | ### textures 11 | Sourcecraft creates the map with texture names equal to that used in minecraft. Suitable minecraft-like textures are not included here, but can be found online. If you put them into the "texture/" folder, sourcecraft makes sure that a copy is at the correct directory needed for the Hammer Editor (unlesss you wish otherwise). 12 | 13 | ### hammer editor 14 | You can launch Hammer Editor directly from sourcecraft (alternatively you may launch it via Steam). Open the coverted .vmf-file via 'File->Open'. You may further edit your map here. By pressing F9 you open the compile dialog. For a first test, you should select for "Run VIS" the option "Fast". It is also better to check not to launch the game after compiling. Instead launch your target game manually with launch option "-console". Ingame you can open your map with the console command "map my-map-name". 15 | 16 | 17 | ### manual setup: 18 | ``` 19 | git clone git@github.com:Garten/sourcecraft.git 20 | cd sourcecraft 21 | mvn install 22 | cd target 23 | java -jar sourcecraft-x.y.jar 24 | ``` 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | sourcecraft 6 | sourcecraft 7 | 3.2 8 | jar 9 | 10 | src 11 | 12 | 13 | maven-compiler-plugin 14 | 3.8.0 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-dependency-plugin 23 | 24 | 25 | copy-dependencies 26 | prepare-package 27 | 28 | copy-dependencies 29 | 30 | 31 | 32 | ${project.build.directory}/libs 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-jar-plugin 41 | 3.2.0 42 | 43 | 44 | 45 | true 46 | libs/ 47 | 48 | main.Main 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | com.google.code.gson 59 | gson 60 | 2.8.6 61 | 62 | 63 | com.google.guava 64 | guava 65 | 29.0-jre 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/basic/IOConsumer.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import java.io.IOException; 4 | 5 | public interface IOConsumer { 6 | 7 | public static final IOConsumer INSTANCE = argument -> { 8 | // do nothing 9 | }; 10 | 11 | public abstract void run(Argument argument) throws IOException; 12 | } 13 | -------------------------------------------------------------------------------- /src/basic/IORunnable.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import java.io.IOException; 4 | 5 | public interface IORunnable { 6 | 7 | public abstract void run() throws IOException; 8 | } 9 | -------------------------------------------------------------------------------- /src/basic/Loggger.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | public class Loggger { 4 | 5 | private static final int TAB_SIZE = 8; 6 | private static final int DEFAULT_INDENT = 1 * TAB_SIZE; 7 | private static int minimalIndent = DEFAULT_INDENT; 8 | 9 | public static void debug(String message) { 10 | print(message, 0); 11 | } 12 | 13 | public static void log(String message) { 14 | print(message, 0); 15 | } 16 | 17 | public static void logg(String message) { 18 | print(message, 1); 19 | } 20 | 21 | public static void log(String message, int callDepth) { 22 | 23 | } 24 | 25 | public static void warn(String message) { 26 | print(message, 0); 27 | } 28 | 29 | public static void error(String message) { 30 | print(message, 0); 31 | } 32 | 33 | public static void maybeLog(String message) { 34 | if (Math.random() < 0.1f) { 35 | print(message, 0); 36 | } 37 | } 38 | 39 | public static void print(String mesasge, int callDepth) { 40 | StringBuilder stringBuilder = new StringBuilder(); 41 | addCallLocation(stringBuilder, callDepth); 42 | adjustMinimalIndent(stringBuilder); 43 | addTabs(stringBuilder); 44 | stringBuilder.append(mesasge); 45 | System.out.println(stringBuilder.toString()); 46 | } 47 | 48 | private static final int EXPECTED_STACK_DEPTH = 4; 49 | 50 | private static void addCallLocation(StringBuilder stringBuilder, int additonalCallDepth) { 51 | int callDepth = EXPECTED_STACK_DEPTH + additonalCallDepth; 52 | StackTraceElement[] elements = Thread.currentThread() 53 | .getStackTrace(); 54 | if (elements.length >= callDepth) { 55 | StackTraceElement element = elements[callDepth]; 56 | String text = "(" + element.getFileName() + ":" + element.getLineNumber() + ")"; 57 | stringBuilder.append(text); 58 | } 59 | } 60 | 61 | private static void adjustMinimalIndent(StringBuilder stringBuilder) { 62 | while (minimalIndent < stringBuilder.length() + 1) { 63 | minimalIndent += TAB_SIZE; 64 | } 65 | } 66 | 67 | private static void addTabs(StringBuilder stringBuilder) { 68 | int blankLength = minimalIndent - stringBuilder.length(); 69 | while (blankLength > 0) { 70 | blankLength -= TAB_SIZE; 71 | stringBuilder.append("\t"); 72 | } 73 | } 74 | 75 | public static void breakk() { 76 | Loggger.log("broken"); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/basic/NameSupplier.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | public interface NameSupplier { 4 | 5 | public abstract String name(); 6 | 7 | default String getName() { 8 | String name = this.name(); 9 | if (name.endsWith("$")) { 10 | return name.substring(0, name.length() - 1); 11 | } 12 | return name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/basic/RunnableWith.java: -------------------------------------------------------------------------------- 1 | //package basic; 2 | // 3 | //import periphery.Place; 4 | // 5 | //public interface RunnableWith { 6 | // 7 | // public static final RunnableWith INSTANCE = argument -> { 8 | // // do nothing 9 | // }; 10 | // 11 | // public static final RunnableWith INSTANCE_PLACE = argument -> { 12 | // // do nothing 13 | // }; 14 | // 15 | // public abstract void run(Argument argument); 16 | //} 17 | -------------------------------------------------------------------------------- /src/basic/Tuple.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | public class Tuple { 4 | 5 | private A first; 6 | private B second; 7 | 8 | public Tuple(A first, B second) { 9 | this.first = first; 10 | this.second = second; 11 | } 12 | 13 | public A getFirst() { 14 | return this.first; 15 | } 16 | 17 | public B getSecond() { 18 | return this.second; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/basic/Validator.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import periphery.Place; 4 | 5 | public interface Validator { 6 | 7 | public static final Validator PLACE_ACCEPTOR = argument -> true; 8 | 9 | public abstract boolean run(Argument argument); 10 | } 11 | -------------------------------------------------------------------------------- /src/basic/Value.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | public class Value { 4 | 5 | private T value; 6 | 7 | public Value set(T value) { 8 | this.value = value; 9 | return this; 10 | } 11 | 12 | public T get() { 13 | return this.value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/converter/ConvertingReport.java: -------------------------------------------------------------------------------- 1 | package converter; 2 | 3 | public class ConvertingReport { 4 | 5 | private int brushCount; 6 | 7 | public ConvertingReport() { 8 | 9 | } 10 | 11 | public int getBrushCount() { 12 | return this.brushCount; 13 | } 14 | 15 | public void setBrushCount(int brushCount) { 16 | this.brushCount = brushCount; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/converter/actions/Action.java: -------------------------------------------------------------------------------- 1 | package converter.actions; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import basic.Loggger; 7 | import converter.mapper.Mapper; 8 | import minecraft.Block; 9 | import minecraft.Position; 10 | import vmfWriter.Orientation; 11 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 12 | 13 | public abstract class Action { 14 | 15 | protected int[] materialUsedFor = {}; 16 | 17 | public Action() { 18 | } 19 | 20 | public Iterable getInstances() { 21 | List list = new LinkedList<>(); 22 | try { 23 | Action a = (Action) this.getClass() 24 | .getConstructors()[0].newInstance(); 25 | list.add(a); 26 | } catch (Exception ex) { 27 | Loggger.warn("Addable " + this.getClass() 28 | .getSimpleName() + " does not have a suitable constructor (InvocationTargetException)"); 29 | } 30 | return list; 31 | } 32 | 33 | public String getName() { 34 | return this.getClass() 35 | .getSimpleName(); 36 | } 37 | 38 | /** 39 | * Returns whether the added blocks are air. 40 | */ 41 | public boolean isAirBlock() { 42 | return true; 43 | } 44 | 45 | public boolean hasWall(Orientation orientation) { 46 | return false; 47 | } 48 | 49 | @Deprecated 50 | public void setMaterialUsedFor(int[] material) { 51 | this.materialUsedFor = material; 52 | } 53 | 54 | public void setMaterialUsedFor(int material) { 55 | this.materialUsedFor = new int[1]; 56 | this.materialUsedFor[0] = material; 57 | } 58 | 59 | /** 60 | * For a given position with given material, this method adds solids and 61 | * entities to the resulting Source map. 62 | * 63 | */ 64 | public void add(Mapper context, Position position, Block material) { 65 | 66 | } 67 | 68 | protected void addDebugMarker(Mapper context, Position position, Block material) { 69 | context.setPointToGrid(position); 70 | context.movePointInGridDimension(0.5, 0, 0.5); 71 | int verticalAngle = (int) (Math.random() * 360); 72 | context.addPointEntity(new RotateablePointEntity().setName(material.getName() + " at " + position.toString()) 73 | .setRotation(verticalAngle)); 74 | context.markAsConverted(position); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/converter/actions/ActionManager.java: -------------------------------------------------------------------------------- 1 | package converter.actions; 2 | 3 | import basic.Tuple; 4 | import converter.actions.actions.NoAction; 5 | import converter.mapper.Mapper; 6 | import minecraft.Block; 7 | import minecraft.Position; 8 | 9 | public class ActionManager { 10 | 11 | protected BlockMap actions; 12 | 13 | public ActionManager(Action fallBack) { 14 | this.actions = new BlockMap().setDefault(fallBack); 15 | } 16 | 17 | public ActionManager setAction(Block block, Action addable) { 18 | this.actions.put(block, addable); 19 | return this; 20 | } 21 | 22 | public ActionManager setActions(Iterable> actions) { 23 | actions.forEach(a -> this.setAction(a.getFirst(), a.getSecond())); 24 | return this; 25 | } 26 | 27 | public Action getAction(Block block) { 28 | return this.actions.getFallBackToSuffix(block); 29 | } 30 | 31 | public void add(Mapper context, Position position, Block block) { 32 | Action action; 33 | if (block == null) { 34 | action = NoAction.INSTANCE; 35 | } else { 36 | action = this.getAction(block); 37 | } 38 | action.add(context, position, block); 39 | } 40 | 41 | public void print() { 42 | actions.print(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/converter/actions/BlockMap.java: -------------------------------------------------------------------------------- 1 | package converter.actions; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.function.Supplier; 6 | 7 | import basic.Loggger; 8 | import minecraft.Block; 9 | import minecraft.BlockTemplate; 10 | 11 | public class BlockMap { 12 | 13 | private static final String SEPERATOR = "_"; 14 | 15 | private Value fallback; 16 | private Map map; 17 | 18 | private BlockTemplate newKey = new BlockTemplate(); 19 | private BlockTemplate newSimpleKey = new BlockTemplate(); 20 | 21 | public BlockMap() { 22 | this.map = new HashMap<>(); 23 | } 24 | 25 | public BlockMap put(Supplier keyHolder, Value value) { // TODO 26 | this.map.put(keyHolder.get(), value); 27 | return this; 28 | } 29 | 30 | public Value getFallBackToPrefix(Block key) { 31 | this.newKey.copyFrom(key); 32 | Value result = this.getFallBackNoProperties(key); 33 | if (result != null) { 34 | return result; 35 | } 36 | String title = key.getName(); 37 | while (true) { 38 | int i = title.lastIndexOf(SEPERATOR); 39 | if (i < 1) { 40 | break; 41 | } 42 | if (title.contains("ramp")) { 43 | Loggger.log("break"); 44 | } 45 | title = title.substring(0, i); 46 | this.newKey.setName(title); 47 | result = this.getFallBackNoProperties(this.newKey); 48 | if (result != null) { 49 | this.put(key, result); 50 | return result; 51 | } 52 | } 53 | return this.fallback; 54 | } 55 | 56 | public Value getFallBackToSuffix(Block key) { 57 | Value result = this.getFallBackNoProperties(key); 58 | if (result != null) { 59 | return result; 60 | } 61 | String title = key.getName(); 62 | int colonPos = title.indexOf(":"); 63 | String nameSpace = title.substring(0, colonPos); 64 | while (true) { 65 | int i = title.indexOf(SEPERATOR); 66 | if (i < 1) { 67 | break; 68 | } 69 | title = title.substring(i + 1); 70 | this.newKey.setName(nameSpace + ":" + title); 71 | result = this.getFallBackNoProperties(this.newKey); 72 | if (result != null) { 73 | this.put(key, result); 74 | return result; 75 | } 76 | } 77 | return this.fallback; 78 | } 79 | 80 | private Value getFallBackNoProperties(Block key) { 81 | Value value = this.map.get(key); 82 | if (value != null) { 83 | return value; 84 | } 85 | // test without properties 86 | this.newSimpleKey.setName(key.getName()); 87 | this.newSimpleKey.setProperties(null); 88 | value = this.map.get(this.newSimpleKey); 89 | if (value != null) { 90 | this.put(key, value); 91 | return value; 92 | } 93 | return null; 94 | } 95 | 96 | public Value get(Block key) { 97 | assert this.fallback != null; 98 | Value value = this.map.get(key); 99 | if (value == null) { 100 | return this.fallback; 101 | } 102 | return value; 103 | } 104 | 105 | public BlockMap setDefault(Value fallback) { 106 | this.fallback = fallback; 107 | return this; 108 | } 109 | 110 | public void print() { 111 | this.map.forEach((key, value) -> Loggger.log(key.toString() + " mapsTo " + value.toString())); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/converter/actions/ConvertEntity.java: -------------------------------------------------------------------------------- 1 | package converter.actions; 2 | 3 | import java.util.function.Supplier; 4 | 5 | import converter.actions.actions.NoAction; 6 | import minecraft.Block; 7 | 8 | public class ConvertEntity { 9 | private Supplier block; 10 | private Action action = NoAction.INSTANCE; 11 | 12 | public ConvertEntity(Supplier block, Action action) { 13 | this.block = block; 14 | this.action = action; 15 | } 16 | 17 | public Supplier getBlock() { 18 | return this.block; 19 | } 20 | 21 | public ConvertEntity setBlock(Supplier block) { 22 | this.block = block; 23 | return this; 24 | } 25 | 26 | public Action getAction() { 27 | return this.action; 28 | } 29 | 30 | public ConvertEntity setAction(Action action) { 31 | this.action = action; 32 | return this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/converter/actions/CustomActionManager.java: -------------------------------------------------------------------------------- 1 | package converter.actions; 2 | 3 | import java.util.Collection; 4 | 5 | import converter.actions.actions.Cactus; 6 | import converter.actions.actions.CenteredPointEntity; 7 | import converter.actions.actions.DetailBlock; 8 | import converter.actions.actions.Fence; 9 | import converter.actions.actions.Fire; 10 | import converter.actions.actions.Liquid; 11 | import converter.actions.actions.NoAction; 12 | import converter.actions.actions.PlayerSpawnCss; 13 | import converter.actions.actions.SlabBottom; 14 | import converter.actions.actions.SlabTop; 15 | import converter.actions.actions.Solid; 16 | import converter.actions.actions.Stairs; 17 | import converter.actions.actions.TallGrassTf2; 18 | import converter.actions.actions.Torch; 19 | import converter.mapper.Mapper; 20 | import minecraft.Blocks; 21 | import minecraft.Material; 22 | import minecraft.Property; 23 | import vmfWriter.entity.pointEntity.pointEntity.InfoPlayerCT; 24 | import vmfWriter.entity.pointEntity.pointEntity.InfoPlayerT; 25 | 26 | public class CustomActionManager extends ActionManager { 27 | 28 | public CustomActionManager(Mapper map, Collection converters) { 29 | super(Solid.INSTANCE); 30 | } 31 | 32 | public CustomActionManager setDefaults() { 33 | this.actions.put(Blocks._UNSET, NoAction.INSTANCE); 34 | this.actions.put(Material.air, NoAction.INSTANCE); 35 | this.actions.put(Material.cave_air, NoAction.INSTANCE); 36 | this.actions.put(Material.void_air, NoAction.INSTANCE); 37 | 38 | for (Material m : new Material[] { Material.fern, Material.grass, Material.dandelion, Material.poppy, 39 | Material.brown_mushroom, Material.red_mushroom, Material.redstone_dust, Material.wheat, 40 | Material.oak_door, Material.ladder, Material.rail, Material.oak_wall_sign, Material.lever, 41 | Material.stone_pressure_plate, Material.iron_door, Material.oak_pressure_plate, Material.sugar_cane, 42 | Material.sunflower, Material.cobweb, Material.detector_rail, Material.detector_rail, Material.fire, 43 | Material.redstone_wall_torch, Material.redstone_torch, Material.stone_button, Material.tall_grass, 44 | Material.tall_grass, Material.large_fern, Material.blue_orchid, Material.allium, Material.azure_bluet, 45 | Material.red_tulip, Material.orange_tulip, Material.white_tulip, Material.pink_tulip, 46 | Material.oxeye_daisy, Material.cornflower, Material.lily_of_the_valley, Material.wither_rose, 47 | Material.lilac, Material.rose_bush, Material.peony, Material.sugar_cane, Material.seagrass, 48 | Material.tall_seagrass, Material.sweet_berry_bush }) { 49 | this.actions.put(m, NoAction.INSTANCE); 50 | } 51 | for (Material m : new Material[] { Material._leaves, Material.glass, Material.ice }) { 52 | this.actions.put(m, new DetailBlock()); 53 | } 54 | for (Material m : new Material[] { Material.water, Material.lava, Material.seagrass, Material.tall_seagrass, 55 | Material.kelp, Material.kelp_plant }) { 56 | this.actions.put(m, new Liquid()); 57 | } 58 | this.actions.put(Material._fence, new Fence()); 59 | this.actions.put(Material._stairs, new Stairs()); 60 | this.actions.put(Blocks.get(t -> t.setName(Material._slab) 61 | .addProperty(Property.half, Property.Half.top) 62 | .addProperty(Property.waterlogged, Property.Waterlogged.false$)), new SlabTop()); 63 | this.actions.put(Blocks.get(t -> t.setName(Material._slab) 64 | .addProperty(Property.half, Property.Half.bottom) 65 | .addProperty(Property.waterlogged, Property.Waterlogged.false$)), new SlabBottom()); 66 | this.actions.put(Material.torch, Torch.INSTANCE); 67 | this.actions.put(Material.wall_torch, Torch.INSTANCE); 68 | this.actions.put(Material.cactus, new Cactus()); 69 | this.actions.put(Material.fire, new Fire()); 70 | 71 | // tf2 72 | this.actions.put(Material.grass, new TallGrassTf2()); 73 | 74 | // ttt 75 | this.actions.put(Material.zombie_head, new CenteredPointEntity("info_player_start")); 76 | this.actions.put(Material.fletching_table, new CenteredPointEntity("ttt_random_weapon")); 77 | this.actions.put(Material.grindstone, new CenteredPointEntity("ttt_random_ammo")); 78 | 79 | // css 80 | // this.actions.put(Material.torch, new CssLamp()); 81 | // this.actions.put(Material.wall_torch, new CssLamp()); 82 | this.actions.put(Material.end_portal_frame, new PlayerSpawnCss(new InfoPlayerT().setRotation(0), false)); 83 | this.actions.put(Material.ender_chest, new PlayerSpawnCss(new InfoPlayerCT().setRotation(180), true)); 84 | return this; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Cactus.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | 8 | public class Cactus extends Action { 9 | 10 | @Override 11 | public void add(Mapper context, Position position, Block block) { 12 | Position end = context.getCuboidFinder() 13 | .getBestY(position, block); 14 | int parts = 8; 15 | Position offset = new Position(1, 0, 1); 16 | Position negativeOffset = new Position(1, 1, 1); 17 | context.addDetail(context.createCuboid(position, end, parts, offset, negativeOffset, block)); 18 | context.markAsConverted(position, end); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/converter/actions/actions/CenteredPointEntity.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 8 | 9 | public class CenteredPointEntity extends Action { 10 | 11 | private RotateablePointEntity entity; 12 | private float yOffset = 0; 13 | 14 | public CenteredPointEntity() { 15 | 16 | } 17 | 18 | public CenteredPointEntity(String name) { 19 | this.setEntity(new RotateablePointEntity().setName(name)); 20 | } 21 | 22 | public CenteredPointEntity setYOffset(float yOffset) { 23 | this.yOffset = yOffset; 24 | return this; 25 | } 26 | 27 | @Override 28 | public void add(Mapper context, Position position, Block material) { 29 | context.setPointToGrid(position); 30 | context.movePointInGridDimension(0.5, yOffset, 0.5); 31 | int verticalAngle = (int) (Math.random() * 360); 32 | context.addPointEntity(this.getEntity() 33 | .setRotation(verticalAngle)); 34 | context.markAsConverted(position); 35 | } 36 | 37 | public CenteredPointEntity setEntity(RotateablePointEntity entity) { 38 | this.entity = entity; 39 | return this; 40 | } 41 | 42 | protected RotateablePointEntity getEntity() { 43 | return this.entity; 44 | } 45 | 46 | @Override 47 | public boolean isAirBlock() { 48 | return true; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/converter/actions/actions/CssLamp.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Blocks; 7 | import minecraft.Material; 8 | import minecraft.Position; 9 | import minecraft.Property; 10 | import vmfWriter.Angles; 11 | import vmfWriter.Color; 12 | import vmfWriter.entity.pointEntity.pointEntity.Light; 13 | import vmfWriter.entity.pointEntity.pointEntity.PropStatic; 14 | 15 | /** 16 | * Add torch props and light entities 17 | * 18 | */ 19 | public class CssLamp extends Action { 20 | 21 | private final static String TORCH_MODEL = "models/props/cs_italy/it_lantern1.mdl"; 22 | private final static String TORCH_HOLDER_MODEL = "models/props/cs_italy/it_lampholder1.mdl"; 23 | 24 | private final static int red = 255; 25 | private final static int green = 255; 26 | private final static int blue = 150; 27 | private final static int brigthness = 10; 28 | private final static int distance50 = 96; 29 | private final static int distance100 = 256; 30 | private final static Color LIGHT_COLOR = new Color(CssLamp.red, CssLamp.green, CssLamp.blue, CssLamp.brigthness); 31 | private final static Light LIGHT = new Light(CssLamp.LIGHT_COLOR, CssLamp.distance50, CssLamp.distance100); 32 | private final static PropStatic TORCH = new PropStatic(CssLamp.TORCH_MODEL); 33 | private final static PropStatic TORCH_HOLDER_EAST = new PropStatic(CssLamp.TORCH_HOLDER_MODEL, new Angles(0, 0, 0)); 34 | private final static PropStatic TORCH_HOLDER_WEST = new PropStatic(CssLamp.TORCH_HOLDER_MODEL, 35 | new Angles(0, 180, 0)); 36 | private final static PropStatic TORCH_HOLDER_SOUTH = new PropStatic(CssLamp.TORCH_HOLDER_MODEL, 37 | new Angles(0, 270, 0)); 38 | private final static PropStatic TORCH_HOLDER_NORTH = new PropStatic(CssLamp.TORCH_HOLDER_MODEL, 39 | new Angles(0, 90, 0)); 40 | 41 | @Override 42 | public void add(Mapper context, Position p, Block block) { 43 | int d = 0; 44 | // x=EAST 45 | // z=SOUTH 46 | context.setPointToGrid(p); 47 | 48 | if (block.equals(Material.torch.get())) { // on ground 49 | context.movePointInGridDimension(0.5, 0, 0.5); 50 | context.movePointExactly(new Position(0, 10, 0)); 51 | } else if (block.equals(Blocks.get(t -> t.setName(Material.wall_torch) 52 | .addProperty(Property.facing, Property.Facing.east)))) { // pointing east 53 | // block == 341 54 | context.movePointInGridDimension(0, 0, 0.5); 55 | context.movePointExactly(new Position(0, -6, 0)); 56 | context.addPointEntity(CssLamp.TORCH_HOLDER_EAST); 57 | context.movePointExactly(new Position(8, 22, 0)); 58 | d = 1; 59 | } else if (block.equals(Blocks.get(t -> t.setName(Material.wall_torch) 60 | .addProperty(Property.facing, Property.Facing.west)))) { // pointing west 61 | context.movePointInGridDimension(1, 0, 0.5); 62 | context.movePointExactly(new Position(0, -6, 0)); 63 | context.addPointEntity(CssLamp.TORCH_HOLDER_WEST); 64 | context.movePointExactly(new Position(0 - 8, 22, 0)); 65 | d = 2; 66 | } else if (block.equals(Blocks.get(t -> t.setName(Material.wall_torch) 67 | .addProperty(Property.facing, Property.Facing.south)))) { // pointing south // ! 68 | context.movePointInGridDimension(0.5, 0, 0); 69 | context.movePointExactly(new Position(0, -6, 0)); 70 | context.addPointEntity(CssLamp.TORCH_HOLDER_SOUTH); 71 | context.movePointExactly(new Position(0, 22, 8)); 72 | d = 4; 73 | } else if (block.equals(Blocks.get(t -> t.setName(Material.wall_torch) 74 | .addProperty(Property.facing, Property.Facing.north)))) { // pointing north 75 | context.movePointInGridDimension(0.5, 0, 1); 76 | context.movePointExactly(new Position(0, -6, 0)); 77 | context.addPointEntity(CssLamp.TORCH_HOLDER_NORTH); 78 | context.movePointExactly(new Position(0, 22, -8)); 79 | d = 3; 80 | 81 | } 82 | context.addPointEntity(CssLamp.TORCH); 83 | 84 | context.movePointExactly(new Position(10, 0, 0)); 85 | if (d != 2) { 86 | context.addPointEntity(CssLamp.LIGHT); 87 | } 88 | context.movePointExactly(new Position(-20, 0, 0)); 89 | if (d != 1) { 90 | context.addPointEntity(CssLamp.LIGHT); 91 | } 92 | context.movePointExactly(new Position(10, 0, 0)); 93 | context.movePointExactly(new Position(0, 0, 10)); 94 | if (d != 3) { 95 | context.addPointEntity(CssLamp.LIGHT); 96 | } 97 | context.movePointExactly(new Position(0, 0, -20)); 98 | if (d != 4) { 99 | context.addPointEntity(CssLamp.LIGHT); 100 | } 101 | context.markAsConverted(p); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Debug.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | 8 | public class Debug extends Action { 9 | 10 | @Override 11 | public void add(Mapper context, Position position, Block block) { 12 | this.addDebugMarker(context, position, block); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/converter/actions/actions/DetailBlock.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.solidEntity.FuncDetail; 8 | 9 | /** 10 | * creates a "func_detail"-Block 11 | */ 12 | public class DetailBlock extends Action { 13 | 14 | @Override 15 | public void add(Mapper context, Position p, Block material) { 16 | Position end = context.getCuboidFinder() 17 | .getBestXYZ(p, material); 18 | context.addSolidEntity(new FuncDetail(context.createCuboid(p, end, material))); 19 | context.markAsConverted(p, end); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/converter/actions/actions/EndPortalFrame.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | 8 | /** 9 | * 10 | * 11 | */ 12 | public class EndPortalFrame extends Action { 13 | 14 | public EndPortalFrame() { 15 | // TODO 16 | } 17 | 18 | @Override 19 | public void add(Mapper context, Position p, Block material) { 20 | Position end = context.getCuboidFinder() 21 | .getBestXZ(p, material); 22 | int parts = 4; 23 | Position offset = new Position(0, 0, 0); 24 | Position negativeOffset = new Position(0, 1, 0); 25 | context.addDetail(context.createCuboid(p, end, parts, offset, negativeOffset, material)); 26 | context.markAsConverted(p, end); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Fence.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import java.util.function.Predicate; 4 | 5 | import converter.actions.Action; 6 | import converter.actions.ActionManager; 7 | import converter.mapper.Mapper; 8 | import minecraft.Block; 9 | import minecraft.Position; 10 | import vmfWriter.Orientation; 11 | 12 | public class Fence extends Action { 13 | 14 | private static int BEAM_SIDE = 7; 15 | private static int BEAM_TOP_OFF = 1; 16 | private static int BEAM_TOP_ON = 12; 17 | private static int BEAM_MID_OFF = 8; 18 | private static int BEAM_MID_ON = 5; 19 | 20 | @Override 21 | public boolean hasWall(Orientation orientation) { 22 | return true; 23 | } 24 | 25 | @Override 26 | public void add(Mapper context, Position p, Block material) { 27 | Position end = context.getCuboidFinder() 28 | .getBestY(p, material); 29 | // pole 30 | int parts = 8; 31 | Position offset = new Position(3, 0, 3); 32 | Position negativeOffset = new Position(3, 0, 3); 33 | context.addDetail(context.createCuboid(p, end, parts, offset, negativeOffset, material)); 34 | context.markAsConverted(p, end); 35 | // add beams 36 | parts = 16; 37 | while (p.getY() <= end.getY()) { 38 | if (context.hasBlock(p.getOffset(1, 0, 0), material)) { 39 | offset = new Position(10, Fence.BEAM_TOP_ON, Fence.BEAM_SIDE); 40 | negativeOffset = new Position(10, Fence.BEAM_TOP_OFF, Fence.BEAM_SIDE); 41 | context.addDetail( 42 | context.createCuboid(p, p.getOffset(1, 0, 0), parts, offset, negativeOffset, material)); 43 | offset = new Position(10, Fence.BEAM_MID_ON, Fence.BEAM_SIDE); 44 | negativeOffset = new Position(10, Fence.BEAM_MID_OFF, Fence.BEAM_SIDE); 45 | context.addDetail( 46 | context.createCuboid(p, p.getOffset(1, 0, 0), parts, offset, negativeOffset, material)); 47 | } else if (context.hasBlock(p.getOffset(1, 0, 0), 48 | new MaterialWallFilter(context.getActions(), Orientation.EAST))) { 49 | offset = new Position(10, Fence.BEAM_TOP_ON, Fence.BEAM_SIDE); 50 | negativeOffset = new Position(parts, Fence.BEAM_TOP_OFF, Fence.BEAM_SIDE); 51 | context.addDetail( 52 | context.createCuboid(p, p.getOffset(1, 0, 0), parts, offset, negativeOffset, material)); 53 | offset = new Position(10, Fence.BEAM_MID_ON, Fence.BEAM_SIDE); 54 | negativeOffset = new Position(parts, Fence.BEAM_MID_OFF, Fence.BEAM_SIDE); 55 | context.addDetail( 56 | context.createCuboid(p, p.getOffset(1, 0, 0), parts, offset, negativeOffset, material)); 57 | } 58 | 59 | if (context.hasBlock(p.getOffset(-1, 0, 0), 60 | new MaterialWallFilter(context.getActions(), Orientation.WEST))) { 61 | offset = new Position(parts, Fence.BEAM_TOP_ON, Fence.BEAM_SIDE); 62 | negativeOffset = new Position(10, Fence.BEAM_TOP_OFF, Fence.BEAM_SIDE); 63 | context.addDetail( 64 | context.createCuboid(p.getOffset(-1, 0, 0), p, parts, offset, negativeOffset, material)); 65 | offset = new Position(parts, Fence.BEAM_MID_ON, Fence.BEAM_SIDE); 66 | negativeOffset = new Position(10, Fence.BEAM_MID_OFF, Fence.BEAM_SIDE); 67 | context.addDetail( 68 | context.createCuboid(p.getOffset(-1, 0, 0), p, parts, offset, negativeOffset, material)); 69 | } 70 | 71 | if (context.hasBlock(p.getOffset(0, 0, 1), material)) { 72 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_ON, 10); 73 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_OFF, 10); 74 | context.addDetail( 75 | context.createCuboid(p, p.getOffset(0, 0, 1), parts, offset, negativeOffset, material)); 76 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_ON, 10); 77 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_OFF, 10); 78 | context.addDetail( 79 | context.createCuboid(p, p.getOffset(0, 0, 1), parts, offset, negativeOffset, material)); 80 | } else if (context.hasBlock(p.getOffset(0, 0, 1), 81 | new MaterialWallFilter(context.getActions(), Orientation.SOUTH))) { 82 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_ON, 10); 83 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_OFF, parts); 84 | context.addDetail( 85 | context.createCuboid(p, p.getOffset(0, 0, 1), parts, offset, negativeOffset, material)); 86 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_ON, 10); 87 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_OFF, parts); 88 | context.addDetail( 89 | context.createCuboid(p, p.getOffset(0, 0, 1), parts, offset, negativeOffset, material)); 90 | } 91 | 92 | if (context.hasBlock(p.getOffset(0, 0, -1), 93 | new MaterialWallFilter(context.getActions(), Orientation.NORTH))) { 94 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_ON, parts); 95 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_TOP_OFF, 10); 96 | context.addDetail( 97 | context.createCuboid(p.getOffset(0, 0, -1), p, parts, offset, negativeOffset, material)); 98 | offset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_ON, parts); 99 | negativeOffset = new Position(Fence.BEAM_SIDE, Fence.BEAM_MID_OFF, 10); 100 | context.addDetail( 101 | context.createCuboid(p.getOffset(0, 0, -1), p, parts, offset, negativeOffset, material)); 102 | } 103 | 104 | p.move(0, 1, 0); 105 | // Block.getMaterialUsedForStatic() 106 | } 107 | } 108 | 109 | private class MaterialWallFilter implements Predicate { 110 | 111 | private ActionManager manager; 112 | private Orientation orientation; 113 | 114 | public MaterialWallFilter(ActionManager manager, Orientation orientation) { 115 | this.manager = manager; 116 | this.orientation = orientation; 117 | } 118 | 119 | @Override 120 | public boolean test(Block material) { 121 | Action addable = this.manager.getAction(material); 122 | if (addable != null) { 123 | return this.manager.getAction(material) 124 | .hasWall(this.orientation); 125 | } else { 126 | return false; 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Fire.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.Color; 8 | import vmfWriter.entity.pointEntity.pointEntity.EnvFire; 9 | import vmfWriter.entity.pointEntity.pointEntity.Light; 10 | 11 | public class Fire extends Action { 12 | 13 | private final static int red = 255; 14 | private final static int green = 113; 15 | private final static int blue = 28; 16 | private final static int brigthness = 100; 17 | private final static int distance50 = 96; 18 | private final static int distance100 = 256; 19 | private final static Color FIRE_COLOR = new Color(Fire.red, Fire.green, Fire.blue, Fire.brigthness); 20 | private static Light LIGHT = new Light(Fire.FIRE_COLOR, Fire.distance50, Fire.distance100); 21 | private static EnvFire ENV_FIRE; 22 | 23 | @Override 24 | public void add(Mapper context, Position position, Block material) { 25 | Fire.ENV_FIRE.setFireSize(context.getScale()); 26 | context.setPointToGrid(position); 27 | context.movePointInGridDimension(0.5, 0, 0.5); 28 | context.movePointExactly(new Position(0, 1, 0)); 29 | context.movePointInGridDimension(this.randomOffset(0.5), 0, this.randomOffset(0.5)); 30 | context.addPointEntity(Fire.ENV_FIRE); 31 | context.movePointInGridDimension(0, 0.5, 0); 32 | context.movePointExactly(new Position(0, -1, 0)); 33 | context.addPointEntity(Fire.LIGHT); 34 | context.markAsConverted(position); 35 | } 36 | 37 | private double randomOffset(double scale) { 38 | return scale; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/converter/actions/actions/LilypadTf2.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import vmfWriter.entity.pointEntity.pointEntity.PropStatic; 9 | 10 | /** 11 | * 12 | * 13 | */ 14 | public class LilypadTf2 extends Action { 15 | 16 | private final static String MODEL = "models/props_swamp/lilypad_large.mdl"; 17 | private final static PropStatic LILY_PAD = new PropStatic(LilypadTf2.MODEL); 18 | 19 | public LilypadTf2() { 20 | int[] temp = { MaterialLegacy.LILY_PAD }; 21 | super.materialUsedFor = temp; 22 | } 23 | 24 | @Override 25 | public void add(Mapper context, Position position, Block material) { 26 | context.setPointToGrid(position); 27 | context.movePointInGridDimension(0.5, 0, 0.5); 28 | int verticalAngle = (int) (Math.random() * 360); 29 | LilypadTf2.LILY_PAD.getAngles() 30 | .setY(verticalAngle); 31 | context.addPointEntity(LilypadTf2.LILY_PAD); 32 | context.markAsConverted(position); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Liquid.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | 8 | /** 9 | * A non-solid block (thus counts as air) that has a lowered height when it ends 10 | * 11 | */ 12 | public class Liquid extends Action { 13 | 14 | @Override 15 | public void add(Mapper context, Position position, Block material) { 16 | Position end = context.getCuboidFinder() 17 | .getBestXYZ(position, material); 18 | context.addSolid(context.createCuboid(position, end, material)); 19 | context.markAsConverted(position, end); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/converter/actions/actions/NoAction.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | 8 | public class NoAction extends Action { 9 | 10 | public static final NoAction INSTANCE = new NoAction(); 11 | 12 | @Override 13 | public void add(Mapper context, Position position, Block material) { 14 | context.markAsConverted(position); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Pane.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | 9 | public class Pane extends Action { 10 | 11 | public Pane() { 12 | int temp[] = { MaterialLegacy.GLASS_PANE }; 13 | super.materialUsedFor = temp; 14 | } 15 | 16 | @Override 17 | public void add(Mapper context, Position p, Block material) { 18 | Position bestXY = context.getCuboidFinder() 19 | .getBestXY(p, material); 20 | Position bestYZ = context.getCuboidFinder() 21 | .getBestYZ(p, material); 22 | int sizeXY = p.getRoomSizeTo(bestXY); 23 | int sizeYZ = p.getRoomSizeTo(bestYZ); 24 | int parts = 16; 25 | int yOffset = 0; 26 | int yStop = 0; 27 | int xOffset = 0; 28 | int zOffset = 0; 29 | int xStop = 0; 30 | int zStop = 0; 31 | Position end; 32 | if (sizeXY > sizeYZ) { // window in x,y direction 33 | end = bestXY; 34 | zOffset = 7; 35 | zStop = 7; 36 | } else if (sizeXY < sizeYZ) { // window in z,y direction 37 | end = bestYZ; 38 | xOffset = 7; 39 | xStop = 7; 40 | } else { // check for borders 41 | int x = p.getX(); 42 | int y = p.getY(); 43 | int z = p.getZ(); 44 | int sumX = this.countAirY(context, x + 1, y, z, bestXY.getY()) 45 | + this.countAirY(context, x - 1, y, z, bestXY.getY()); 46 | int sumZ = this.countAirY(context, x, y, z + 1, bestYZ.getY()) 47 | + this.countAirY(context, x, y, z - 1, bestYZ.getY()); 48 | if (sumX <= sumZ) { 49 | end = bestXY; 50 | zOffset = 7; 51 | zStop = 7; 52 | } else { 53 | end = bestYZ; 54 | xOffset = 7; 55 | xStop = 7; 56 | } 57 | } 58 | Position offset = new Position(xOffset, yOffset, zOffset); 59 | Position negativeOffset = new Position(xStop, yStop, zStop); 60 | context.addDetail(context.createCuboid(p, end, parts, offset, negativeOffset, material)); 61 | context.markAsConverted(p, end); 62 | } 63 | 64 | private int countAirY(Mapper context, int x, int yStart, int z, int yEnd) { 65 | int sum = 0; 66 | for (int yRun = yStart; yRun <= yEnd; yRun++) { 67 | if (context.isAirBlock(new Position(x, yRun, z))) { 68 | sum++; 69 | } 70 | } 71 | return sum; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/converter/actions/actions/PlayerSpawnCss.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 8 | import vmfWriter.entity.solidEntity.Buyzone; 9 | 10 | public class PlayerSpawnCss extends Action { 11 | 12 | private final static int SPACE = 40; 13 | 14 | private RotateablePointEntity type; 15 | private boolean police; 16 | 17 | public PlayerSpawnCss() { 18 | 19 | } 20 | 21 | public PlayerSpawnCss(RotateablePointEntity type, boolean police) { 22 | this.type = type; 23 | this.police = police; 24 | } 25 | 26 | @Override 27 | public void add(Mapper context, Position p, Block material) { 28 | Position end = context.getCuboidFinder() 29 | .getBestXZ(p, material); 30 | context.addPointEntitys(p, end, PlayerSpawnCss.SPACE, this.type); 31 | end.move(0, 2, 0); 32 | context.addSolidEntity(new Buyzone(context.createCuboid(p, end, null), this.police)); 33 | context.markAsConverted(p, end); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/converter/actions/actions/PlayerSpawnTf2.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 8 | import vmfWriter.entity.solidEntity.Buyzone; 9 | 10 | public class PlayerSpawnTf2 extends Action { 11 | 12 | private final static int SPACE = 50; 13 | 14 | private RotateablePointEntity type; 15 | private boolean police; 16 | 17 | public PlayerSpawnTf2() { 18 | 19 | } 20 | 21 | // public PlayerSpawnTf2(Block material, RotateablePointEntity type, boolean police) { 22 | // super.setMaterialUsedFor(material); 23 | // this.type = type; 24 | // this.police = police; 25 | // } 26 | // 27 | // @Override 28 | // public Iterable getInstances() { 29 | // RotateablePointEntity redSpawn = new InfoPlayerTeamSpawn().setTeamNum(Tf2Team.RED) 30 | // .setRotation(0); 31 | // RotateablePointEntity blueSpawn = new InfoPlayerTeamSpawn().setTeamNum(Tf2Team.BLUE) 32 | // .setRotation(180); 33 | // LinkedList list = new LinkedList<>(); 34 | // list.add(new PlayerSpawnTf2(MaterialLegacy.END_PORTAL_FRAME, redSpawn, false)); 35 | // list.add(new PlayerSpawnTf2(MaterialLegacy.ENDER_CHEST$NORTH, blueSpawn, true)); 36 | // list.add(new PlayerSpawnTf2(MaterialLegacy.ENDER_CHEST$EAST, blueSpawn, true)); 37 | // list.add(new PlayerSpawnTf2(MaterialLegacy.ENDER_CHEST$SOUTH, blueSpawn, true)); 38 | // list.add(new PlayerSpawnTf2(MaterialLegacy.ENDER_CHEST$WEST, blueSpawn, true)); 39 | // return list; 40 | // } 41 | 42 | @Override 43 | public void add(Mapper context, Position p, Block material) { 44 | Position end = context.getCuboidFinder() 45 | .getBestXZ(p, material); 46 | context.addPointEntitys(p, end, PlayerSpawnTf2.SPACE, this.type); 47 | context.markAsConverted(p, end); 48 | end.move(0, 2, 0); 49 | context.addSolidEntity(new Buyzone(context.createCuboid(p, end, null), this.police)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/converter/actions/actions/SlabBottom.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import minecraft.SubBlockPosition; 9 | 10 | public class SlabBottom extends Action { 11 | 12 | public SlabBottom() { 13 | int[] temp = { MaterialLegacy.OAK_SLAB$BOTTOM, MaterialLegacy.COBBLESTONE_SLAB$BOTTOM, 14 | MaterialLegacy.BRICK_SLAB$BOTTOM, MaterialLegacy.ANDESITE_SLAB$BOTTOM, 15 | MaterialLegacy.NETHER_BRICK_SLAB$BOTTOM, MaterialLegacy.ACACIA_SLAB$BOTTOM, 16 | MaterialLegacy.BIRCH_SLAB$BOTTOM, MaterialLegacy.DIORITE_SLAB$BOTTOM, 17 | MaterialLegacy.CUT_RED_SANDSTONE_SLAB$BOTTOM, MaterialLegacy.CUT_SANDSTONE_SLAB$BOTTOM, 18 | MaterialLegacy.DIORITE_SLAB$BOTTOM, MaterialLegacy.DARK_OAK_SLAB$BOTTOM, 19 | MaterialLegacy.DARK_PRISMARINE_SLAB$BOTTOM, MaterialLegacy.END_STONE_BRICK_SLAB$BOTTOM, 20 | MaterialLegacy.GRANITE_SLAB$BOTTOM, MaterialLegacy.JUNGLE_SLAB$BOTTOM, 21 | MaterialLegacy.MOSSY_COBBLESTONE_SLAB$BOTTOM, MaterialLegacy.MOSSY_STONE_BRICK_SLAB$BOTTOM, 22 | MaterialLegacy.PETRIFIED_OAK_SLAB$BOTTOM, MaterialLegacy.POLISHED_ANDESITE_SLAB$BOTTOM, 23 | MaterialLegacy.POLISHED_DIORITE_SLAB$BOTTOM, MaterialLegacy.POLISHED_GRANITE_SLAB$BOTTOM, 24 | MaterialLegacy.PRISMARINE_BRICK_SLAB$BOTTOM, MaterialLegacy.PURPUR_SLAB$BOTTOM, 25 | MaterialLegacy.QUARTZ_SLAB$BOTTOM, MaterialLegacy.RED_NETHER_BRICK_SLAB$BOTTOM, 26 | MaterialLegacy.SANDSTONE_SLAB$BOTTOM, MaterialLegacy.SMOOTH_QUARTZ_SLAB$BOTTOM, 27 | MaterialLegacy.SMOOTH_RED_SANDSTONE_SLAB$BOTTOM, MaterialLegacy.SMOOTH_SANDSTONE_SLAB$BOTTOM, 28 | MaterialLegacy.SMOOTH_STONE_SLAB$BOTTOM, MaterialLegacy.SPRUCE_SLAB$BOTTOM, 29 | MaterialLegacy.STONE_BRICK_SLAB$BOTTOM, MaterialLegacy.STONE_SLAB$BOTTOM }; 30 | super.materialUsedFor = temp; 31 | } 32 | 33 | @Override 34 | public void add(Mapper context, Position position, Block material) { 35 | context.addSubBlock(position, SubBlockPosition.BOTTOM_EAST_SOUTH, material); 36 | context.addSubBlock(position, SubBlockPosition.BOTTOM_EAST_NORTH, material); 37 | context.addSubBlock(position, SubBlockPosition.BOTTOM_WEST_SOUTH, material); 38 | context.addSubBlock(position, SubBlockPosition.BOTTOM_WEST_NORTH, material); 39 | context.markAsConverted(position); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/converter/actions/actions/SlabTop.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import minecraft.SubBlockPosition; 9 | 10 | public class SlabTop extends Action { 11 | 12 | public SlabTop() { 13 | int[] temp = { MaterialLegacy.OAK_SLAB$TOP, MaterialLegacy.COBBLESTONE_SLAB$TOP, MaterialLegacy.BRICK_SLAB$TOP, 14 | MaterialLegacy.ANDESITE_SLAB$TOP, MaterialLegacy.NETHER_BRICK_SLAB$TOP, MaterialLegacy.ACACIA_SLAB$TOP, 15 | MaterialLegacy.BIRCH_SLAB$TOP, MaterialLegacy.DIORITE_SLAB$TOP, 16 | MaterialLegacy.CUT_RED_SANDSTONE_SLAB$TOP, MaterialLegacy.CUT_SANDSTONE_SLAB$TOP, 17 | MaterialLegacy.DIORITE_SLAB$TOP, MaterialLegacy.DARK_OAK_SLAB$TOP, 18 | MaterialLegacy.DARK_PRISMARINE_SLAB$TOP, MaterialLegacy.END_STONE_BRICK_SLAB$TOP, 19 | MaterialLegacy.GRANITE_SLAB$TOP, MaterialLegacy.JUNGLE_SLAB$TOP, 20 | MaterialLegacy.MOSSY_COBBLESTONE_SLAB$TOP, MaterialLegacy.MOSSY_STONE_BRICK_SLAB$TOP, 21 | MaterialLegacy.PETRIFIED_OAK_SLAB$TOP, MaterialLegacy.POLISHED_ANDESITE_SLAB$TOP, 22 | MaterialLegacy.POLISHED_DIORITE_SLAB$TOP, MaterialLegacy.POLISHED_GRANITE_SLAB$TOP, 23 | MaterialLegacy.PRISMARINE_BRICK_SLAB$TOP, MaterialLegacy.PURPUR_SLAB$TOP, 24 | MaterialLegacy.QUARTZ_SLAB$TOP, MaterialLegacy.RED_NETHER_BRICK_SLAB$TOP, 25 | MaterialLegacy.SANDSTONE_SLAB$TOP, MaterialLegacy.SMOOTH_QUARTZ_SLAB$TOP, 26 | MaterialLegacy.SMOOTH_RED_SANDSTONE_SLAB$TOP, MaterialLegacy.SMOOTH_SANDSTONE_SLAB$TOP, 27 | MaterialLegacy.SMOOTH_STONE_SLAB$TOP, MaterialLegacy.SPRUCE_SLAB$TOP, 28 | MaterialLegacy.STONE_BRICK_SLAB$TOP, MaterialLegacy.STONE_SLAB$TOP }; 29 | super.materialUsedFor = temp; 30 | } 31 | 32 | @Override 33 | public void add(Mapper context, Position position, Block material) { 34 | context.addSubBlock(position, SubBlockPosition.TOP_EAST_SOUTH, material); 35 | context.addSubBlock(position, SubBlockPosition.TOP_EAST_NORTH, material); 36 | context.addSubBlock(position, SubBlockPosition.TOP_WEST_SOUTH, material); 37 | context.addSubBlock(position, SubBlockPosition.TOP_WEST_NORTH, material); 38 | context.markAsConverted(position); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/converter/actions/actions/SnowBlock.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | 9 | public class SnowBlock extends Action { 10 | 11 | public SnowBlock() { 12 | int[] temp = { MaterialLegacy.SNOW }; 13 | super.setMaterialUsedFor(temp); 14 | } 15 | 16 | @Override 17 | public void add(Mapper context, Position p, Block material) { 18 | Position end = context.getCuboidFinder() 19 | .getBestXZ(p, material); 20 | int parts = 8; 21 | Position offset = new Position(0, 0, 0); 22 | Position negativeOffset = new Position(0, 7, 0); 23 | context.addDetail(context.createCuboid(p, end, parts, offset, negativeOffset, material)); 24 | context.markAsConverted(p, end); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Solid.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import basic.Loggger; 4 | import converter.Skins; 5 | import converter.actions.Action; 6 | import converter.mapper.Mapper; 7 | import minecraft.Block; 8 | import minecraft.Position; 9 | import vmfWriter.Orientation; 10 | 11 | public class Solid extends Action { 12 | 13 | public static final Action INSTANCE = new Solid(); 14 | 15 | public Solid() { 16 | // is default addable 17 | } 18 | 19 | @Override 20 | public boolean isAirBlock() { 21 | return false; 22 | } 23 | 24 | @Override 25 | public boolean hasWall(Orientation orientation) { 26 | return true; 27 | } 28 | 29 | @Override 30 | public void add(Mapper context, Position position, Block block) { 31 | Position end = context.getCuboidFinder() 32 | .getBestXYZ(position, block); 33 | if (Skins.INSTANCE.getSkin(block).materialFront.equals(Skins.DEFAULT_TEXTURE)) { // temp 34 | Loggger.log("no texture set for " + block.getName()); 35 | } 36 | context.addSolid(context.createCuboid(position, end, block)); 37 | context.markAsConverted(position, end); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/converter/actions/actions/SupplyTf2.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import basic.Loggger; 4 | import converter.actions.Action; 5 | import converter.mapper.Mapper; 6 | import minecraft.Block; 7 | import minecraft.MaterialLegacy; 8 | import minecraft.Position; 9 | import vmfWriter.Orientation; 10 | import vmfWriter.Solid; 11 | import vmfWriter.entity.Tf2Team; 12 | import vmfWriter.entity.pointEntity.pointEntity.PropDynamic; 13 | import vmfWriter.entity.solidEntity.FuncRegenerate; 14 | 15 | /** 16 | * 17 | * 18 | */ 19 | public class SupplyTf2 extends Action { 20 | 21 | private static final String MODEL = "models/props_gameplay/resupply_locker.mdl"; 22 | private static final int DISTANCE_FROM_WALL = 16; 23 | 24 | private Orientation orientation; 25 | private PropDynamic prop; 26 | 27 | public SupplyTf2() { 28 | int[] temp = { MaterialLegacy.CHEST$NORTH, MaterialLegacy.CHEST$SOUTH, MaterialLegacy.CHEST$WEST, 29 | MaterialLegacy.CHEST$EAST }; 30 | super.setMaterialUsedFor(temp); 31 | } 32 | 33 | // public SupplyTf2(Block material, Orientation orientation) { 34 | // super.setMaterialUsedFor(material); 35 | // this.setPropDynamic(orientation); 36 | // } 37 | // 38 | // @Override 39 | // public Iterable getInstances() { 40 | // LinkedList list = new LinkedList<>(); 41 | //// list.add(new SupplyTf2(MaterialLegacy.CHEST$NORTH, Orientation.NORTH)); 42 | //// list.add(new SupplyTf2(MaterialLegacy.CHEST$SOUTH, Orientation.SOUTH)); 43 | //// list.add(new SupplyTf2(MaterialLegacy.CHEST$EAST, Orientation.EAST)); 44 | //// list.add(new SupplyTf2(MaterialLegacy.CHEST$WEST, Orientation.WEST)); 45 | // return list; 46 | // } 47 | 48 | @Override 49 | public void add(Mapper context, Position p, Block material) { 50 | Loggger.log(this.getName() + " at " + p.getString()); 51 | Position end = context.getCuboidFinder() 52 | .getBestXZ(p, material); 53 | Position point = new Position(p); 54 | context.setPointToGrid(p); 55 | this.moveToMiddle(context, point, point); // TODO 56 | PropDynamic createdProp = (PropDynamic) context.addPointEntity(this.prop); 57 | context.addSolidEntity(new FuncRegenerate(this.createArea(context, p, end), Tf2Team.ANY, createdProp)); 58 | context.markAsConverted(p, end); 59 | } 60 | 61 | private Solid createArea(Mapper context, Position p, Position end) { 62 | return context.createCuboid(p, end.getOffset(0, 2, 0), null); 63 | } 64 | 65 | private void moveToMiddle(Mapper context, Position p, Position end) { 66 | switch (this.orientation) { 67 | case NORTH: 68 | context.movePointInGridDimension((end.x - p.x + 1) / 2, 0, 1); 69 | context.movePointExactly(new Position(0, 0, -SupplyTf2.DISTANCE_FROM_WALL)); 70 | break; 71 | case SOUTH: 72 | context.movePointInGridDimension((end.x - p.x + 1) / 2, 0, 0); 73 | context.movePointExactly(new Position(0, 0, SupplyTf2.DISTANCE_FROM_WALL)); 74 | break; 75 | case EAST: 76 | context.movePointInGridDimension(0, 0, (end.z - p.z + 1) / 2); 77 | context.movePointExactly(new Position(SupplyTf2.DISTANCE_FROM_WALL, 0, 0)); 78 | break; 79 | case WEST: 80 | context.movePointInGridDimension(1, 0, (end.z - p.z + 1) / 2); 81 | context.movePointExactly(new Position(-SupplyTf2.DISTANCE_FROM_WALL, 0, 0)); 82 | break; 83 | default: 84 | break; 85 | } 86 | } 87 | 88 | public void setPropDynamic(Orientation orientation) { 89 | this.orientation = orientation; 90 | this.prop = new PropDynamic(SupplyTf2.MODEL, 0, this.getAngleY(orientation), 0); 91 | } 92 | 93 | private int getAngleY(Orientation orientation) { 94 | switch (orientation) { 95 | case NORTH: 96 | return 90; 97 | case SOUTH: 98 | return 270; 99 | case EAST: 100 | return 0; 101 | case WEST: 102 | return 180; 103 | default: 104 | return 0; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/converter/actions/actions/TallGrassTf2.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.pointEntity.pointEntity.PropStatic; 8 | 9 | /** 10 | * 11 | * 12 | */ 13 | public class TallGrassTf2 extends Action { 14 | 15 | private final static String MODEL = "models/props_swamp/tallgrass_01.mdl"; 16 | private final static PropStatic TALL_GRASS = new PropStatic(TallGrassTf2.MODEL); 17 | 18 | @Override 19 | public void add(Mapper context, Position p, Block material) { 20 | context.setPointToGrid(p); 21 | context.movePointInGridDimension(0.5, 0, 0.5); 22 | int verticalRotation = (int) (Math.random() * 360); 23 | TallGrassTf2.TALL_GRASS.getAngles() 24 | .setY(verticalRotation); 25 | context.addPointEntity(TallGrassTf2.TALL_GRASS); 26 | context.markAsConverted(p); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/converter/actions/actions/Torch.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.Color; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | import vmfWriter.entity.pointEntity.pointEntity.EnvFire; 10 | import vmfWriter.entity.pointEntity.pointEntity.InfoParticleSystem; 11 | import vmfWriter.entity.pointEntity.pointEntity.Light; 12 | import vmfWriter.entity.solidEntity.FuncIllusionary; 13 | 14 | public class Torch extends Action { 15 | 16 | public final static int red = 255; 17 | public final static int blue = 50; 18 | public final static int green = 243; 19 | public final static int brigthness = 40; 20 | public final static int distance50 = 96; 21 | public final static int distance100 = 256; 22 | public final static Color LIGHT_COLOR = new Color(Torch.red, Torch.green, Torch.blue, Torch.brigthness); 23 | public final static Light LIGHT = new Light(Torch.LIGHT_COLOR, Torch.distance50, Torch.distance100); 24 | private final static String EFFECT_NAME = "flaming_arrow"; 25 | public final static InfoParticleSystem PARTICLE_SYSTEM = new InfoParticleSystem(Torch.EFFECT_NAME, 270, 0, 0); 26 | protected static final PointEntity FLAME = new EnvFire().setFireSize(3); 27 | public static final Torch INSTANCE = new Torch(); 28 | 29 | @Override 30 | public void add(Mapper context, Position p, Block material) { 31 | int parts = 16; 32 | Position offset = new Position(7, 0, 7); 33 | Position negativeOffset = new Position(7, 6, 7); 34 | context.addSolidEntity( 35 | new FuncIllusionary(context.createCuboid(p, p, parts, offset, negativeOffset, material))); 36 | context.setPointToGrid(p); 37 | context.movePointInGridDimension(0.5, ((double) (parts - negativeOffset.getY())) / ((parts)), 0.5); 38 | this.addFlame(context); 39 | context.markAsConverted(p); 40 | } 41 | 42 | public void addFlame(Mapper context) { 43 | context.addPointEntity(Torch.PARTICLE_SYSTEM); 44 | context.movePointInGridDimension(0, 1.0 / ((16)), 0); 45 | context.addPointEntity(Torch.FLAME); 46 | context.addPointEntity(Torch.LIGHT); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/converter/actions/actions/TorchEast.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.mapper.Mapper; 4 | import minecraft.Block; 5 | import minecraft.Position; 6 | import vmfWriter.entity.solidEntity.FuncIllusionary; 7 | 8 | public class TorchEast extends Torch { 9 | 10 | public static int red = 255; 11 | public static int blue = 50; 12 | public static int green = 243; 13 | public static int brigthness = 40; 14 | public final static int distance50 = 96; 15 | public final static int distance100 = 256; 16 | 17 | @Override 18 | public void add(Mapper context, Position p, Block material) { 19 | int parts = 32; 20 | Position[] pointOffset = new Position[8]; 21 | pointOffset[0] = new Position(0, 6, 18); // a 22 | pointOffset[1] = new Position(9, 24, 18); // b 23 | pointOffset[2] = new Position(13, 22, 18); // c 24 | pointOffset[3] = new Position(4, 4, 18); // d 25 | pointOffset[4] = new Position(0, 6, 14); // e 26 | pointOffset[5] = new Position(9, 24, 14); // f 27 | pointOffset[6] = new Position(13, 22, 14); // g 28 | pointOffset[7] = new Position(4, 4, 14); // h 29 | 30 | Position point = new Position(p); 31 | context.addSolidEntity( 32 | new FuncIllusionary(context.createFree8Point(point, point, parts, pointOffset, true, material))); 33 | context.setPointToGrid(p); 34 | context.movePointInGridDimension((7.0 / 20.0), 0.7, 0.5); 35 | this.addFlame(context); 36 | context.markAsConverted(p); 37 | 38 | // textureshift: -92 39 | // textureshift -24 40 | // rotation 28 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/converter/actions/actions/TorchNorth.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.Position; 7 | import vmfWriter.entity.solidEntity.FuncIllusionary; 8 | 9 | public class TorchNorth extends Action { 10 | 11 | @Override 12 | public void add(Mapper context, Position p, Block material) { 13 | int parts = 32; 14 | Position[] pointOffset = new Position[8]; 15 | 16 | pointOffset[0] = new Position(18, 6, 32); // a 17 | pointOffset[1] = new Position(18, 24, 23); // b 18 | pointOffset[2] = new Position(18, 22, 19); // c 19 | pointOffset[3] = new Position(18, 4, 28); // d 20 | pointOffset[4] = new Position(14, 6, 32); // e 21 | pointOffset[5] = new Position(14, 24, 23); // f 22 | pointOffset[6] = new Position(14, 22, 19); // g 23 | pointOffset[7] = new Position(14, 4, 28); // h 24 | 25 | Position point = new Position(p); 26 | context.addSolidEntity( 27 | new FuncIllusionary(context.createFree8Point(point, point, parts, pointOffset, false, material))); 28 | context.setPointToGrid(p); 29 | context.movePointInGridDimension(0.5, 0.7, (13.0 / 20.0)); 30 | context.addPointEntity(Torch.PARTICLE_SYSTEM); 31 | context.movePointInGridDimension(0, 1.0 / ((parts)), 0); 32 | context.addPointEntity(Torch.LIGHT); 33 | context.markAsConverted(p); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/converter/actions/actions/TorchSouth.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.mapper.Mapper; 4 | import minecraft.Block; 5 | import minecraft.Position; 6 | import vmfWriter.entity.solidEntity.FuncIllusionary; 7 | 8 | public class TorchSouth extends Torch { 9 | 10 | @Override 11 | public void add(Mapper context, Position p, Block material) { 12 | int parts = 32; 13 | Position[] pointOffset = new Position[8]; 14 | 15 | pointOffset[0] = new Position(14, 6, 0); // a 16 | pointOffset[1] = new Position(14, 24, 9); // b 17 | pointOffset[2] = new Position(14, 22, 13); // c 18 | pointOffset[3] = new Position(14, 4, 4); // d 19 | pointOffset[4] = new Position(18, 6, 0); // e 20 | pointOffset[5] = new Position(18, 24, 9); // f 21 | pointOffset[6] = new Position(18, 22, 13); // g 22 | pointOffset[7] = new Position(18, 4, 4); // h 23 | 24 | Position point = new Position(p); 25 | context.addSolidEntity( 26 | new FuncIllusionary(context.createFree8Point(point, point, parts, pointOffset, false, material))); 27 | context.setPointToGrid(p); 28 | context.movePointInGridDimension(0.5, 0.7, (7.0 / 20.0)); 29 | this.addFlame(context); 30 | context.markAsConverted(p); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/actions/actions/TorchWest.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.mapper.Mapper; 4 | import minecraft.Block; 5 | import minecraft.Position; 6 | import vmfWriter.entity.solidEntity.FuncIllusionary; 7 | 8 | public class TorchWest extends Torch { 9 | 10 | @Override 11 | public void add(Mapper context, Position p, Block material) { 12 | int parts = 32; 13 | Position[] pointOffset = new Position[8]; 14 | 15 | pointOffset[0] = new Position(32, 6, 14); // a 16 | pointOffset[1] = new Position(23, 24, 14); // b 17 | pointOffset[2] = new Position(19, 22, 14); // c 18 | pointOffset[3] = new Position(28, 4, 14); // d 19 | pointOffset[4] = new Position(32, 6, 18); // e 20 | pointOffset[5] = new Position(23, 24, 18); // f 21 | pointOffset[6] = new Position(19, 22, 18); // g 22 | pointOffset[7] = new Position(28, 4, 18); // h 23 | 24 | Position point = Position.create(p); 25 | context.addSolidEntity( 26 | new FuncIllusionary(context.createFree8Point(point, point, parts, pointOffset, true, material))); 27 | context.setPointToGrid(p); 28 | context.movePointInGridDimension((13.0 / 20.0), 0.7, 0.5); 29 | this.addFlame(context); 30 | context.markAsConverted(p); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/actions/actions/VinesEast.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import vmfWriter.entity.solidEntity.FuncIllusionary; 9 | 10 | /** 11 | * 12 | * 13 | */ 14 | public class VinesEast extends Action { 15 | 16 | public VinesEast() { 17 | int[] temp = { MaterialLegacy.VINES }; 18 | super.setMaterialUsedFor(temp); 19 | } 20 | 21 | @Override 22 | public void add(Mapper context, Position p, Block material) { 23 | Position end = context.getCuboidFinder() 24 | .getBestY(p, material); 25 | int parts = 8; 26 | Position offset = new Position(7, 0, 0); 27 | Position negativeOffset = new Position(0, 0, 0); 28 | context.addSolidEntity( 29 | new FuncIllusionary(context.createCuboid(p, end, parts, offset, negativeOffset, material))); 30 | context.markAsConverted(p, end); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/actions/actions/VinesNorth.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import vmfWriter.entity.solidEntity.FuncIllusionary; 9 | 10 | /** 11 | * 12 | * 13 | */ 14 | public class VinesNorth extends Action { 15 | 16 | public VinesNorth() { 17 | int[] temp = { MaterialLegacy.VINES }; 18 | super.setMaterialUsedFor(temp); 19 | } 20 | 21 | @Override 22 | public void add(Mapper context, Position p, Block material) { 23 | Position end = context.getCuboidFinder() 24 | .getBestY(p, material); 25 | int parts = 8; 26 | Position offset = new Position(0, 0, 0); 27 | Position negativeOffset = new Position(0, 0, 7); 28 | context.addSolidEntity( 29 | new FuncIllusionary(context.createCuboid(p, end, parts, offset, negativeOffset, material))); 30 | context.markAsConverted(p, end); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/actions/actions/VinesSouth.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import vmfWriter.entity.solidEntity.FuncIllusionary; 9 | 10 | /** 11 | * 12 | * 13 | */ 14 | public class VinesSouth extends Action { 15 | 16 | public VinesSouth() { 17 | int[] temp = { MaterialLegacy.VINES }; 18 | super.setMaterialUsedFor(temp); 19 | } 20 | 21 | @Override 22 | public void add(Mapper context, Position p, Block material) { 23 | Position end = context.getCuboidFinder() 24 | .getBestY(p, material); 25 | int parts = 8; 26 | Position offset = new Position(0, 0, 7); 27 | Position negativeOffset = new Position(0, 0, 0); 28 | context.addSolidEntity( 29 | new FuncIllusionary(context.createCuboid(p, end, parts, offset, negativeOffset, material))); 30 | context.markAsConverted(p, end); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/actions/actions/VinesWest.java: -------------------------------------------------------------------------------- 1 | package converter.actions.actions; 2 | 3 | import converter.actions.Action; 4 | import converter.mapper.Mapper; 5 | import minecraft.Block; 6 | import minecraft.MaterialLegacy; 7 | import minecraft.Position; 8 | import vmfWriter.entity.solidEntity.FuncIllusionary; 9 | 10 | /** 11 | * 12 | * 13 | */ 14 | public class VinesWest extends Action { 15 | 16 | public VinesWest() { 17 | int[] temp = { MaterialLegacy.VINES }; 18 | super.setMaterialUsedFor(temp); 19 | } 20 | 21 | @Override 22 | public void add(Mapper context, Position p, Block material) { 23 | Position end = context.getCuboidFinder() 24 | .getBestY(p, material); 25 | int parts = 8; 26 | Position offset = new Position(0, 0, 0); 27 | Position negativeOffset = new Position(7, 0, 0); 28 | context.addSolidEntity( 29 | new FuncIllusionary(context.createCuboid(p, end, parts, offset, negativeOffset, material))); 30 | context.markAsConverted(p, end); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/converter/cuboidFinder/CuboidFinder.java: -------------------------------------------------------------------------------- 1 | package converter.cuboidFinder; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | 6 | import minecraft.Block; 7 | import minecraft.Position; 8 | 9 | public abstract class CuboidFinder { 10 | 11 | public Position getBestXYZ(Position position, Block... material) { 12 | return this.getBestXYZ(position, Arrays.asList(material)); 13 | } 14 | 15 | public Position getBestXY(Position position, Block... material) { 16 | return this.getBestXY(position, Arrays.asList(material)); 17 | } 18 | 19 | public Position getBestXZ(Position position, Block... material) { 20 | return this.getBestXZ(position, Arrays.asList(material)); 21 | } 22 | 23 | public Position getBestYZ(Position position, Block... material) { 24 | return this.getBestYZ(position, Arrays.asList(material)); 25 | } 26 | 27 | public Position getBestX(Position position, Block... material) { 28 | return this.getBestX(position, Arrays.asList(material)); 29 | } 30 | 31 | public Position getBestY(Position position, Block... material) { 32 | return this.getBestY(position, Arrays.asList(material)); 33 | } 34 | 35 | public Position getBestZ(Position position, Block... material) { 36 | return this.getBestZ(position, Arrays.asList(material)); 37 | } 38 | 39 | public abstract Position getBestXYZ(Position position, Collection material); 40 | 41 | public abstract Position getBestXY(Position position, Collection material); 42 | 43 | public abstract Position getBestXZ(Position position, Collection material); 44 | 45 | public abstract Position getBestYZ(Position position, Collection material); 46 | 47 | public abstract Position getBestX(Position position, Collection material); 48 | 49 | public abstract Position getBestY(Position position, Collection material); 50 | 51 | public abstract Position getBestZ(Position position, Collection material); 52 | } 53 | -------------------------------------------------------------------------------- /src/converter/mapper/Mapper.java: -------------------------------------------------------------------------------- 1 | package converter.mapper; 2 | 3 | import basic.Tuple; 4 | import converter.ConvertingReport; 5 | import converter.Skins; 6 | import converter.actions.ActionManager; 7 | import converter.cuboidFinder.CuboidFinder; 8 | import converter.cuboidFinder.DefaultCuboidFinder; 9 | import minecraft.Block; 10 | import minecraft.Position; 11 | import minecraft.SubBlockPosition; 12 | import periphery.SourceGame; 13 | import vmfWriter.Cuboid; 14 | import vmfWriter.entity.pointEntity.PointEntity; 15 | 16 | public abstract class Mapper extends SourceMapper { 17 | 18 | private CuboidFinder cuboidFinder = new DefaultCuboidFinder(this); 19 | protected ActionManager convertActions; 20 | private int scale; 21 | 22 | public Mapper() { 23 | } 24 | 25 | public CuboidFinder getCuboidFinder() { 26 | return this.cuboidFinder; 27 | } 28 | 29 | public Mapper setAddableManager(ActionManager addableManager) { 30 | this.convertActions = addableManager; 31 | return this; 32 | } 33 | 34 | @Override 35 | public ConvertingReport prepareWrite(SourceGame game) { 36 | this.addObjects(game); 37 | return null; 38 | } 39 | 40 | public abstract void addObjects(SourceGame game); 41 | 42 | public void addSubBlock(Position position, SubBlockPosition pos, Block materialInt) { 43 | throw new UnsupportedOperationException(); 44 | } 45 | 46 | public Mapper setScale(int scale) { 47 | this.scale = scale; 48 | return this; 49 | } 50 | 51 | public int getScale() { 52 | return this.scale; 53 | } 54 | 55 | @Override 56 | public void movePointInGridDimension(double x, double y, double z) { 57 | // ugly 58 | this.target.movePointInGridDimension(x * this.scale, -z * this.scale, y * this.scale); 59 | } 60 | 61 | @Override 62 | public void movePointExactly(Position offset) { 63 | Position translated = new Position(offset.x, -offset.z, offset.y); 64 | this.target.movePointExactly(translated); 65 | } 66 | 67 | protected Position convert(Position p) { 68 | // z and y axis are switched 69 | // NORTH-SOUTH axis is flipped 70 | return new Position(p.getX() * this.scale, -p.getZ() * this.scale, p.getY() * this.scale); 71 | } 72 | 73 | @Override 74 | public void setPointToGrid(Position position) { 75 | this.target.setPointToGrid(this.convert(position)); 76 | } 77 | 78 | @Override 79 | public Cuboid createCuboid(Position start, Position end, Block material) { 80 | return new Cuboid(this.convertPositions(start, end), Skins.INSTANCE.getSkin(material)); 81 | } 82 | 83 | public Tuple convertPositions(Position start, Position endIn) { 84 | Position end = endIn.getOffset(1, 1, 1); 85 | Position startConverted = this.convert(start); 86 | Position endConverted = this.convert(end); 87 | Position.bringInOrder(startConverted, endConverted); 88 | 89 | return new Tuple<>(startConverted, endConverted); 90 | } 91 | 92 | @Override 93 | public Cuboid createCuboid(Position start, Position end, int parts, Position offset, Position negativeOffset, 94 | Block material) { 95 | double grid = (double) (this.getScale()) / (double) (parts); 96 | Position startNew = new Position(start.x * this.getScale() + offset.x * grid, 97 | (-end.z - 1) * this.getScale() + negativeOffset.z * grid, start.y * this.getScale() + offset.y * grid); 98 | Position endNew = new Position((end.x + 1) * this.getScale() - negativeOffset.x * grid, 99 | -start.z * this.getScale() - offset.z * grid, (end.y + 1) * this.getScale() - negativeOffset.y * grid); 100 | return new Cuboid(new Tuple<>(startNew, endNew), Skins.INSTANCE.getSkin(material)); 101 | } 102 | 103 | // protected abstract boolean needsConversion(Position position); 104 | 105 | public ActionManager getActions() { 106 | return this.convertActions; 107 | } 108 | 109 | public boolean isAirBlock(Position position) { 110 | return this.getActions() 111 | .getAction(this.getBlock(position)) 112 | .isAirBlock(); 113 | } 114 | 115 | // public boolean stillNeedsConversion(Position position) { 116 | // return this.needsConversion(position) && (!this.isConverted(position)); 117 | // } 118 | 119 | public boolean needsConversion(Position position) { 120 | return true; // overwrite me 121 | } 122 | 123 | public abstract void markAsConverted(Position position); 124 | 125 | public abstract void markAsConverted(Position position, Position end); 126 | 127 | @Override 128 | public void addPointEntitys(Position start, Position end, int space, PointEntity type) { 129 | Tuple conveted = this.convertPositions(start, end); 130 | this.addPointEntitys(conveted.getFirst(), conveted.getSecond(), space, type); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/converter/mapper/SourceMapper.java: -------------------------------------------------------------------------------- 1 | package converter.mapper; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import converter.ConvertingReport; 7 | import minecraft.Block; 8 | import minecraft.MinecraftMap; 9 | import minecraft.Position; 10 | import periphery.SourceGame; 11 | import vmfWriter.Cuboid; 12 | import vmfWriter.Free8Point; 13 | import vmfWriter.Solid; 14 | import vmfWriter.SourceMap; 15 | import vmfWriter.entity.pointEntity.PointEntity; 16 | import vmfWriter.entity.solidEntity.SolidEntity; 17 | 18 | public abstract class SourceMapper extends MinecraftMap implements SourceMap { 19 | 20 | protected SourceMap target; 21 | 22 | public SourceMapper() { 23 | } 24 | 25 | public SourceMapper setTarget(SourceMap target) { 26 | this.target = target; 27 | return this; 28 | } 29 | 30 | @Override 31 | public void setSkyTexture(String skyTexture) { 32 | this.target.setSkyTexture(skyTexture); 33 | } 34 | 35 | @Override 36 | public void addSolid(Solid shape) { 37 | this.target.addSolid(shape); 38 | } 39 | 40 | @Override 41 | public void addDetail(Solid... solids) { 42 | this.target.addDetail(solids); 43 | } 44 | 45 | @Override 46 | public PointEntity addPointEntity(PointEntity position) { 47 | return this.target.addPointEntity(position); 48 | } 49 | 50 | @Override 51 | public PointEntity addPointEntity(PointEntity entity, Position position) { 52 | return this.target.addPointEntity(entity, position); 53 | } 54 | 55 | @Override 56 | public void addPointEntity(Position origin, PointEntity type) { 57 | this.target.addPointEntity(origin, type); 58 | } 59 | 60 | @Override 61 | public void addSolidEntity(SolidEntity solidEnttiy) { 62 | this.target.addSolidEntity(solidEnttiy); 63 | } 64 | 65 | @Override 66 | public void setCameraPosition(Position origin) { 67 | this.target.setCameraPosition(origin); 68 | } 69 | 70 | @Override 71 | public void setCameraLook(Position position) { 72 | this.target.setCameraLook(position); 73 | } 74 | 75 | @Override 76 | public ConvertingReport write(File file, SourceGame game) throws IOException { 77 | this.prepareWrite(game); 78 | this.target.write(file, game); 79 | return null; 80 | } 81 | 82 | public abstract ConvertingReport prepareWrite(SourceGame game); 83 | 84 | public abstract Cuboid createCuboid(Position start, Position end, Block material); 85 | 86 | public abstract Cuboid createCuboid(Position start, Position end, int positionarts, Position offset, 87 | Position negativeOffset, Block material); 88 | 89 | public abstract Free8Point createFree8Point(Position start, Position end, int parts, Position[] offset, 90 | boolean align, Block material); 91 | } 92 | -------------------------------------------------------------------------------- /src/converter/mapper/SubblockMapper.java: -------------------------------------------------------------------------------- 1 | package converter.mapper; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | import java.util.SortedMap; 6 | import java.util.TreeMap; 7 | 8 | import basic.Value; 9 | import converter.actions.Action; 10 | import converter.actions.ActionManager; 11 | import converter.actions.actions.DetailBlock; 12 | import minecraft.Block; 13 | import minecraft.Blocks; 14 | import minecraft.Position; 15 | import periphery.SourceGame; 16 | import vmfWriter.Cuboid; 17 | import vmfWriter.Free8Point; 18 | import vmfWriter.Orientation; 19 | import vmfWriter.Ramp; 20 | import vmfWriter.SourceMap; 21 | 22 | public class SubblockMapper extends Mapper { 23 | 24 | private static final Position STEP_NORTH = new Position(0, 0, 1); 25 | private static final Position STEP_SOUTH = new Position(0, 0, -1); 26 | private static final Position STEP_WEST = new Position(1, 0, 0); 27 | private static final Position STEP_EAST = new Position(-1, 0, 0); 28 | 29 | private Set isConverted = new HashSet<>(); 30 | private SortedMap> subBlocks; 31 | 32 | private class RampAddableZ extends Action { 33 | private Orientation orientation; 34 | private Block mStart; 35 | private Block mEnd; 36 | 37 | public RampAddableZ(Orientation orientation, Block mStart, Block mEnd) { 38 | this.orientation = orientation; 39 | this.mStart = mStart; 40 | this.mEnd = mEnd; 41 | } 42 | 43 | @Override 44 | public void add(Mapper context, Position start, Block material) { 45 | Position end = context.getCuboidFinder() 46 | .getBestZ(start, material); 47 | Cuboid cuboid = context.createCuboid(start, end, material); 48 | if (context.hasBlock(Position.add(end, STEP_NORTH), this.mEnd)) { 49 | cuboid.extend(this.orientation, Orientation.NORTH); 50 | } 51 | if (context.hasBlock(Position.add(start, STEP_SOUTH), this.mStart)) { 52 | cuboid.extend(this.orientation, Orientation.SOUTH); 53 | } 54 | Ramp ramp = new Ramp(cuboid, this.orientation); 55 | context.addSolid(ramp); 56 | context.markAsConverted(start, end); 57 | } 58 | 59 | } 60 | 61 | private class RampAddableX extends Action { 62 | private Orientation orientation; 63 | private Block mStart; 64 | private Block mEnd; 65 | 66 | public RampAddableX(Orientation orientation, Block mStart, Block mEnd) { 67 | this.orientation = orientation; 68 | this.mStart = mStart; 69 | this.mEnd = mEnd; 70 | } 71 | 72 | @Override 73 | public void add(Mapper mapper, Position start, Block material) { 74 | Position end = mapper.getCuboidFinder() 75 | .getBestX(start, material); 76 | Cuboid cuboid = mapper.createCuboid(start, end, material); 77 | if (mapper.hasBlock(Position.add(end, STEP_WEST), this.mEnd)) { 78 | cuboid.extend(this.orientation, Orientation.WEST); 79 | } 80 | if (mapper.hasBlock(Position.add(start, STEP_EAST), this.mStart)) { 81 | cuboid.extend(this.orientation, Orientation.EAST); 82 | } 83 | Ramp ramp = new Ramp(cuboid, this.orientation); 84 | mapper.addSolid(ramp); 85 | mapper.markAsConverted(start, end); 86 | } 87 | } 88 | 89 | public SubblockMapper(SourceMap target, int originalScale) { 90 | ActionManager addableManager = new ActionManager(new DetailBlock()) 91 | .setAction(Blocks._RAMP_EAST, 92 | new RampAddableZ(Orientation.EAST, Blocks._RAMP_SOUTH_EAST, Blocks._RAMP_NORTH_EAST)) 93 | .setAction(Blocks._RAMP_WEST, 94 | new RampAddableZ(Orientation.WEST, Blocks._RAMP_SOUTH_WEST, Blocks._RAMP_NORTH_WEST)) 95 | .setAction(Blocks._RAMP_NORTH, 96 | new RampAddableX(Orientation.NORTH, Blocks._RAMP_NORTH_EAST, Blocks._RAMP_NORTH_WEST)) 97 | .setAction(Blocks._RAMP_SOUTH, 98 | new RampAddableX(Orientation.SOUTH, Blocks._RAMP_SOUTH_EAST, Blocks._RAMP_SOUTH_WEST)) 99 | // .setAddable(Arrays.asList(Material._RAMP_NORTH_EAST, Material._RAMP_NORTH_WEST, 100 | // Material._RAMP_SOUTH_EAST, Material._RAMP_SOUTH_WEST), new Debug()) 101 | ; 102 | this.setAddableManager(addableManager); 103 | this.setTarget(target); 104 | this.subBlocks = new TreeMap<>(); 105 | this.setScale(originalScale / 2); 106 | } 107 | 108 | @Override 109 | public void addObjects(SourceGame game) { 110 | this.subBlocks.forEach((position, block) -> { 111 | if (this.needsConversion(position)) { 112 | this.convertActions.add(this, position, block.get()); 113 | } 114 | }); 115 | } 116 | 117 | @Override 118 | public Block getBlock(Position position) { 119 | Value value = this.subBlocks.get(position); 120 | if (value == null) { 121 | return Blocks._UNSET; 122 | } 123 | return value.get(); 124 | } 125 | 126 | @Override 127 | public void markAsConverted(Position position) { 128 | this.isConverted.add(position); 129 | } 130 | 131 | @Override 132 | public void markAsConverted(Position start, Position end) { 133 | for (int xMark = start.getX(); xMark <= end.getX(); xMark++) { 134 | for (int yMark = start.getY(); yMark <= end.getY(); yMark++) { 135 | for (int zMark = start.getZ(); zMark <= end.getZ(); zMark++) { 136 | this.markAsConverted(new Position(xMark, yMark, zMark)); 137 | } 138 | } 139 | } 140 | } 141 | 142 | @Override 143 | public void setBlock(Position position, Block material) { 144 | this.subBlocks.put(position, new Value().set(material)); 145 | } 146 | 147 | @Override 148 | public Free8Point createFree8Point(Position start, Position end, int parts, Position[] offset, boolean align, 149 | Block material) { 150 | // not supported 151 | return null; 152 | } 153 | 154 | @Override 155 | public boolean needsConversion(Position position) { 156 | return !this.isConverted.contains(position); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/gui/SimpleTextFieldChangeListener.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javax.swing.JTextField; 4 | import javax.swing.event.DocumentEvent; 5 | import javax.swing.event.DocumentListener; 6 | 7 | public class SimpleTextFieldChangeListener implements DocumentListener { 8 | 9 | private Runnable action; 10 | 11 | public SimpleTextFieldChangeListener(Runnable action) { 12 | this.action = action; 13 | } 14 | 15 | @Override 16 | public void changedUpdate(DocumentEvent arg0) { 17 | this.action.run(); 18 | } 19 | 20 | @Override 21 | public void insertUpdate(DocumentEvent arg0) { 22 | this.action.run(); 23 | } 24 | 25 | @Override 26 | public void removeUpdate(DocumentEvent arg0) { 27 | this.action.run(); 28 | } 29 | 30 | public static void addTo(JTextField textField, Runnable action) { 31 | textField.getDocument() 32 | .addDocumentListener(new SimpleTextFieldChangeListener(action)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/gui/WorldComboboxRenderer.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import java.awt.Color; 4 | import java.awt.Component; 5 | 6 | import javax.swing.JLabel; 7 | import javax.swing.JList; 8 | import javax.swing.ListCellRenderer; 9 | 10 | import minecraft.World; 11 | 12 | public class WorldComboboxRenderer extends JLabel implements ListCellRenderer { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -1184215949297548461L; 18 | 19 | private static final Color NIMBUS_FOCUS = new Color(51, 98, 140); 20 | 21 | public WorldComboboxRenderer() { 22 | // setOpaque(true); 23 | this.setVerticalAlignment(CENTER); 24 | } 25 | 26 | /* 27 | * This method finds the image and text corresponding to the selected value and 28 | * returns the label, set up to display the text and image. 29 | */ 30 | @Override 31 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 32 | boolean cellHasFocus) { 33 | this.setText(""); 34 | if (value instanceof World) { 35 | World world = (World) value; 36 | this.setIcon(world.getIcon()); 37 | this.setText(world.toString()); 38 | } 39 | if (isSelected) { 40 | this.setForeground(Color.WHITE); 41 | this.setBackground(NIMBUS_FOCUS); 42 | } else { 43 | this.setForeground(Color.BLACK); 44 | this.setBackground(Color.WHITE); 45 | } 46 | 47 | return this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/gui/panel/LabeledCoordinates.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import minecraft.Position; 4 | 5 | public class LabeledCoordinates { 6 | 7 | private String name; 8 | 9 | private Position start; 10 | private Position end; 11 | 12 | public LabeledCoordinates(String name) { 13 | this(name, null, null); 14 | } 15 | 16 | public LabeledCoordinates(String name, Position start, Position end) { 17 | this.name = name; 18 | this.start = start; 19 | this.end = end; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return this.name; 25 | } 26 | 27 | public Position getStart() { 28 | return this.start; 29 | } 30 | 31 | public Position getEnd() { 32 | return this.end; 33 | } 34 | 35 | public String getDebugInfo() { 36 | return this.name + " " + this.start.toString() + " " + this.end.toString(); 37 | } 38 | 39 | public void enlarge(Position lowering, Position highering) { 40 | this.start = Position.add(this.start, lowering); 41 | this.end = Position.add(this.end, highering); 42 | } 43 | 44 | @Override 45 | public boolean equals(Object other) { 46 | if (!(other instanceof LabeledCoordinates)) { 47 | return false; 48 | } 49 | return this.name.equals(((LabeledCoordinates) other).name); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/ConvertTask.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import periphery.ConvertOption; 4 | import periphery.Place; 5 | import periphery.SourceGame; 6 | import periphery.TexturePack; 7 | 8 | public class ConvertTask { 9 | 10 | private Place place; 11 | private SourceGame game; 12 | private ConvertOption option; 13 | private TexturePack texturePack; 14 | private boolean updateTextures; 15 | 16 | public ConvertTask() { 17 | 18 | } 19 | 20 | public boolean getUpdateTextures() { 21 | return this.updateTextures; 22 | } 23 | 24 | public void setUpdateTextures(boolean copyTextures) { 25 | this.updateTextures = copyTextures; 26 | } 27 | 28 | public Place getPlace() { 29 | return this.place; 30 | } 31 | 32 | public void setPlace(Place place) { 33 | this.place = place; 34 | } 35 | 36 | public SourceGame getGame() { 37 | return this.game; 38 | } 39 | 40 | public void setGame(SourceGame game) { 41 | this.game = game; 42 | } 43 | 44 | public ConvertOption getOption() { 45 | return this.option; 46 | } 47 | 48 | public void setOption(ConvertOption option) { 49 | this.option = option; 50 | } 51 | 52 | public TexturePack getTexturePack() { 53 | return this.texturePack; 54 | } 55 | 56 | public void setTexturePack(TexturePack texturePack) { 57 | this.texturePack = texturePack; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/Main.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import java.io.File; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import basic.Loggger; 8 | import converter.Converter; 9 | import gui.Gui; 10 | import minecraft.MaterialLegacy; 11 | import minecraft.World; 12 | import periphery.ConvertOption; 13 | import periphery.Periphery; 14 | import periphery.Place; 15 | import periphery.Steam; 16 | import periphery.TexturePack; 17 | 18 | public class Main { 19 | 20 | public static final String TITLE = "Sourcecraft - Minecraft to VMF converter"; 21 | public static final String VERSION = "3.1+"; 22 | public static final String AUTHOR = "garten"; 23 | public static final String LICENSE = "GNU General Public License v3.0"; 24 | public static final String LICENSE_INFO = "https://www.gnu.org/licenses/gpl-3.0.html"; 25 | 26 | private Converter converter; 27 | private Gui gui; 28 | 29 | public static boolean isUnix() { 30 | String OS = System.getProperty("os.name") 31 | .toLowerCase(); 32 | return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0); 33 | } 34 | 35 | public static void main(String[] args) { 36 | new Main(); 37 | } 38 | 39 | public Main() { 40 | MaterialLegacy.init(); 41 | Periphery.init(); 42 | 43 | this.gui = new Gui(TITLE + " " + VERSION); 44 | 45 | new GuiLogic().accept(this.gui); 46 | 47 | this.gui.setUponRun(() -> { 48 | this.saveNewPlace(); 49 | 50 | File output = new File(this.gui.getOutputFile()); 51 | ConvertTask data = this.getConverterData(); 52 | if (data == null) { 53 | return; 54 | } 55 | this.converter = new Converter(data); 56 | this.converter.convert(output); 57 | if (data.getUpdateTextures()) { 58 | final TexturePack pack = data.getTexturePack(); 59 | if (!Steam.areTexturesUpToDate(data.getGame(), pack)) { 60 | File targetDirectory = data.getGame() 61 | .getMatriealPath(pack); 62 | if (targetDirectory.exists()) { 63 | TextureFolderMover.copyFolder(pack.getFolder(), data.getGame() 64 | .getMatriealPath(pack)); 65 | } else if (targetDirectory.getParentFile() 66 | .getParentFile() 67 | .exists()) { 68 | targetDirectory.getParentFile() 69 | .mkdir(); // Garrysmod comes without material folder 70 | TextureFolderMover.copyFolder(pack.getFolder(), data.getGame() 71 | .getMatriealPath(pack)); 72 | } else { 73 | Loggger.log("Not copying textures. The directory " + targetDirectory 74 | + " does not exist. Have you launched " + data.getGame() 75 | .getLongName() 76 | + " at least once?"); 77 | } 78 | } 79 | } 80 | 81 | data.getGame() 82 | .setGameTargetSavePath(output); 83 | Periphery.CONFIG.setConvertData(data); 84 | Periphery.CONFIG.setMinecraftPath(this.gui.getMincraftPath()); 85 | Periphery.CONFIG.setSteamPath(this.gui.getSourcePath()); 86 | Periphery.write(); 87 | 88 | // result 89 | String outputLast = output.getName(); 90 | this.gui.setDisplayedOutputName(outputLast); 91 | this.gui.setLabelOutputPath(output.getName()); 92 | this.gui.setDisplayOpenFor(data.getGame() 93 | .getLongName()); 94 | this.gui.setPanelResultVisible(); 95 | }); 96 | } 97 | 98 | /** 99 | * returns true if place has been found. 100 | */ 101 | private void saveNewPlace() { 102 | if (this.gui.getRememberPlaceSelected()) { 103 | String name = this.gui.getSaveLocation(); 104 | if (name != null && name.length() > 0) { 105 | Loggger.log("Saving new place " + name + "."); 106 | Place place = this.gui.getPlaceFromCoordinates(); 107 | Periphery.PLACES.addPlace(place); 108 | } 109 | } else { 110 | Place place = this.gui.getPlace(); 111 | Place placeFromCoordinates = this.gui.getPlaceFromCoordinates(); 112 | if (place != null) { 113 | place.setTo(placeFromCoordinates); 114 | } 115 | } 116 | } 117 | 118 | private void moveFolder(File materiaPath) { 119 | Object[] options = { "Cancel", "Copy" }; 120 | String title = "Copy textures"; 121 | String question = "This copies \"" + Periphery.CONFIG.getTexturePack() + "\"-textures to \n\"" + materiaPath 122 | + "\\\"\n as desired by Valve's Hammer Editor."; 123 | int n = JOptionPane.showOptionDialog(null, question, title, JOptionPane.YES_NO_CANCEL_OPTION, 124 | JOptionPane.PLAIN_MESSAGE, null, options, options[1]); 125 | if (n == 1) { 126 | File srcFolder = new File("textures" + File.separator + Periphery.CONFIG.getTexturePack()); 127 | TextureFolderMover.moveFolderOld(materiaPath, srcFolder); 128 | } 129 | } 130 | 131 | public ConvertTask getConverterData() { 132 | ConvertTask converterData = new ConvertTask(); 133 | 134 | Place place = this.gui.getPlaceFromCoordinates(); 135 | World world = this.gui.getWorld(); 136 | if (world == null) { 137 | return null; 138 | } 139 | String worldName = world.toString(); 140 | Loggger.log("world = " + worldName); 141 | if (place == null) { 142 | Loggger.warn("Place not found"); 143 | } 144 | place.setWorld(worldName); 145 | converterData.setPlace(place); 146 | 147 | converterData.setGame(this.gui.getSourceGame()); 148 | 149 | // option 150 | String optionName = this.gui.getConvertOption(); 151 | Loggger.log("option = " + optionName); 152 | ConvertOption option = Periphery.CONFIG.getConvertOption(optionName); 153 | converterData.setOption(option); 154 | 155 | // textures 156 | converterData.setTexturePack(TexturePack.getTexturePack(this.gui.getTexturePack())); 157 | converterData.setUpdateTextures(this.gui.getUpdateTextures()); 158 | return converterData; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/main/TextureFolderMover.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | 10 | public class TextureFolderMover { 11 | 12 | public static void copyFolder(File srcFolder, File destFolder) { 13 | try { 14 | TextureFolderMover.copyFolderIntern(srcFolder, destFolder); 15 | } catch (IOException e) { 16 | e.printStackTrace(); 17 | } 18 | } 19 | 20 | public static void moveFolderOld(File destFolder, File srcFolder) { 21 | try { 22 | TextureFolderMover.copyFolderIntern(srcFolder, destFolder); 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | private static void copyFolderIntern(File source, File dest) throws IOException { 29 | if (source.isDirectory()) { 30 | if (!dest.exists()) { 31 | dest.mkdir(); 32 | } 33 | 34 | String files[] = source.list(); 35 | 36 | for (String file : files) { 37 | File srcFile = new File(source, file); 38 | File destFile = new File(dest, file); 39 | TextureFolderMover.copyFolderIntern(srcFile, destFile); 40 | } 41 | } else { 42 | InputStream in = new FileInputStream(source); 43 | OutputStream out = new FileOutputStream(dest); 44 | 45 | byte[] buffer = new byte[1024]; 46 | 47 | int length; 48 | while ((length = in.read(buffer)) > 0) { 49 | out.write(buffer, 0, length); 50 | } 51 | in.close(); 52 | out.close(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/minecraft/Area.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.util.Iterator; 4 | 5 | public class Area implements Iterable { 6 | 7 | private Position lower; 8 | private Position higher; 9 | 10 | public Area(Position lower, Position higher) { 11 | this.lower = Position.create(lower); 12 | this.higher = Position.create(higher); 13 | } 14 | 15 | public Position getLower() { 16 | return this.lower; 17 | } 18 | 19 | public Area setLower(Position lower) { 20 | this.lower = lower; 21 | return this; 22 | } 23 | 24 | public Position getHigher() { 25 | return this.higher; 26 | } 27 | 28 | public Area setHigher(Position higher) { 29 | this.higher = higher; 30 | return this; 31 | } 32 | 33 | @Override 34 | public Iterator iterator() { 35 | return new Iterator() { 36 | 37 | Position current = Position.create(Area.this.lower); 38 | 39 | @Override 40 | public boolean hasNext() { 41 | return (this.current != null && this.current.x <= Area.this.higher.x 42 | && this.current.y <= Area.this.higher.y && this.current.z <= Area.this.higher.z); 43 | } 44 | 45 | @Override 46 | public Position next() { 47 | if (this.current == null) { 48 | return null; 49 | } 50 | Position result = Position.create(this.current); 51 | if (this.current.x < Area.this.higher.x) { 52 | this.current.x++; 53 | } else if (this.current.y < Area.this.higher.y) { 54 | this.current.y++; 55 | this.current.x = Area.this.lower.x; 56 | } else if (this.current.z < Area.this.higher.z) { 57 | this.current.z++; 58 | this.current.x = Area.this.lower.x; 59 | this.current.y = Area.this.lower.y; 60 | } else { 61 | this.current = null; 62 | } 63 | return result; 64 | } 65 | 66 | }; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/minecraft/Block.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.util.Map; 4 | import java.util.Objects; 5 | import java.util.function.Predicate; 6 | import java.util.function.Supplier; 7 | 8 | public abstract class Block implements Supplier, Predicate { 9 | 10 | public abstract String getName(); 11 | 12 | public abstract Map getProperties(); 13 | 14 | public String getProperty(Property property) { 15 | return this.getProperties() 16 | .get(property.name()); 17 | } 18 | 19 | @Override 20 | public Block get() { 21 | return this; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(this.getName(), this.getProperties()); 27 | } 28 | 29 | @Override 30 | public boolean test(Block containee) { 31 | return this.equals(containee); 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) { 37 | return true; 38 | } 39 | if (!(obj instanceof Block)) { 40 | return false; 41 | } 42 | Block other = (Block) obj; 43 | boolean result = Objects.equals(this.getName(), other.getName()) 44 | && Objects.equals(this.getProperties(), other.getProperties()); 45 | return result; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | Map properties = this.getProperties(); 51 | if (properties == null) { 52 | return this.getName(); 53 | } 54 | return this.getName() + properties.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/minecraft/BlockTemplate.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import basic.NameSupplier; 7 | 8 | public class BlockTemplate extends Block { 9 | 10 | private String title; 11 | private Map properties; 12 | 13 | public BlockTemplate() { 14 | } 15 | 16 | public BlockTemplate setName(Material material) { 17 | this.title = material.getName(); 18 | return this; 19 | } 20 | 21 | public BlockTemplate setName(String title) { 22 | this.title = title; 23 | return this; 24 | } 25 | 26 | public BlockTemplate setProperties(Map properties) { 27 | this.properties = properties; 28 | return this; 29 | } 30 | 31 | public BlockTemplate addProperty(String property, String value) { 32 | return this.addProperty(() -> property, () -> value); 33 | } 34 | 35 | public BlockTemplate addProperty(NameSupplier property, NameSupplier value) { 36 | if (this.properties == null) { 37 | this.properties = new HashMap(); 38 | } 39 | this.properties.put(property.getName(), value.getName()); 40 | return this; 41 | } 42 | 43 | public BlockTemplate copyFrom(Block template) { 44 | this.title = template.getName(); 45 | this.properties = template.getProperties(); 46 | return this; 47 | } 48 | 49 | public BlockTemplate reset() { 50 | this.title = null; 51 | this.properties = null; 52 | return this; 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | return this.title; 58 | } 59 | 60 | @Override 61 | public Map getProperties() { 62 | return this.properties; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/minecraft/Blocks.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.function.Consumer; 7 | import java.util.function.Supplier; 8 | 9 | import basic.IOConsumer; 10 | import periphery.Minecraft; 11 | 12 | /** 13 | * Class that lets you create immutable {@code Block} instances without 14 | * duplicates. 15 | */ 16 | public class Blocks { 17 | public static final Blocks I = new Blocks(); 18 | private static final BlockTemplate TEMPLATE = new BlockTemplate(); 19 | public static final Map KNOWN = new HashMap(); 20 | 21 | public static final Block _UNSET = Blocks.get(t -> t.setName("_unset")); 22 | 23 | public static Block _RAMP_SOUTH_EAST = Blocks.get(t -> t.setName("sourcecraft:ramp_south_east")); 24 | public static Block _RAMP_NORTH_EAST = Blocks.get(t -> t.setName("sourcecraft:ramp_nort_east")); 25 | public static Block _RAMP_SOUTH_WEST = Blocks.get(t -> t.setName("sourcecraft:ramp_south_west")); 26 | public static Block _RAMP_NORTH_WEST = Blocks.get(t -> t.setName("sourcecraft:ramp_north_west")); 27 | 28 | public static Block _RAMP_NORTH = Blocks.get(t -> t.setName("sourcecraft:ramp_north")); 29 | public static Block _RAMP_EAST = Blocks.get(t -> t.setName("sourcecraft:ramp_east")); 30 | public static Block _RAMP_SOUTH = Blocks.get(t -> t.setName("sourcecraft:ramp_south")); 31 | public static Block _RAMP_WEST = Blocks.get(t -> t.setName("sourcecraft:ramp_west")); 32 | 33 | private static Block get() { 34 | Block hashed = KNOWN.get(TEMPLATE); 35 | if (hashed != null) { 36 | TEMPLATE.reset(); 37 | return hashed; 38 | } 39 | Block lookup = I.new ImmutableBlock(TEMPLATE); 40 | KNOWN.put(lookup, lookup); 41 | return lookup; 42 | } 43 | 44 | public static Block get(Consumer setter) { 45 | TEMPLATE.reset(); 46 | setter.accept(TEMPLATE); 47 | return get(); 48 | } 49 | 50 | public static Block get(Supplier> supplier) { 51 | return get(supplier.get()); 52 | } 53 | 54 | public static Block get(String title) { 55 | return get(t -> t.setName(title)); 56 | } 57 | 58 | public static Block getMC(String title) { 59 | return get(t -> t.setName(Minecraft.toMaterial(title))); 60 | } 61 | 62 | public Block getIO(IOConsumer setter) throws IOException { 63 | TEMPLATE.reset(); 64 | setter.run(TEMPLATE); 65 | return get(); 66 | } 67 | 68 | public class ImmutableBlock extends Block { 69 | 70 | private final String title; 71 | private final Map properties; 72 | 73 | ImmutableBlock(BlockTemplate template) { 74 | this.title = template.getName(); 75 | this.properties = template.getProperties(); 76 | } 77 | 78 | @Override 79 | public String getName() { 80 | return this.title; 81 | } 82 | 83 | @Override 84 | public Map getProperties() { 85 | return this.properties; 86 | } 87 | 88 | @Override 89 | public String getProperty(Property property) { 90 | return this.properties.get(property.toString()); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/minecraft/MinecraftMap.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.util.Collection; 4 | import java.util.function.Predicate; 5 | 6 | public abstract class MinecraftMap { 7 | 8 | public abstract Block getBlock(Position position); 9 | 10 | public abstract void setBlock(Position position, Block block); 11 | 12 | public boolean hasBlock(Position position, Predicate container) { 13 | return container.test(this.getBlock(position)); 14 | } 15 | 16 | public boolean hasBlock(Position position, Collection blocks) { 17 | return this.hasBlock(position, block -> blocks.contains(block)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/minecraft/Property.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import basic.NameSupplier; 4 | 5 | public enum Property implements NameSupplier { 6 | half, 7 | facing, 8 | shape, 9 | waterlogged; 10 | 11 | public enum Half implements NameSupplier { 12 | top, 13 | bottom, 14 | double$; 15 | } 16 | 17 | public enum Facing implements NameSupplier { 18 | north, 19 | east, 20 | south, 21 | west 22 | } 23 | 24 | public enum Shape implements NameSupplier { 25 | inner_left, 26 | inner_right, 27 | outer_left, 28 | outer_right, 29 | straight 30 | } 31 | 32 | public enum Waterlogged implements NameSupplier { 33 | true$, 34 | false$; 35 | } 36 | } -------------------------------------------------------------------------------- /src/minecraft/SubBlockPosition.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import basic.Loggger; 4 | 5 | public enum SubBlockPosition { 6 | // order is crucial 7 | BOTTOM_WEST_NORTH, 8 | BOTTOM_WEST_SOUTH, 9 | BOTTOM_EAST_NORTH, 10 | BOTTOM_EAST_SOUTH, 11 | TOP_WEST_NORTH, 12 | TOP_WEST_SOUTH, 13 | TOP_EAST_NORTH, 14 | TOP_EAST_SOUTH; 15 | 16 | public static int getPos(SubBlockPosition pos) { 17 | switch (pos) { 18 | case BOTTOM_WEST_NORTH: 19 | return 0; 20 | case BOTTOM_WEST_SOUTH: 21 | return 1; 22 | case BOTTOM_EAST_NORTH: 23 | return 2; 24 | case BOTTOM_EAST_SOUTH: 25 | return 3; 26 | case TOP_WEST_NORTH: 27 | return 4; 28 | case TOP_WEST_SOUTH: 29 | return 5; 30 | case TOP_EAST_NORTH: 31 | return 6; 32 | case TOP_EAST_SOUTH: 33 | return 7; 34 | default: 35 | Loggger.warn("default case of subBlocks occured"); 36 | return 0; 37 | } 38 | } 39 | 40 | public static Position getPosition(SubBlockPosition pos) { 41 | int x = 1; 42 | int y = 1; 43 | int z = 1; 44 | Position position; 45 | switch (pos) { 46 | case BOTTOM_EAST_SOUTH: 47 | position = new Position(x, y - 1, z); 48 | break; 49 | case BOTTOM_EAST_NORTH: 50 | position = new Position(x, y - 1, z - 1); 51 | break; 52 | case BOTTOM_WEST_SOUTH: 53 | position = new Position(x - 1, y - 1, z); 54 | break; 55 | case BOTTOM_WEST_NORTH: 56 | position = new Position(x - 1, y - 1, z - 1); 57 | break; 58 | case TOP_EAST_SOUTH: 59 | position = new Position(x, y, z); 60 | break; 61 | case TOP_EAST_NORTH: 62 | position = new Position(x, y, z - 1); 63 | break; 64 | case TOP_WEST_SOUTH: 65 | position = new Position(x - 1, y, z); 66 | break; 67 | case TOP_WEST_NORTH: 68 | position = new Position(x - 1, y, z - 1); 69 | break; 70 | default: 71 | position = new Position(1, 1, 1); 72 | Loggger.warn("default cse of subBlocks occured"); 73 | break; 74 | } 75 | return position; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/minecraft/World.java: -------------------------------------------------------------------------------- 1 | package minecraft; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.DataInputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.nio.file.Path; 9 | import java.util.zip.GZIPInputStream; 10 | 11 | import javax.swing.ImageIcon; 12 | 13 | import basic.Loggger; 14 | import gui.panel.LabeledCoordinates; 15 | import nbtReader.PlayerInLevelReader; 16 | import periphery.Minecraft; 17 | import periphery.Periphery; 18 | 19 | public class World { 20 | 21 | public static final String PLAYER_POSITION = "Player position"; 22 | 23 | private static final String WORLD_LEVEL_DAT_NAME = "level.dat"; 24 | 25 | private static final String WORLD_ICON_NAME = "icon.png"; 26 | 27 | private static final int ICON_SIZE = 64; 28 | 29 | private String name; 30 | 31 | private ImageIcon icon; 32 | 33 | private LabeledCoordinates playerPosition; 34 | private LabeledCoordinates worldSpawnPosition; 35 | 36 | public World(String name) { 37 | this(Minecraft.getMinecraftPath(), name); 38 | } 39 | 40 | public World(Path parent, String name) { 41 | try { // TODO 42 | this.name = name; 43 | Path path = parent.resolve(this.getName()) 44 | .resolve(WORLD_LEVEL_DAT_NAME); 45 | // Path path = Paths.get(Minecraft.getMinecraftPath(), this.getName(), WORLD_LEVEL_DAT_NAME); 46 | // File file = new File(Periphery.CONFIG.getWorldPath(this), WORLD_LEVEL_DAT_NAME); 47 | Position player = new Position(); 48 | Position worldSpawn = new Position(); 49 | DataInputStream stream; 50 | 51 | stream = new DataInputStream(new GZIPInputStream(new FileInputStream(path.toFile()))); 52 | 53 | PlayerInLevelReader reader = new PlayerInLevelReader(stream); 54 | reader.read(); 55 | player = reader.getPlayerPosition(); 56 | worldSpawn = reader.getWorldSpawn(); 57 | this.playerPosition = new LabeledCoordinates(PLAYER_POSITION, player, player); 58 | this.worldSpawnPosition = new LabeledCoordinates("World spawn", worldSpawn, worldSpawn); 59 | this.playerPosition.enlarge(new Position(-20, -30, -20), new Position(20, 30, 20)); 60 | this.worldSpawnPosition.enlarge(new Position(-20, -30, -20), new Position(20, 30, 20)); 61 | } catch (IOException e) { 62 | Loggger.log("Cannot find world \"" + name + "\" in " + parent); 63 | } 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return this.name; 69 | } 70 | 71 | @Override 72 | public boolean equals(Object another) { 73 | if (another instanceof World == false) { 74 | return false; 75 | } 76 | World anotherWorld = (World) another; 77 | return this.name.equals(anotherWorld.name); 78 | } 79 | 80 | public ImageIcon getIcon() { 81 | if (this.icon == null) { 82 | File path = new File(Periphery.CONFIG.getWorldPath(this), WORLD_ICON_NAME); 83 | ImageIcon icon; 84 | if (path.exists()) { 85 | icon = new ImageIcon(path.toString()); 86 | this.icon = new ImageIcon(icon.getImage() 87 | .getScaledInstance(ICON_SIZE, ICON_SIZE, 0)); 88 | } else { 89 | this.icon = new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB) 90 | .getScaledInstance(ICON_SIZE, ICON_SIZE, 0)); 91 | } 92 | 93 | } 94 | return this.icon; 95 | } 96 | 97 | public LabeledCoordinates getPlayerPosition() { 98 | return this.playerPosition; 99 | } 100 | 101 | public LabeledCoordinates getWorldSpawnPosition() { 102 | return this.worldSpawnPosition; 103 | } 104 | 105 | public String getName() { 106 | return this.name; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/nbtReader/BitNbtReader.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.IOException; 4 | 5 | public class BitNbtReader { 6 | 7 | private static final int LONG_END = 64; 8 | 9 | private NbtReader source; 10 | private long amount; 11 | private long currentByte; 12 | private long currentPos = LONG_END; 13 | 14 | public BitNbtReader(NbtReader source, int amount) { 15 | this.source = source; 16 | this.amount = amount; 17 | } 18 | 19 | public int readBits() throws IOException { 20 | long result = 0; 21 | long resultPos = 0; 22 | for (int i = 0; i < this.amount; i++) { 23 | if (this.currentPos == LONG_END) { 24 | this.currentPos = 0; 25 | this.currentByte = this.source.readLong(); 26 | } 27 | long bit = (this.currentByte >> this.currentPos) & 1L; 28 | long mask = (bit << resultPos); 29 | result = result | mask; 30 | resultPos++; 31 | this.currentPos++; 32 | } 33 | return (int) result; 34 | } 35 | } -------------------------------------------------------------------------------- /src/nbtReader/ChunkPosition.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import minecraft.Position; 4 | import periphery.Minecraft; 5 | 6 | public class ChunkPosition { 7 | 8 | private int x; 9 | private int z; 10 | 11 | public ChunkPosition(Position position) { 12 | this(obtainChunkCoordinate(position.getX()), obtainChunkCoordinate(position.getZ())); 13 | } 14 | 15 | private static int obtainChunkCoordinate(int value) { 16 | if (value >= 0) { 17 | return value / Minecraft.CHUNK_SIZE_X; 18 | } else { 19 | return -((-value - 1) / Minecraft.CHUNK_SIZE_X) - 1; 20 | // treat value as a positive value 21 | // due to java rounds towards 0, and not down 22 | } 23 | } 24 | 25 | public ChunkPosition(int x, int z) { 26 | this.x = x; 27 | this.z = z; 28 | } 29 | 30 | public int getX() { 31 | return this.x; 32 | } 33 | 34 | public int getZ() { 35 | return this.z; 36 | } 37 | 38 | public Position getMaxPosition() { 39 | int resultX = ((this.x + 1) * Minecraft.CHUNK_SIZE_X) - 1; 40 | int resultZ = ((this.z + 1) * Minecraft.CHUNK_SIZE_Z) - 1; 41 | return new Position(resultX, Minecraft.MAX_Y, resultZ); 42 | } 43 | 44 | public ChunkPosition copy() { 45 | return new ChunkPosition(this.x, this.z); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "[" + this.x + " " + this.z + "]"; 51 | } 52 | 53 | public String toFileName() { 54 | return "r." + this.x + "." + this.z + "." + Minecraft.ANVIL_ENDING; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/nbtReader/ChunkReader.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | import converter.Converter; 7 | import minecraft.Block; 8 | import minecraft.Blocks; 9 | 10 | public class ChunkReader extends NbtReader { 11 | 12 | private static final NamedTag Y = new NamedTag(NbtTag.BYTE, "Y"); 13 | private static final NamedTag SECTIONS = new NamedTag(NbtTag.LIST, "Sections"); 14 | private static final NamedTag PALETTE = new NamedTag(NbtTag.LIST, "Palette"); 15 | private static final NamedTag BLOCK_STATES = new NamedTag(NbtTag.LONG_ARRAY, "BlockStates"); 16 | 17 | private static final NamedTag PALETTE_NAME = new NamedTag(NbtTag.STRING, "Name"); 18 | private static final NamedTag PALETTE_PROPERTIES = new NamedTag(NbtTag.COMPOUND, "Properties"); 19 | 20 | private static final NamedTag LEVEL = new NamedTag(NbtTag.COMPOUND, "Level"); 21 | 22 | private Converter map; 23 | private WorldPiece convertee; 24 | 25 | public ChunkReader(DataInputStream stream, Converter map, WorldPiece convertee) { 26 | super(stream); 27 | this.map = map; 28 | this.convertee = convertee; 29 | } 30 | 31 | public void readChunk() throws IOException { 32 | if (this.readTag() == NbtTag.COMPOUND) { 33 | this.readTitle(); 34 | this.doCompound(NbtTasks.I.create() 35 | .put(LEVEL, () -> this.doCompound(NbtTasks.I.create() 36 | .put(SECTIONS, this::readSections)))); 37 | } 38 | } 39 | 40 | private void readSections() throws IOException { 41 | this.doListOfCompounds(() -> { 42 | Section section = this.readSection(); 43 | this.map.addMcaSection(section); 44 | }); 45 | } 46 | 47 | /** 48 | * Reads the section after the title has already be been read. 49 | */ 50 | private Section readSection() throws IOException { 51 | Section section = new Section(this.convertee); 52 | this.doCompound(NbtTasks.I.create() 53 | .put(Y, () -> section.setHeight(this.readByte())) 54 | .put(BLOCK_STATES, () -> section.readBlocksRaw(this)) 55 | .put(PALETTE, () -> this.readPalette(section))); 56 | return section; 57 | } 58 | 59 | private void readPalette(Section section) throws IOException { 60 | this.doListOfCompounds(pos -> { 61 | section.addPalette(pos, this.readBlock()); 62 | }); 63 | } 64 | 65 | private Block readBlock() throws IOException { 66 | return Blocks.I.getIO(template -> { 67 | this.doCompound(NbtTasks.I.create() 68 | .put(PALETTE_NAME, () -> template.setName(this.readString())) 69 | .put(PALETTE_PROPERTIES, 70 | () -> this.doCompond(title -> template.addProperty(title, this.readString())))); 71 | }); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/nbtReader/NamedTag.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.util.Objects; 4 | 5 | public class NamedTag { 6 | 7 | private int tag; 8 | private String name; 9 | 10 | public NamedTag(int tag, String name) { 11 | this.tag = tag; 12 | this.name = name; 13 | } 14 | 15 | public String getName() { 16 | return this.name; 17 | } 18 | 19 | public int getTag() { 20 | return this.tag; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | return Objects.hash(name, tag); 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | if (this == obj) { 31 | return true; 32 | } 33 | if (!(obj instanceof NamedTag)) { 34 | return false; 35 | } 36 | NamedTag other = (NamedTag) obj; 37 | return Objects.equals(name, other.name) && tag == other.tag; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/nbtReader/NbtTag.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | public class NbtTag { 4 | 5 | public static final int END = 0; 6 | public static final int BYTE = 1; 7 | public static final int SHORT = 2; // two bytes 8 | public static final int INT = 3; 9 | public static final int LONG = 4; 10 | public static final int FLOAT = 5; 11 | public static final int DOUBLE = 6; 12 | public static final int BYTE_ARRAY = 7; 13 | public static final int STRING = 8; 14 | public static final int LIST = 9; 15 | public static final int COMPOUND = 10; // for whole list 16 | public static final int INT_ARRAY = 11; 17 | public static final int LONG_ARRAY = 12; 18 | 19 | public static String get(int tag) { 20 | switch (tag) { 21 | case 0: 22 | return "END"; 23 | case 1: 24 | return "BYTE"; 25 | case 2: 26 | return "SHORT"; 27 | case 3: 28 | return "INT"; 29 | case 4: 30 | return "LONG"; 31 | case 5: 32 | return "FLOAT"; 33 | case 6: 34 | return "DOUBLE"; 35 | case 7: 36 | return "BYTE_ARRAY"; 37 | case 8: 38 | return "STRING"; 39 | case 9: 40 | return "LIST"; 41 | case 10: 42 | return "COMPOUND"; 43 | case 11: 44 | return "INT_ARRAY"; 45 | case 12: 46 | return "LONG_ARRAY"; 47 | default: 48 | return "UNKOWN_TAG"; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/nbtReader/NbtTasks.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import basic.IORunnable; 7 | 8 | public class NbtTasks { 9 | 10 | public static final NbtTasks I = new NbtTasks(); 11 | 12 | private Map tasks; 13 | 14 | private NbtTasks() { 15 | 16 | } 17 | 18 | public NbtTasks put(NamedTag namedTag, IORunnable task) { 19 | this.tasks.put(namedTag, task); 20 | return this; 21 | } 22 | 23 | public NbtTasks create(NamedTag namedTag, IORunnable task) { 24 | NbtTasks result = new NbtTasks(); 25 | result.tasks = new HashMap<>(); 26 | result.put(namedTag, task); 27 | return result; 28 | } 29 | 30 | public NbtTasks create() { 31 | NbtTasks result = new NbtTasks(); 32 | result.tasks = new HashMap<>(); 33 | return result; 34 | } 35 | 36 | public IORunnable get(NamedTag namedTag) { 37 | return this.tasks.get(namedTag); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/nbtReader/PlayerInLevelReader.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | import minecraft.Position; 7 | 8 | public class PlayerInLevelReader extends PlayerPositionReader { 9 | 10 | private Position playerPosition = new Position(); 11 | private Position worldSpawn = new Position(); 12 | 13 | private final NbtTasks tasks; 14 | private static final NamedTag DATA = new NamedTag(NbtTag.COMPOUND, "Data"); 15 | 16 | private static final NamedTag PLAYER = new NamedTag(NbtTag.COMPOUND, "Player"); 17 | private static final NamedTag SPAWN_X = new NamedTag(NbtTag.INT, "SpawnX"); 18 | private static final NamedTag SPAWN_Y = new NamedTag(NbtTag.INT, "SpawnY"); 19 | private static final NamedTag SPAWN_Z = new NamedTag(NbtTag.INT, "SpawnZ"); 20 | 21 | public PlayerInLevelReader(DataInputStream stream) { 22 | super(stream); 23 | 24 | this.tasks = NbtTasks.I.create() 25 | .put(DATA, () -> this.doCompound(NbtTasks.I.create() 26 | .put(PLAYER, () -> this.playerPosition = this.readPlayerData()) 27 | .put(SPAWN_X, () -> this.worldSpawn.setX(this.readInt())) 28 | .put(SPAWN_Y, () -> this.worldSpawn.setY(this.readInt())) 29 | .put(SPAWN_Z, () -> this.worldSpawn.setZ(this.readInt())))); 30 | } 31 | 32 | public PlayerInLevelReader read() throws IOException { 33 | if (this.readTag() == NbtTag.COMPOUND) { 34 | this.readTitle(); 35 | this.doCompound(this.tasks); 36 | } 37 | return this; 38 | } 39 | 40 | public Position getPlayerPosition() { 41 | return this.playerPosition; 42 | } 43 | 44 | public Position getWorldSpawn() { 45 | return this.worldSpawn; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/nbtReader/PlayerPositionReader.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | import minecraft.Position; 7 | 8 | public abstract class PlayerPositionReader extends NbtReader { 9 | 10 | public PlayerPositionReader(DataInputStream stream) { 11 | super(stream); 12 | } 13 | 14 | private static final NamedTag POS = new NamedTag(NbtTag.LIST, "Pos"); 15 | 16 | public Position readPlayerData() throws IOException { 17 | Position position = new Position(); 18 | this.doCompound(NbtTasks.I.create() 19 | .put(POS, () -> this.readPosition(position))); 20 | return position; 21 | } 22 | 23 | private void readPosition(Position position) throws IOException { 24 | int listTag = this.readTag(); 25 | if (listTag == NbtTag.DOUBLE && this.readLength() == 3) { 26 | double posX = this.readDouble(); 27 | double posY = this.readDouble(); 28 | double posZ = this.readDouble(); 29 | position.setTo(new Position(posX, posY, posZ)); 30 | } else { 31 | this.skipListOf(listTag); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/nbtReader/PlayerReader.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | import minecraft.Position; 7 | 8 | public class PlayerReader extends PlayerPositionReader { 9 | 10 | public PlayerReader(DataInputStream stream) { 11 | super(stream); 12 | } 13 | 14 | public Position read() throws IOException { 15 | int type = this.readTag(); 16 | if (type == NbtTag.COMPOUND) { 17 | this.readTitle(); 18 | return this.readPlayerData(); 19 | } 20 | return null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/nbtReader/Section.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import basic.Tuple; 8 | import minecraft.Area; 9 | import minecraft.Block; 10 | import minecraft.Position; 11 | import periphery.Minecraft; 12 | 13 | public class Section { 14 | 15 | WorldPiece worldPiece; 16 | 17 | private int firstYPosition; 18 | 19 | private int[][][] rawBlocks = new int[Minecraft.CHUNK_SIZE_X][Minecraft.SECTION_SIZE_Y][Minecraft.CHUNK_SIZE_Z]; 20 | private Map palette = new HashMap(); 21 | 22 | public Section(WorldPiece convertee) { 23 | this.worldPiece = convertee; 24 | } 25 | 26 | public WorldPiece getConvertee() { 27 | return this.worldPiece; 28 | } 29 | 30 | public Block getBlock(Position p) { 31 | return this.palette.get(Integer.valueOf(this.rawBlocks[p.x][p.y][p.z])); 32 | } 33 | 34 | public int getFirstYPosition() { 35 | return this.firstYPosition; 36 | } 37 | 38 | public void readBlocksRaw(NbtReader source) throws IOException { 39 | int length = source.readLength(); 40 | int unitSize = this.getUnitLength(length); 41 | BitNbtReader reader = new BitNbtReader(source, unitSize); 42 | for (int y = 0; y < Minecraft.SECTION_SIZE_Y; y++) { 43 | for (int z = 0; z < Minecraft.CHUNK_SIZE_Z; z++) { 44 | for (int x = 0; x < Minecraft.CHUNK_SIZE_X; x++) { 45 | this.rawBlocks[x][y][z] = reader.readBits(); 46 | } 47 | } 48 | } 49 | } 50 | 51 | private int getUnitLength(int length) { 52 | return length / 64; 53 | } 54 | 55 | public void setHeight(int height) { 56 | this.firstYPosition = height * Minecraft.SECTION_SIZE_Y; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return this.worldPiece.toString() + " @height " + this.firstYPosition; 62 | } 63 | 64 | public Tuple getBoundAndTarget() { 65 | Position lower = this.getConvertee() 66 | .getLower(); 67 | Position higher = this.getConvertee() 68 | .getHigher(); 69 | int yMappedToStart = lower.getY(); 70 | int absolutStartY = Math.max(this.getFirstYPosition(), lower.getY()); 71 | int absoluteEndY = Math.min(this.getFirstYPosition() + (Minecraft.SECTION_SIZE_Y - 1), higher.getY()); 72 | Position start = this.getConvertee() 73 | .getLower(); 74 | start.setY(absolutStartY % Minecraft.SECTION_SIZE_Y); 75 | Position end = this.getConvertee() 76 | .getHigher(); 77 | end.setY(absoluteEndY % Minecraft.SECTION_SIZE_Y); 78 | Position target = Position.subtract(this.getConvertee() 79 | .getVmfStart(), start); 80 | target.setY(absolutStartY - start.y - yMappedToStart + 1); 81 | if (absolutStartY > absoluteEndY) { 82 | start.y = 1; 83 | end.y = 0; 84 | } 85 | return new Tuple<>(new Area(start, end), target); 86 | } 87 | 88 | public void addPalette(Integer i, Block block) { 89 | this.palette.put(i, block); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/nbtReader/WorldPiece.java: -------------------------------------------------------------------------------- 1 | package nbtReader; 2 | 3 | import minecraft.Area; 4 | import minecraft.Position; 5 | import periphery.Minecraft; 6 | 7 | public class WorldPiece { 8 | 9 | private Position vmfStart; 10 | 11 | private ChunkPosition globalChunkPosition; 12 | 13 | private ChunkPosition localChunkPosition; 14 | 15 | private ChunkPosition filePosition; 16 | 17 | private Position lower; 18 | private Position higher; 19 | 20 | public WorldPiece(Position position, Position end, Position vmfStart) { 21 | this.vmfStart = vmfStart.copy(); 22 | this.globalChunkPosition = new ChunkPosition(position); 23 | 24 | int lowerX = getLowerLocalCoordinate(position.getX()); 25 | int lowerZ = getLowerLocalCoordinate(position.getZ()); 26 | this.lower = new Position(lowerX, position.y, lowerZ); 27 | Position chunkStart = new Position(position.x - lowerX, position.y, position.z - lowerZ); 28 | 29 | this.higher = Position.subtract(end, chunkStart); 30 | this.higher.y = end.y; 31 | this.higher = Position.capBelow(this.higher, 32 | new Position(Minecraft.CHUNK_SIZE_X, Minecraft.MAX_Y, Minecraft.CHUNK_SIZE_Z)); 33 | 34 | // local chunk position 35 | int x = getLocalCunkCoordinate(this.globalChunkPosition.getX()); 36 | int z = getLocalCunkCoordinate(this.globalChunkPosition.getZ()); 37 | this.localChunkPosition = new ChunkPosition(x, z); 38 | 39 | this.filePosition = this.getFileOfChunk(this.globalChunkPosition); 40 | 41 | assert this.higher != null; 42 | assert this.lower != null; 43 | } 44 | 45 | private static final int getLowerLocalCoordinate(int value) { 46 | if (value >= 0) { 47 | return value % Minecraft.CHUNK_SIZE_X; 48 | } else { 49 | // 'negative' chunk positions range from -16 to -1 instead of 0 to 15. 50 | return ((value + 1) % Minecraft.CHUNK_SIZE_X) + Minecraft.CHUNK_SIZE_X - 1; 51 | } 52 | } 53 | 54 | private ChunkPosition getFileOfChunk(ChunkPosition global) { 55 | int globalX = global.getX(); 56 | int fileX, fileZ; 57 | if (globalX >= 0) { 58 | fileX = globalX / Minecraft.MAX_CHUNK_IN_FILE_X; 59 | } else { 60 | fileX = ((globalX + 1) / Minecraft.MAX_CHUNK_IN_FILE_X) - 1; 61 | } 62 | int globalZ = global.getZ(); 63 | if (globalZ >= 0) { 64 | fileZ = globalZ / Minecraft.MAX_CHUNK_IN_FILE_Z; 65 | } else { 66 | fileZ = ((globalZ + 1) / Minecraft.MAX_CHUNK_IN_FILE_Z) - 1; 67 | } 68 | return new ChunkPosition(fileX, fileZ); 69 | } 70 | 71 | public ChunkPosition getFilePosition() { 72 | return this.filePosition.copy(); 73 | } 74 | 75 | public Position getLower() { 76 | return this.lower.copy(); 77 | } 78 | 79 | public Position getHigher() { 80 | return this.higher.copy(); 81 | } 82 | 83 | public ChunkPosition getGlobalChunk() { 84 | return this.globalChunkPosition; 85 | } 86 | 87 | public ChunkPosition getLocalChunk() { 88 | return this.localChunkPosition; 89 | } 90 | 91 | private static final int getLocalCunkCoordinate(int value) { 92 | if (value >= 0) { 93 | return value % Minecraft.MAX_CHUNK_IN_FILE_X; 94 | } else { 95 | // 'negative' chunk positions range from -16 to -1 instead of 0 to 15. 96 | return ((value + 1) % Minecraft.MAX_CHUNK_IN_FILE_X) + Minecraft.MAX_CHUNK_IN_FILE_X - 1; 97 | } 98 | } 99 | 100 | public Area createBounds() { 101 | return new Area(this.getLower(), this.getHigher()); 102 | } 103 | 104 | public Position getAreaXZ() { 105 | Position result = Position.areaSpan(this.lower, this.higher); 106 | result.y = 0; 107 | return result; 108 | } 109 | 110 | @Override 111 | public String toString() { 112 | return this.filePosition.toFileName() + " local " + this.localChunkPosition.toString() + " bounds " 113 | + this.lower.toBracketString() + " to " + this.higher.toBracketString() + " -> " 114 | + this.vmfStart.toBracketString(); 115 | } 116 | 117 | public Position getVmfStart() { 118 | return this.vmfStart.copy(); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/periphery/ConfigIO.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | 7 | import com.google.gson.Gson; 8 | import com.google.gson.GsonBuilder; 9 | import com.google.gson.InstanceCreator; 10 | 11 | import basic.Loggger; 12 | import vmfWriter.Color; 13 | 14 | public class ConfigIO { 15 | 16 | public static void write(Config config, Path target) throws IOException { 17 | Gson gson = new GsonBuilder().setPrettyPrinting() 18 | .create(); 19 | String toSafe = gson.toJson(config); 20 | 21 | Files.write(target, toSafe.getBytes()); 22 | } 23 | 24 | public static Config obtain(Config config, Path path) { 25 | try { 26 | if (path.toFile() 27 | .exists()) { 28 | config = ConfigIO.read(config, path); 29 | } else { 30 | config = Config.getDetaulftConfig(); 31 | } 32 | } catch (IOException e1) { 33 | Loggger.log("No fonig at " + path + " found."); 34 | } 35 | return config; 36 | } 37 | 38 | public static Config read(Config config, Path source) throws IOException { 39 | Gson gson = getGson(); 40 | String fileAsString = new String(Files.readAllBytes(source)); 41 | config = gson.fromJson(fileAsString, Config.class); 42 | 43 | return config; 44 | } 45 | 46 | private static Gson getGson() { 47 | GsonBuilder gsonBuilder = new GsonBuilder(); 48 | 49 | gsonBuilder.registerTypeAdapter(periphery.Place.class, (InstanceCreator) arg0 -> new periphery.Place()); 50 | 51 | gsonBuilder.registerTypeAdapter(vmfWriter.Color.class, (InstanceCreator) arg0 -> new vmfWriter.Color()); 52 | 53 | gsonBuilder.registerTypeAdapter(periphery.ConvertOption.class, 54 | (InstanceCreator) arg0 -> new periphery.ConvertOption()); 55 | 56 | gsonBuilder.registerTypeAdapter(SourceGame.class, (InstanceCreator) arg0 -> new SourceGame()); 57 | return gsonBuilder.create(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/periphery/ConvertOption.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.util.Stack; 4 | 5 | import vmfWriter.Color; 6 | 7 | public class ConvertOption { 8 | 9 | private String name; 10 | private int scale; 11 | private String skyTexture; 12 | private Color sunLight; 13 | private Color sunAmbient; 14 | private Color sunShadow; 15 | private Stack addables; 16 | 17 | public static ConvertOption create() { 18 | return new ConvertOption(); 19 | } 20 | 21 | public ConvertOption() { 22 | this.addables = new Stack(); 23 | } 24 | 25 | public ConvertOption(String aName) { 26 | this.addables = new Stack(); 27 | this.name = aName; 28 | this.scale = 40; 29 | } 30 | 31 | public ConvertOption setName(String name) { 32 | this.name = name; 33 | return this; 34 | } 35 | 36 | public ConvertOption setScale(int scale) { 37 | this.scale = scale; 38 | return this; 39 | } 40 | 41 | public ConvertOption setSkyTexture(String skyTexture) { 42 | this.skyTexture = skyTexture; 43 | return this; 44 | } 45 | 46 | public ConvertOption setSunAmbient(Color sunAmbient) { 47 | this.sunAmbient = sunAmbient; 48 | return this; 49 | } 50 | 51 | public ConvertOption setSunLight(Color sunLight) { 52 | this.sunLight = sunLight; 53 | return this; 54 | } 55 | 56 | public ConvertOption setSunShadow(Color sunShadow) { 57 | this.sunShadow = sunShadow; 58 | return this; 59 | } 60 | 61 | public String getName() { 62 | return this.name; 63 | } 64 | 65 | public int getScale() { 66 | return this.scale; 67 | } 68 | 69 | public String getSkyTexture() { 70 | return this.skyTexture; 71 | } 72 | 73 | public Color getSunAmbient() { 74 | return this.sunAmbient; 75 | } 76 | 77 | public Color getSunLight() { 78 | return this.sunLight; 79 | } 80 | 81 | public Color getSunShadow() { 82 | return this.sunShadow; 83 | } 84 | 85 | public ConvertOption addAddable(String addable) { 86 | this.addables.push(addable); 87 | return this; 88 | } 89 | 90 | public String[] getAddablesAsStrings() { 91 | Stack addablesNew = new Stack(); 92 | int l = this.addables.size(); 93 | String[] result = new String[l]; 94 | for (int i = 0; i < l; i++) { 95 | result[i] = this.addables.pop(); 96 | addablesNew.push(result[i]); 97 | } 98 | this.addables = addablesNew; 99 | return result; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/periphery/DirectoryFilter.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | 6 | public class DirectoryFilter implements FilenameFilter { 7 | 8 | @Override 9 | public boolean accept(File dir, String name) { 10 | return new File(dir, name).isDirectory(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/periphery/Minecraft.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Vector; 11 | import java.util.zip.GZIPInputStream; 12 | 13 | import basic.Loggger; 14 | import gui.panel.LabeledCoordinates; 15 | import main.Main; 16 | import minecraft.Position; 17 | import minecraft.World; 18 | import nbtReader.PlayerInLevelReader; 19 | import nbtReader.WorldPiece; 20 | 21 | public class Minecraft { 22 | 23 | private static final String SAVES_FOLDER = "saves"; 24 | private static final String REGION_FOLDER = "region"; 25 | 26 | public static final int MAX_CHUNK_IN_FILE_X = 32; // number of last chunk 27 | public static final int MAX_CHUNK_IN_FILE_Z = 32; 28 | 29 | public static final int CHUNK_SIZE_X = 16; 30 | public static final int CHUNK_SIZE_Z = 16; 31 | 32 | public static final int SECTION_SIZE_Y = 16; 33 | public static final int MAX_Y = 256; 34 | 35 | public static final String ANVIL_ENDING = "mca"; 36 | public static final String DAT_ENDING = ".dat"; 37 | public static final String LEVEL_FILE_NAME = "level.dat"; 38 | public static final String PLAYERS_FOLDER = "players"; 39 | 40 | public static final int MAXIMUM_HEIGHT = 256; 41 | 42 | public static Path getMinecraftPath() { 43 | return Periphery.CONFIG.getMinceraftSavePath(); 44 | } 45 | 46 | public static Path getCorrectMinecraftPath() { 47 | Path minecraftPath = Periphery.CONFIG.getMinceraftSavePath(); 48 | if (minecraftPath == null) { 49 | return getNewMinecraftPath(); 50 | } 51 | if (!(isMinecraftInputDirectory(minecraftPath))) { 52 | return getNewMinecraftPath(); 53 | } 54 | Loggger.log("valid minecraft path: " + Periphery.CONFIG.getMinecraftPathString()); 55 | return minecraftPath; 56 | } 57 | 58 | public static boolean isMinecraftInputDirectory(Path path) { 59 | return getPossibleWorlds(path).size() > 0; 60 | } 61 | 62 | private static Path getNewMinecraftPath() { 63 | Path minecraftPath; 64 | if (Main.isUnix()) { 65 | minecraftPath = Paths.get(System.getProperty("user.home"), ".minecraft"); 66 | } else { 67 | minecraftPath = Paths.get(System.getProperty("user.home"), "AppData", "Roaming", ".minecraft", 68 | SAVES_FOLDER); 69 | } 70 | Periphery.CONFIG.setMinecraftPath(minecraftPath); 71 | Loggger.log("guessing minecraft path: " + Periphery.CONFIG.getMinecraftPathString()); 72 | return minecraftPath; 73 | } 74 | 75 | public Vector getPlayerCoordinates(World world) { 76 | File file = new File(Periphery.CONFIG.getWorldPath(world), "level.dat"); 77 | Vector vector = new Vector<>(); 78 | try { 79 | DataInputStream stream = new DataInputStream(new GZIPInputStream(new FileInputStream(file))); 80 | PlayerInLevelReader reader = new PlayerInLevelReader(stream); 81 | Position position = reader.read() 82 | .getPlayerPosition(); 83 | 84 | vector.add(new LabeledCoordinates("Player position", position, position)); 85 | vector.add(new LabeledCoordinates("World origin", new Position(-20, 45, -20), new Position(20, 150, 20))); 86 | return vector; 87 | } catch (IOException e) { 88 | // TODO Auto-generated catch block 89 | e.printStackTrace(); 90 | } 91 | return vector; 92 | } 93 | 94 | public static File getFileOfChunk(File fileFolder, WorldPiece source) { 95 | int fileX = source.getFilePosition() 96 | .getX(); 97 | int fileZ = source.getFilePosition() 98 | .getZ(); 99 | return new File(fileFolder, "r." + fileX + "." + fileZ + "." + ANVIL_ENDING); 100 | } 101 | 102 | public static Vector getPossibleWorlds() { 103 | return getPossibleWorlds(Periphery.CONFIG.getMinceraftSavePath()); 104 | } 105 | 106 | public static Vector getPossibleWorlds(Path savesPath) { 107 | Vector result = new Vector<>(); 108 | try { 109 | Files.list(savesPath) 110 | .filter(path -> Files.isDirectory(path.resolve(REGION_FOLDER))) 111 | .forEach(path -> result.add(new World(path.getParent(), path.getFileName() 112 | .toString()))); 113 | } catch (IOException e) { 114 | } 115 | return result; 116 | } 117 | 118 | // public static Vector getPossibleWorlds(Path savesPath) { 119 | // String[] list = file.list(); 120 | // Vector vector = new Vector<>(); 121 | // if (list != null) { 122 | // for (String world : list) { 123 | // if (!(Files.isDirectory(Paths.get(Periphery.CONFIG.getMinceraftSavePath() 124 | // .toString(), world, REGION_FOLDER)))) { 125 | // continue; 126 | // } 127 | // try { 128 | // vector.addElement(new World(world)); 129 | // } catch (IOException e) { 130 | // Loggger.log("cannot create world"); 131 | // } 132 | // 133 | // } 134 | // } 135 | // return vector; 136 | // } 137 | 138 | public static File getWorldFolder(Place place) { 139 | return new File(Periphery.CONFIG.getMinecraftPath() + File.separator + place.getWorld()); 140 | // return new File(Periphery.CONFIG.getMinecraftPath(), "saves" + File.separator + place.getWorld()); 141 | //// return String.join(File.separator, Periphery.CONFIG.getMinecraftPathString(), place.getWorld()); 142 | } 143 | 144 | public static Path getRegionFolder(Place place) { 145 | return Paths.get(getWorldFolder(place).toString(), REGION_FOLDER); 146 | } 147 | 148 | public static String toMaterial(String name) { 149 | return "minecraft:" + name; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/periphery/Periphery.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | 8 | import com.google.gson.Gson; 9 | import com.google.gson.GsonBuilder; 10 | 11 | import basic.Loggger; 12 | 13 | public class Periphery { 14 | 15 | private static final Path CONFIG_PATH = new File("config.json").toPath(); 16 | private static final Path PLACES_PATH = new File("places.json").toPath(); 17 | 18 | private static final String SC_TEXTURE_FOLDER = "textures"; 19 | 20 | public static Config CONFIG = new Config(); 21 | public static Places PLACES = new Places(); 22 | 23 | public static void init() { 24 | CONFIG = new Config(); 25 | PLACES = new Places(); 26 | obtainConfig(); 27 | obtainPlaces(); 28 | } 29 | 30 | public static void obtainConfig() { 31 | CONFIG = ConfigIO.obtain(CONFIG, CONFIG_PATH); 32 | } 33 | 34 | public static void writeConfig() { 35 | try { 36 | ConfigIO.write(CONFIG, CONFIG_PATH); 37 | } catch (IOException e) { 38 | // TODO Auto-generated catch block 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | public static void writePlaces() { 44 | writePlaces(PLACES); 45 | } 46 | 47 | public static void obtainPlaces() { 48 | PLACES = new Places(); 49 | try { 50 | Gson gson = new GsonBuilder().create(); 51 | if (PLACES_PATH.toFile() 52 | .exists()) { 53 | String fileAsString = new String(Files.readAllBytes(PLACES_PATH)); 54 | PLACES = gson.fromJson(fileAsString, Places.class); 55 | } 56 | } catch (IOException e) { 57 | Loggger.log(e.getMessage()); 58 | } 59 | } 60 | 61 | private static void writePlaces(Places places) { 62 | Gson gson = new GsonBuilder().setPrettyPrinting() 63 | .create(); 64 | String toSafe = gson.toJson(places); 65 | try { 66 | Files.write(PLACES_PATH, toSafe.getBytes()); 67 | } catch (IOException e) { 68 | // TODO Auto-generated catch block 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | public static void write() { 74 | Periphery.writeConfig(); 75 | Periphery.writePlaces(); 76 | } 77 | 78 | public static String[] detectTexturePacks() { 79 | File file = new File(SC_TEXTURE_FOLDER + File.separator); 80 | File[] files = file.listFiles(new DirectoryFilter()); 81 | if (files == null) { 82 | // TODO 83 | Loggger.log("no textures to install found"); 84 | } else { 85 | int length = files.length; 86 | String[] detectedTexturePacks = new String[length]; 87 | int i = 0; 88 | for (File f : files) { 89 | detectedTexturePacks[i] = f.getName(); 90 | i++; 91 | } 92 | return detectedTexturePacks; 93 | } 94 | return null; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/periphery/Place.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.util.Objects; 4 | 5 | import minecraft.Area; 6 | import minecraft.Position; 7 | 8 | public class Place { 9 | 10 | private String displayName; 11 | private String world; 12 | 13 | private Position start; 14 | private Position end; 15 | 16 | public Place(String name) { 17 | this.displayName = name; 18 | this.start = new Position(); 19 | this.end = new Position(); 20 | } 21 | 22 | public static Place create() { 23 | return new Place(); 24 | } 25 | 26 | public Place() { 27 | this.start = new Position(); 28 | this.end = new Position(); 29 | } 30 | 31 | public String getWorld() { 32 | return this.world; 33 | } 34 | 35 | public static String getWorld(Place place) { 36 | if (place == null) { 37 | return null; 38 | } 39 | return place.getWorld(); 40 | } 41 | 42 | public Place setWorld(String world) { 43 | this.world = world; 44 | return this; 45 | } 46 | 47 | public String getDisplayName() { 48 | return this.displayName; 49 | } 50 | 51 | public Position getStart() { 52 | return this.start.copy(); 53 | } 54 | 55 | public Position getEnd() { 56 | return this.end.copy(); 57 | } 58 | 59 | public Place setStart(Position start) { 60 | this.start.setTo(start); 61 | return this; 62 | } 63 | 64 | public Place setEnd(Position end) { 65 | this.end.setTo(end); 66 | return this; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return this.displayName; 72 | } 73 | 74 | public Area createBound() { 75 | return new Area(this.getStart(), this.getEnd()); 76 | } 77 | 78 | public Place setTo(Place other) { 79 | if (other == null) { 80 | return this; 81 | } 82 | if (!other.displayName.isEmpty()) { 83 | this.displayName = other.displayName; 84 | } 85 | this.start.setTo(other.start); 86 | this.end.setTo(other.end); 87 | return this; 88 | } 89 | 90 | public boolean correctCoordinates() { 91 | boolean changed = Position.bringInOrder(this.start, this.end); 92 | if (this.start.x == this.end.x) { 93 | this.end.x = this.end.x + 1; 94 | changed = true; 95 | } 96 | if (this.start.y == this.end.y) { 97 | this.end.y = this.end.y + 1; 98 | changed = true; 99 | } 100 | if (this.start.z == this.end.z) { 101 | this.end.z = this.end.z + 1; 102 | changed = true; 103 | } 104 | return changed; 105 | } 106 | 107 | @Override 108 | public int hashCode() { 109 | return Objects.hash(this.displayName, this.end, this.start, this.world); 110 | } 111 | 112 | @Override 113 | public boolean equals(Object obj) { 114 | if (this == obj) { 115 | return true; 116 | } 117 | if (!(obj instanceof Place)) { 118 | return false; 119 | } 120 | Place other = (Place) obj; 121 | return Objects.equals(this.displayName, other.displayName) && Objects.equals(this.end, other.end) 122 | && Objects.equals(this.start, other.start) && Objects.equals(this.world, other.world); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/periphery/Places.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Vector; 6 | 7 | public class Places { 8 | 9 | private List places; 10 | 11 | public Places() { 12 | this.places = new ArrayList<>(); 13 | } 14 | 15 | public Places(List places) { 16 | this.places = places; 17 | } 18 | 19 | public String[] getPlaceNamesWithDefault(String defaultName) { 20 | Place[] placesArray = new Place[this.places.size()]; 21 | placesArray = this.places.toArray(placesArray); 22 | String[] result = new String[this.places.size() + 1]; 23 | result[0] = defaultName; 24 | for (int i = 1; i < this.places.size() + 1; i++) { 25 | result[i] = placesArray[i - 1].getDisplayName(); 26 | } 27 | return result; 28 | } 29 | 30 | public String[] getPlaceNames() { 31 | Place[] placesArray = new Place[this.places.size()]; 32 | placesArray = this.places.toArray(placesArray); 33 | String[] result = new String[this.places.size()]; 34 | for (int i = 0; i < this.places.size(); i++) { 35 | result[i] = placesArray[i].getDisplayName(); 36 | } 37 | return result; 38 | } 39 | 40 | public Place getPlace(String searchedName) { 41 | Object[] placesArray = this.places.toArray(); 42 | for (Object object : placesArray) { 43 | Place posPlace = (Place) object; 44 | if (posPlace.getDisplayName() 45 | .equals(searchedName)) { 46 | return posPlace; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | public void addPlace(Place place) { 53 | this.places.add(place); 54 | } 55 | 56 | public void deletePlace(Place place) { 57 | this.places.remove(place); 58 | } 59 | 60 | public boolean placesEmpty() { 61 | return this.places.isEmpty(); 62 | } 63 | 64 | public Vector getPlaces() { 65 | return new Vector<>(this.places); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/periphery/SourceGame.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import basic.Loggger; 8 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 9 | 10 | public class SourceGame { 11 | 12 | private String nameLong; 13 | private String nameShort; 14 | private String gamePath; 15 | private String defaultConvertOption; 16 | private RotateablePointEntity spawn; // =new NamedRotateablePointEntity().setName("info_player_start"); 17 | // private static PointEntity SPAWN = new InfoPlayerStart(); // InfoPlayerTeamSpawn.setTeamNumber(0); 18 | 19 | private static final String MATERIALS_FOLDER = "materials"; 20 | 21 | public static List createDefaults() { 22 | ArrayList result = new ArrayList<>(); 23 | result.add(create().setLongName("Team Fortress 2") 24 | .setShortName("tf") 25 | .setDefaultConvertOption("defaultTF2") 26 | .setSpawnEntity(new RotateablePointEntity().setName("info_player_teamspawn"))); 27 | result.add(create().setLongName("Counter-Strike Source") 28 | .setShortName("cstrike") 29 | .setDefaultConvertOption("defaultCss") 30 | .setSpawnEntity(new RotateablePointEntity().setName("info_player_teamspawn"))); 31 | result.add(create().setLongName("Garrysmod") 32 | .setShortName("garrysmod") 33 | .setDefaultConvertOption("defaultGmod") 34 | .setSpawnEntity(new RotateablePointEntity().setName("info_player_start"))); 35 | return result; 36 | } 37 | 38 | public static SourceGame create() { 39 | return new SourceGame(); 40 | } 41 | 42 | public SourceGame() { 43 | 44 | } 45 | 46 | public SourceGame setSpawnEntity(RotateablePointEntity spawn) { 47 | this.spawn = spawn; 48 | return this; 49 | } 50 | 51 | public RotateablePointEntity getSpawnEntity() { 52 | return this.spawn; 53 | } 54 | 55 | public void setGameTargetSavePath(File filePath) { 56 | this.gamePath = filePath.getParent(); 57 | } 58 | 59 | public String getGamePath() { 60 | if (this.gamePath != null) { 61 | File f = new File(this.gamePath); 62 | if (f.exists()) { 63 | return this.gamePath; 64 | } 65 | } 66 | String path = Periphery.CONFIG.getSteamPath() + File.separator + Steam.STEAM_GAME_PATH() + File.separator 67 | + Steam.STEAM_SDK_PATH + File.separator + this.getShortName() + File.separator 68 | + Steam.STEAM_MAP_SRC_PATH; 69 | Loggger.log(path); 70 | return path; 71 | } 72 | 73 | public String getGameHammerPath(Config config) { 74 | String path = config.getSteamPath() + File.separator + Steam.STEAM_GAME_PATH() + File.separator + this.nameLong 75 | + File.separator + "bin" + File.separator + "hammer.exe"; 76 | Loggger.log(path); 77 | return path; 78 | } 79 | 80 | public SourceGame setLongName(String nameLong) { 81 | this.nameLong = nameLong; 82 | return this; 83 | } 84 | 85 | public String getLongName() { 86 | return this.nameLong; 87 | } 88 | 89 | public SourceGame setShortName(String nameShort) { 90 | this.nameShort = nameShort; 91 | return this; 92 | } 93 | 94 | public String getShortName() { 95 | return this.nameShort; 96 | } 97 | 98 | public SourceGame setDefaultConvertOption(String name) { 99 | this.defaultConvertOption = name; 100 | return this; 101 | } 102 | 103 | public String getDefaultConvertOption() { 104 | return this.defaultConvertOption; 105 | } 106 | 107 | public File getMatriealPath(TexturePack texturePack) { 108 | if (Periphery.CONFIG.getSteamPath() == null) { 109 | return null; 110 | } 111 | return new File(String.join(File.separator, Periphery.CONFIG.getSteamPath() 112 | .toString(), Steam.STEAM_GAME_PATH(), this.getLongName(), this.getShortName(), 113 | SourceGame.MATERIALS_FOLDER, texturePack.getName())); 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return this.getLongName(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/periphery/Steam.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.Paths; 7 | 8 | import basic.Loggger; 9 | import main.Main; 10 | import main.TextureFolderMover; 11 | 12 | public class Steam { 13 | 14 | private static final String STEAM_NAME = "Steam"; 15 | private static final String STEAM_NAME_UNIX = ".steam" + File.separator + "steam"; 16 | 17 | public static final String STEAM_GAME_PATH() { 18 | if (Main.isUnix()) { 19 | return "steamapps" + File.separator + "common"; 20 | } 21 | return "SteamApps" + File.separator + "common"; 22 | }; 23 | 24 | public static final String STEAM_SDK_PATH = "sourcesdk_content"; 25 | public static final String STEAM_MAP_SRC_PATH = "mapsrc"; 26 | 27 | private static final String[] POTENTIAL_STEAM_PATH_GRAND_PARENTS = { "C:", "D:", "E:", File.separator }; 28 | private static final String[] POTENTIAL_STEAM_PATH_PARENTS = { "Program Files", "Program Files (x86)", "Programs", 29 | "Programme" }; 30 | 31 | public static Path getSteamPath() { 32 | Path steamPath = Periphery.CONFIG.getSteamPath(); 33 | if (!isSteamPath(steamPath)) { 34 | Path potentialPath = guessSteamPath(); 35 | if (potentialPath != null) { 36 | Loggger.log("guessed steam path: " + potentialPath); 37 | steamPath = potentialPath; 38 | } 39 | Periphery.CONFIG.setSteamPath(steamPath); 40 | } 41 | return steamPath; 42 | } 43 | 44 | private static Path guessSteamPath() { 45 | if (Main.isUnix()) { 46 | Path potentialPath = Paths.get(System.getProperty("user.home"), STEAM_NAME_UNIX); 47 | if (isSteamPath(potentialPath)) { 48 | return potentialPath; 49 | } 50 | } 51 | for (String first : POTENTIAL_STEAM_PATH_GRAND_PARENTS) { 52 | for (String second : POTENTIAL_STEAM_PATH_PARENTS) { 53 | Path potentialPath = Paths.get(first, second, STEAM_NAME); 54 | if (isSteamPath(potentialPath)) { 55 | return potentialPath; 56 | } 57 | } 58 | } 59 | return null; 60 | } 61 | 62 | public static boolean isSteamPath(Path path) { 63 | if (path == null) { 64 | return false; 65 | } 66 | if (!Files.isDirectory(path) || !path.getFileName() 67 | .toString() 68 | .toLowerCase() 69 | .equals(STEAM_NAME.toLowerCase())) { 70 | return false; 71 | } 72 | File gamePath = new File(path.toString() + File.separator + STEAM_GAME_PATH()); 73 | if (!gamePath.exists() || !gamePath.isDirectory()) { 74 | return false; 75 | } 76 | return true; 77 | } 78 | 79 | public static boolean isGameInstalled(SourceGame game) { 80 | File hammer = new File(getHammerPath(game)); 81 | return hammer.exists(); 82 | } 83 | 84 | public static String getGamePathString(SourceGame game) { 85 | if (game == null) { 86 | game = Periphery.CONFIG.getGames() 87 | .get(0); 88 | } 89 | return game.getGamePath(); 90 | } 91 | 92 | public static String getHammerPath(SourceGame game) { 93 | return game.getGameHammerPath(Periphery.CONFIG); 94 | } 95 | 96 | public static final String TEXTURES_NOT_OK = ""; 97 | public static final String TEXTURES_OK = "Textures are in the right folder."; 98 | 99 | public static boolean areTexturesUpToDate(SourceGame game, TexturePack pack) { 100 | File materiaPath = game.getMatriealPath(pack); 101 | if (materiaPath == null) { 102 | return false; 103 | } 104 | Loggger.log("checking textures in " + materiaPath.toString()); 105 | if (materiaPath == null || materiaPath.getParentFile() 106 | .exists() == false) { 107 | Loggger.warn("Cannot find material path."); 108 | return false; 109 | } 110 | Path optionsGamePath = new File(materiaPath.toString() + File.separator + TexturePack.TEXTURE_OPTIONS_FILE) 111 | .toPath(); 112 | TextureOptions toGame = TexturePack.readTextureOptions(new TextureOptions(), optionsGamePath); 113 | TextureOptions toSourcecraft = pack.getTextureOptions(); 114 | return TextureOptions.isUpToDate(toGame, toSourcecraft); 115 | } 116 | 117 | public static void updateTextures(TexturePack pack, SourceGame game) { 118 | File srcFolder = pack.getFolder(); 119 | File materiaPath = game.getMatriealPath(pack); 120 | TextureFolderMover.copyFolder(srcFolder, materiaPath); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/periphery/TextureOptions.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | public class TextureOptions { 4 | 5 | private static final int DEFAULT_SCALE = 128; 6 | 7 | private int scale = DEFAULT_SCALE; 8 | private int textureVersion; 9 | 10 | public TextureOptions() { 11 | this.textureVersion = -1; 12 | } 13 | 14 | public int getTextureVersion() { 15 | try { 16 | return Integer.valueOf(this.textureVersion); 17 | } catch (java.lang.NumberFormatException e) { 18 | return 0; 19 | } 20 | } 21 | 22 | public int getScale() { 23 | return this.scale; 24 | } 25 | 26 | public static boolean isUpToDate(TextureOptions one, TextureOptions two) { 27 | if (one == null) { 28 | return false; 29 | } 30 | if (two == null) { 31 | return true; 32 | } 33 | return one.getTextureVersion() >= two.getTextureVersion(); 34 | } 35 | 36 | public void setScale(int scale) { 37 | this.scale = scale; 38 | } 39 | 40 | public void setTextureVersion(int textureVersion) { 41 | this.textureVersion = textureVersion; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/periphery/TexturePack.java: -------------------------------------------------------------------------------- 1 | package periphery; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | 8 | import com.google.gson.Gson; 9 | import com.google.gson.GsonBuilder; 10 | 11 | import basic.Loggger; 12 | 13 | public class TexturePack { 14 | 15 | private static final String TEXTURES_FOLDER = "textures"; 16 | public static final String TEXTURE_OPTIONS_FILE = "options.json"; 17 | private String name; 18 | private TextureOptions textureOptions; 19 | 20 | public TexturePack(String name) { 21 | this.name = name; 22 | this.textureOptions = new TextureOptions(); 23 | } 24 | 25 | public static TextureOptions readTextureOptions(Path source) { 26 | try { 27 | Gson gson = new GsonBuilder().create(); 28 | String fileAsString = new String(Files.readAllBytes(source)); 29 | return gson.fromJson(fileAsString, TextureOptions.class); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | return null; 34 | } 35 | 36 | public static TexturePack getTexturePack(String texturePackName) { 37 | TexturePack result = new TexturePack(texturePackName); 38 | Path textureOptionsPath = new File( 39 | String.join(File.separator, TEXTURES_FOLDER, texturePackName, TEXTURE_OPTIONS_FILE)).toPath(); 40 | result.textureOptions = readTextureOptions(result.textureOptions, textureOptionsPath); 41 | return result; 42 | } 43 | 44 | public static TextureOptions readTextureOptions(TextureOptions textureOptions, Path source) { 45 | Gson gson = new GsonBuilder().create(); 46 | String fileAsString; 47 | try { 48 | fileAsString = new String(Files.readAllBytes(source)); 49 | return gson.fromJson(fileAsString, TextureOptions.class); 50 | } catch (IOException e) { 51 | Loggger.log("unable to read textureOptions " + e.getMessage()); 52 | return textureOptions; 53 | } 54 | } 55 | 56 | public int getTextureSize() { 57 | if (this.textureOptions == null) { 58 | return -1; 59 | } 60 | return this.textureOptions.getScale(); 61 | } 62 | 63 | public String getName() { 64 | return this.name; 65 | } 66 | 67 | public File getFolder() { 68 | return new File(TEXTURES_FOLDER + File.separator + this.getName()); 69 | } 70 | 71 | public TextureOptions getTextureOptions() { 72 | return this.textureOptions; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/vmfWriter/Angles.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import minecraft.Position; 4 | 5 | public class Angles extends Position { 6 | 7 | public Angles() { 8 | this(0, 0, 0); 9 | } 10 | 11 | public Angles(int x, int y, int z) { 12 | this.x = x; 13 | this.y = y; 14 | this.z = z; 15 | } 16 | 17 | @Override 18 | public Angles copy() { 19 | return new Angles(this.x, this.y, this.z); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/vmfWriter/Color.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | public class Color { 4 | 5 | private static final int DEFAULT_ALPHA = 0; 6 | public int red; 7 | public int green; 8 | public int blue; 9 | public int alpha; 10 | 11 | public static final Color FULL = new Color(255, 255, 255); 12 | 13 | public Color() { 14 | 15 | } 16 | 17 | public Color(java.awt.Color color) { 18 | this(color.getRed(), color.getGreen(), color.getBlue()); 19 | } 20 | 21 | public Color(Color original) { 22 | this.red = original.red; 23 | this.green = original.green; 24 | this.blue = original.blue; 25 | this.alpha = original.alpha; 26 | } 27 | 28 | public Color(int red, int green, int blue) { 29 | this(red, green, blue, Color.DEFAULT_ALPHA); 30 | } 31 | 32 | public Color(int red, int green, int blue, int brightness) { 33 | this.red = red; 34 | this.green = green; 35 | this.blue = blue; 36 | this.alpha = brightness; 37 | } 38 | 39 | public Color copy() { 40 | return new Color(this.red, this.green, this.blue, this.alpha); 41 | } 42 | 43 | public java.awt.Color getJavaAwtColorNegative() { 44 | return this.getNegative() 45 | .getJavaAwtColor(); 46 | } 47 | 48 | public Color getNegative() { 49 | return new Color(this.negate(this.red), this.negate(this.green), this.negate(this.blue), this.alpha); 50 | } 51 | 52 | private int negate(int value) { 53 | return 255 - value; 54 | } 55 | 56 | public java.awt.Color getJavaAwtColor() { 57 | return new java.awt.Color(this.red, this.green, this.blue); 58 | } 59 | 60 | public void setAlpha(int alpha) { 61 | this.alpha = alpha; 62 | } 63 | 64 | public int getAlpha() { 65 | return this.alpha; 66 | } 67 | 68 | public int getBlue() { 69 | return this.blue; 70 | } 71 | 72 | public int getGreen() { 73 | return this.green; 74 | } 75 | 76 | public int getRed() { 77 | return this.red; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/vmfWriter/Counter.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | /** 4 | * Contains 2 counter. 5 | * 6 | */ 7 | public class Counter { 8 | 9 | private int brushId; 10 | private int sideId; 11 | 12 | public Counter() { 13 | this.brushId = 1; // first is 2 14 | this.sideId = 0; // fist is 1 15 | } 16 | 17 | public int getNewBrushId() { 18 | this.brushId++; 19 | return this.brushId; 20 | } 21 | 22 | public int getNewSideId() { 23 | this.sideId++; 24 | return this.sideId; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/vmfWriter/EightPoint.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | 7 | public abstract class EightPoint extends Solid { 8 | 9 | private static final int LIGHTMAPSCALE = 16; 10 | 11 | public Position a; 12 | public Position aTop; 13 | public Position dTop; 14 | public Position d; 15 | public Position e; 16 | public Position eTop; 17 | public Position hTop; 18 | public Position h; 19 | 20 | protected double textureScaleX = 1; 21 | protected double textureScaleY = 1; 22 | protected double textureScaleZ = 1; 23 | 24 | public final void scale(int scale) { 25 | this.a.scale(scale); 26 | this.aTop.scale(scale); 27 | this.dTop.scale(scale); 28 | this.d.scale(scale); 29 | this.e.scale(scale); 30 | this.eTop.scale(scale); 31 | this.hTop.scale(scale); 32 | this.h.scale(scale); 33 | } 34 | 35 | public final Position[] getPointArray() { 36 | Position[] allPoints = new Position[8]; 37 | allPoints[0] = this.a; 38 | allPoints[1] = this.aTop; 39 | allPoints[2] = this.dTop; 40 | allPoints[3] = this.d; 41 | allPoints[4] = this.e; 42 | allPoints[5] = this.eTop; 43 | allPoints[6] = this.hTop; 44 | allPoints[7] = this.h; 45 | return allPoints; 46 | } 47 | 48 | public final void move(int xDistance, int yDistance, int zDistance) { 49 | this.a.move(xDistance, yDistance, zDistance); 50 | this.aTop.move(xDistance, yDistance, zDistance); 51 | this.dTop.move(xDistance, yDistance, zDistance); 52 | this.d.move(xDistance, yDistance, zDistance); 53 | this.e.move(xDistance, yDistance, zDistance); 54 | this.eTop.move(xDistance, yDistance, zDistance); 55 | this.hTop.move(xDistance, yDistance, zDistance); 56 | this.h.move(xDistance, yDistance, zDistance); 57 | } 58 | 59 | private static final String SIDE_TAG = "side"; 60 | private static final String PLANE_TAG = "plane"; 61 | private static final String MATERIAL_TAG = "material"; 62 | private static final String UAXIS_TAG = "uaxis"; 63 | private static final String VAXIS_TAG = "vaxis"; 64 | private static final String ROTATION_TAG = "rotation"; 65 | private static final String LIGHTMAPSCALE_TAG = "lightmapscale"; 66 | private static final String SMOOTHING_GROUPS_TAG = "smoothing_groups"; 67 | 68 | protected static final Position TOP_U_AXIS = new Position(1, 0, 0); 69 | protected static final Position TOP_V_AXIS = new Position(0, -1, 0); 70 | protected static final Position BOTTOM_U_AXIS = new Position(-1, 0, 0); 71 | protected static final Position BOTTOM_V_AXIS = new Position(0, -1, 0); 72 | 73 | protected static final Position LEFT_U_AXIS = new Position(0, -1, 0); 74 | protected static final Position LEFT_V_AXIS = new Position(0, 0, -1); 75 | protected static final Position RIGHT_U_AXIS = new Position(0, 1, 0); 76 | protected static final Position RIGHT_V_AXIS = new Position(0, 0, -1); 77 | 78 | protected static final Position FRONT_U_AXIS = new Position(1, 0, 0); 79 | protected static final Position FRONT_V_AXIS = new Position(0, 0, -1); 80 | protected static final Position BACK_U_AXIS = new Position(-1, 0, 0); 81 | protected static final Position BACK_V_AXIS = new Position(0, 0, -1); 82 | 83 | public final void writeSide(ValveWriter writer, Position first, Position second, Position third, String skin, 84 | double textureScale1, double textureScale2, Position uAxis, Position vAxis) throws IOException { 85 | 86 | writer.open(SIDE_TAG) 87 | .put(ValveElement.ID_TAG, writer.getCounter() 88 | .getNewSideId()) 89 | .put(PLANE_TAG, "(" + first.getString() + ") (" + second.getString() + ") (" + third.getString() + ")") 90 | .put(MATERIAL_TAG, skin) 91 | .put(UAXIS_TAG, "[" + uAxis.toAxisString() + " 0] " + this.skin.scale * textureScale1) 92 | .put(VAXIS_TAG, "[" + vAxis.toAxisString() + " 0] " + this.skin.scale * textureScale2) 93 | .put(ROTATION_TAG, 0) 94 | .put(LIGHTMAPSCALE_TAG, LIGHTMAPSCALE) 95 | .put(SMOOTHING_GROUPS_TAG, 0); 96 | writer.close(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/vmfWriter/Free8Point.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | 7 | public class Free8Point extends Cuboid { 8 | 9 | private boolean align; 10 | 11 | public Free8Point(Position[] p, Skin skin, boolean align) { 12 | super(p, skin); 13 | this.align = align; 14 | } 15 | 16 | @Override 17 | public void writeVmf(ValveWriter writer) throws IOException { 18 | writer.open(Solid.SOLID_TAG) 19 | .put(ValveElement.ID_TAG, writer.getCounter() 20 | .getNewBrushId()); 21 | if (this.align) { 22 | this.writeSide(writer, this.aTop, this.eTop, this.hTop, this.skin.materialTop, this.textureScaleX, 23 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 24 | this.writeSide(writer, this.e, this.a, this.d, this.skin.materialBottom, this.textureScaleX, 25 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 26 | this.writeSide(writer, this.a, this.e, this.eTop, this.skin.materialLeft, this.textureScaleX, 27 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 28 | this.writeSide(writer, this.h, this.d, this.dTop, this.skin.materialRight, this.textureScaleX, 29 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 30 | this.writeSide(writer, this.e, this.h, this.hTop, this.skin.materialBack, this.textureScaleY, 31 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); 32 | this.writeSide(writer, this.d, this.a, this.aTop, this.skin.materialFront, this.textureScaleY, 33 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); 34 | } else { 35 | this.writeSide(writer, this.aTop, this.eTop, this.hTop, this.skin.materialTop, this.textureScaleX, 36 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 37 | this.writeSide(writer, this.e, this.a, this.d, this.skin.materialBottom, this.textureScaleX, 38 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 39 | this.writeSide(writer, this.a, this.e, this.eTop, this.skin.materialLeft, this.textureScaleX, 40 | this.textureScaleZ, FRONT_U_AXIS, LEFT_V_AXIS); 41 | this.writeSide(writer, this.h, this.d, this.dTop, this.skin.materialRight, this.textureScaleX, 42 | this.textureScaleZ, FRONT_U_AXIS, LEFT_V_AXIS); 43 | this.writeSide(writer, this.e, this.h, this.hTop, this.skin.materialBack, this.textureScaleY, 44 | this.textureScaleZ, LEFT_U_AXIS, FRONT_V_AXIS); 45 | this.writeSide(writer, this.d, this.a, this.aTop, this.skin.materialFront, this.textureScaleY, 46 | this.textureScaleZ, LEFT_U_AXIS, FRONT_V_AXIS); 47 | } 48 | writer.open(ValveElement.EDITOR_TAG) 49 | .put(ValveElement.COLOR, "0 215 172") 50 | .put(ValveElement.VISGROUPSHOWN, 1) 51 | .put(ValveElement.VISGROUPAUTOSHOWN, 1) 52 | .close(); 53 | writer.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/vmfWriter/Orientation.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | public enum Orientation { 4 | NORTH, 5 | WEST, 6 | SOUTH, 7 | EAST 8 | } 9 | -------------------------------------------------------------------------------- /src/vmfWriter/Ramp.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.IOException; 4 | 5 | import basic.Tuple; 6 | import minecraft.Position; 7 | 8 | public class Ramp extends Cuboid { 9 | 10 | private Orientation orientation; 11 | 12 | public Ramp(Cuboid cuboid, Orientation orientation) { 13 | super(cuboid); 14 | this.orientation = orientation; 15 | } 16 | 17 | public Ramp(Tuple positions, Skin skin, Orientation o) { 18 | super(positions, skin); 19 | this.orientation = o; 20 | } 21 | 22 | public Ramp(Position fPoint, int xLength, int yLength, int zLength, int scale, Skin skin, Orientation o) { 23 | super(fPoint, xLength, yLength, zLength, scale); 24 | this.setSkin(skin); 25 | this.orientation = o; 26 | this.scale(scale); 27 | } 28 | 29 | @Override 30 | public void writeVmf(ValveWriter writer) throws IOException { 31 | writer.open(Solid.SOLID_TAG) 32 | .putBrushID(); 33 | switch (this.orientation) { 34 | case WEST: 35 | // top 36 | this.writeSide(writer, this.aTop, this.eTop, this.h, this.skin.materialTop, this.textureScaleX, 37 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 38 | // bottom 39 | this.writeSide(writer, this.e, this.a, this.d, this.skin.materialBottom, this.textureScaleX, 40 | this.textureScaleY, BOTTOM_U_AXIS, BOTTOM_V_AXIS); 41 | 42 | // negative x side 43 | this.writeSide(writer, this.a, this.e, this.eTop, this.skin.materialLeft, this.textureScaleX, 44 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 45 | // positive y side 46 | this.writeSide(writer, this.e, this.h, this.eTop, this.skin.materialBack, this.textureScaleY, 47 | this.textureScaleZ, BACK_U_AXIS, BACK_V_AXIS); 48 | // negative y side 49 | this.writeSide(writer, this.d, this.a, this.aTop, this.skin.materialFront, this.textureScaleY, 50 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); 51 | break; 52 | case EAST: 53 | // top 54 | this.writeSide(writer, this.a, this.e, this.hTop, this.skin.materialTop, this.textureScaleX, 55 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 56 | // bottom 57 | this.writeSide(writer, this.e, this.a, this.d, this.skin.materialBottom, this.textureScaleX, 58 | this.textureScaleY, BOTTOM_U_AXIS, BOTTOM_V_AXIS); 59 | 60 | // positive x side 61 | this.writeSide(writer, this.h, this.d, this.dTop, this.skin.materialRight, this.textureScaleX, 62 | this.textureScaleZ, RIGHT_U_AXIS, RIGHT_V_AXIS); 63 | 64 | // positive y side 65 | this.writeSide(writer, this.e, this.h, this.hTop, this.skin.materialBack, this.textureScaleY, 66 | this.textureScaleZ, BACK_U_AXIS, BACK_V_AXIS); 67 | // negative y side 68 | this.writeSide(writer, this.d, this.a, this.dTop, this.skin.materialFront, this.textureScaleY, 69 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); 70 | break; 71 | case NORTH: 72 | this.writeSide(writer, this.hTop, this.d, this.a, this.skin.materialTop, this.textureScaleX, 73 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 74 | this.writeSide(writer, this.d, this.h, this.e, this.skin.materialBottom, this.textureScaleX, 75 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 76 | 77 | this.writeSide(writer, this.a, this.e, this.eTop, this.skin.materialLeft, this.textureScaleX, 78 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 79 | 80 | this.writeSide(writer, this.d, this.hTop, this.h, this.skin.materialBack, this.textureScaleX, 81 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 82 | this.writeSide(writer, this.eTop, this.e, this.h, this.skin.materialFront, this.textureScaleY, 83 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); // really? 84 | break; 85 | case SOUTH: 86 | this.writeSide(writer, this.d, this.a, this.aTop, this.skin.materialTop, this.textureScaleX, 87 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 88 | this.writeSide(writer, this.a, this.d, this.h, this.skin.materialBottom, this.textureScaleX, 89 | this.textureScaleY, TOP_U_AXIS, TOP_V_AXIS); 90 | 91 | this.writeSide(writer, this.a, this.e, this.aTop, this.skin.materialLeft, this.textureScaleX, 92 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 93 | 94 | this.writeSide(writer, this.d, this.dTop, this.h, this.skin.materialBack, this.textureScaleX, 95 | this.textureScaleZ, LEFT_U_AXIS, LEFT_V_AXIS); 96 | this.writeSide(writer, this.h, this.dTop, this.aTop, this.skin.materialFront, this.textureScaleY, 97 | this.textureScaleZ, FRONT_U_AXIS, FRONT_V_AXIS); 98 | break; 99 | } 100 | writer.open(ValveElement.EDITOR_TAG) 101 | .put(ValveElement.COLOR, "0 215 172") 102 | .put(ValveElement.VISGROUPSHOWN, 1) 103 | .put(ValveElement.VISGROUPAUTOSHOWN, 1) 104 | .close(); 105 | writer.close(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/vmfWriter/Skin.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | /** 4 | * 5 | * 6 | */ 7 | public class Skin { 8 | 9 | public String materialFront; 10 | public String materialLeft; 11 | public String materialRight; 12 | public String materialTop; 13 | public String materialBottom; 14 | public String materialBack; 15 | public double scale; 16 | 17 | public Skin() { 18 | this.materialFront = null; 19 | this.materialLeft = null; 20 | this.materialRight = null; 21 | this.materialTop = null; 22 | this.materialBottom = null; 23 | this.materialBack = null; 24 | this.scale = 64 / 256; 25 | } 26 | 27 | public Skin(String newMaterial, double newScale) { 28 | this.materialFront = newMaterial; 29 | this.materialLeft = newMaterial; 30 | this.materialRight = newMaterial; 31 | this.materialTop = newMaterial; 32 | this.materialBottom = newMaterial; 33 | this.materialBack = newMaterial; 34 | this.scale = newScale; 35 | } 36 | 37 | public Skin(String material, String materialTopBottom, double newScale) { 38 | this.materialFront = material; 39 | this.materialLeft = material; 40 | this.materialRight = material; 41 | this.materialBack = material; 42 | 43 | this.materialTop = materialTopBottom; 44 | this.materialBottom = materialTopBottom; 45 | 46 | this.scale = newScale; 47 | } 48 | 49 | public Skin(String newMaterial, String newMaterialTop, String newMaterialFront, double newScale) { 50 | this.materialLeft = newMaterial; 51 | this.materialRight = newMaterial; 52 | this.materialBack = newMaterial; 53 | 54 | this.materialTop = newMaterialTop; 55 | this.materialBottom = newMaterialTop; 56 | 57 | this.materialFront = newMaterialFront; 58 | 59 | this.scale = newScale; 60 | } 61 | 62 | public Skin(String newMaterial, String newMaterialTop, String newMaterialFront, Orientation orientation, 63 | double newScale) { 64 | this.materialLeft = newMaterial; 65 | this.materialRight = newMaterial; 66 | this.materialBack = newMaterial; 67 | this.materialFront = newMaterial; 68 | 69 | this.materialTop = newMaterialTop; 70 | this.materialBottom = newMaterialTop; 71 | 72 | switch (orientation) { 73 | case SOUTH: 74 | this.materialFront = newMaterialFront; 75 | break; 76 | case EAST: 77 | this.materialRight = newMaterialFront; 78 | break; 79 | case NORTH: 80 | this.materialBack = newMaterialFront; 81 | break; 82 | case WEST: 83 | this.materialLeft = newMaterialFront; 84 | break; 85 | } 86 | this.scale = newScale; 87 | } 88 | 89 | public Skin(String newMaterial, String newMaterialTop, String newMaterialFront, String newMaterialBottom, 90 | double newScale) { 91 | this.materialLeft = newMaterial; 92 | this.materialRight = newMaterial; 93 | this.materialBack = newMaterial; 94 | 95 | this.materialTop = newMaterialTop; 96 | this.materialBottom = newMaterialBottom; 97 | this.materialFront = newMaterialFront; 98 | 99 | this.scale = newScale; 100 | } 101 | 102 | public Skin(String newMaterial, String newMaterialTop, String newMaterialFront, String newMaterialBottom, 103 | Orientation orientation, double newScale) { 104 | this.materialLeft = newMaterial; 105 | this.materialRight = newMaterial; 106 | this.materialBack = newMaterial; 107 | this.materialFront = newMaterial; 108 | 109 | this.materialTop = newMaterialTop; 110 | this.materialBottom = newMaterialBottom; 111 | 112 | switch (orientation) { 113 | case SOUTH: 114 | this.materialFront = newMaterialFront; 115 | break; 116 | case EAST: 117 | this.materialRight = newMaterialFront; 118 | break; 119 | case NORTH: 120 | this.materialBack = newMaterialFront; 121 | break; 122 | case WEST: 123 | this.materialLeft = newMaterialFront; 124 | break; 125 | } 126 | this.scale = newScale; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/vmfWriter/Solid.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | public abstract class Solid extends ValveElement { 4 | 5 | protected static final String SOLID_TAG = "solid"; 6 | 7 | protected Skin skin; 8 | 9 | public final void setSkin(Skin skin) { 10 | this.skin = skin; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/vmfWriter/SourceMap.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import converter.ConvertingReport; 7 | import minecraft.Position; 8 | import periphery.SourceGame; 9 | import vmfWriter.entity.pointEntity.PointEntity; 10 | import vmfWriter.entity.solidEntity.SolidEntity; 11 | 12 | public interface SourceMap { 13 | 14 | public void setSkyTexture(String skyTexture); 15 | 16 | public void addSolid(Solid solid); 17 | 18 | public void addDetail(Solid... solids); 19 | 20 | /** 21 | * Adds a point entity and returns the just added point entity. 22 | * 23 | * @param pointEntity 24 | * @return 25 | */ 26 | public PointEntity addPointEntity(PointEntity pointEntity); 27 | 28 | public PointEntity addPointEntity(PointEntity entity, Position position); 29 | 30 | public void addPointEntity(Position position, PointEntity type); 31 | 32 | public void addPointEntitys(Position position, Position end, int space, PointEntity type); 33 | 34 | public void addSolidEntity(SolidEntity solidEnttiy); 35 | 36 | public void setPointToGrid(Position position); 37 | 38 | public void movePointInGridDimension(double x, double y, double z); 39 | 40 | public void movePointExactly(Position offset); 41 | 42 | public void setCameraPosition(Position origin); 43 | 44 | public void setCameraLook(Position position); 45 | 46 | public ConvertingReport write(File file, SourceGame game) throws IOException; 47 | } 48 | -------------------------------------------------------------------------------- /src/vmfWriter/ValveElement.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.IOException; 4 | 5 | public abstract class ValveElement { 6 | 7 | public static final String ID_TAG = "id"; 8 | public static final String COLOR = "color"; 9 | public static final String VISGROUPSHOWN = "visgroupshown"; 10 | public static final String EDITOR_TAG = "editor"; 11 | public static final String VISGROUPAUTOSHOWN = "visgroupautoshown"; 12 | public static final String ENTITY_TAG = "entity"; 13 | public static final String CLASSNAME_TAG = "classname"; 14 | 15 | public abstract void writeVmf(ValveWriter writer) throws IOException; 16 | } 17 | -------------------------------------------------------------------------------- /src/vmfWriter/ValveWriter.java: -------------------------------------------------------------------------------- 1 | package vmfWriter; 2 | 3 | import java.io.File; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | 8 | import minecraft.Position; 9 | 10 | public class ValveWriter { 11 | 12 | private static final String INDENTATION = "\t"; 13 | private static final String OPEN_TAG = "{"; 14 | private static final String CLOSE_TAG = "}"; 15 | private static final String QUOTE = "\""; 16 | private static final String LINE_BREAK = "\n"; 17 | 18 | private Writer writer; 19 | private Counter counter; 20 | private int indentation = 0; 21 | 22 | public ValveWriter(File file) throws IOException { 23 | this(new FileWriter(file), new Counter()); 24 | } 25 | 26 | public ValveWriter(Writer w, Counter counter) { 27 | this.writer = w; 28 | this.counter = counter; 29 | } 30 | 31 | public Counter getCounter() { 32 | return this.counter; 33 | } 34 | 35 | public void setCounter(Counter counter) { 36 | this.counter = counter; 37 | } 38 | 39 | public ValveWriter setIndentation(int indentation) { 40 | this.indentation = indentation; 41 | return this; 42 | } 43 | 44 | public ValveWriter putATry(String title, Runnable body) throws IOException { 45 | this.open(title); 46 | body.run(); 47 | this.close(); 48 | return this; 49 | } 50 | 51 | public ValveWriter open(String title) throws IOException { 52 | this.writeLine(title); 53 | this.writeLine(OPEN_TAG); 54 | this.indentation++; 55 | return this; 56 | } 57 | 58 | public ValveWriter close() throws IOException { 59 | this.indentation--; 60 | this.writeLine(CLOSE_TAG); 61 | return this; 62 | } 63 | 64 | public ValveWriter put(String key, String value) throws IOException { 65 | this.writeLine(QUOTE + key + QUOTE + " " + QUOTE + value + QUOTE); 66 | return this; 67 | } 68 | 69 | public ValveWriter put(String key, int value) throws IOException { 70 | return this.put(key, value + ""); 71 | } 72 | 73 | public ValveWriter put(String key, boolean value) throws IOException { 74 | if (value) { 75 | return this.put(key, "1"); 76 | } else { 77 | return this.put(key, "0"); 78 | } 79 | } 80 | 81 | public ValveWriter put(String key, Color color) throws IOException { 82 | return this.put(key, color.red + " " + color.green + " " + color.blue); 83 | } 84 | 85 | public ValveWriter putInBrackets(String key, java.awt.Color color) throws IOException { 86 | if (color != null) { 87 | this.put(key, "{" + color.getRed() + " " + color.getGreen() + " " + color.getBlue() + "}"); 88 | } 89 | return this; 90 | } 91 | 92 | public ValveWriter putTransparentColor(String key, Color color) throws IOException { 93 | return this.put(key, color.red + " " + color.green + " " + color.blue + " " + color.alpha); 94 | } 95 | 96 | public ValveWriter put(String key, Position position) throws IOException { 97 | return this.put(key, position.getX() + " " + position.getY() + " " + position.getZ()); 98 | } 99 | 100 | public ValveWriter put(String key, Angles angles) throws IOException { 101 | return this.put(key, angles.getX() + " " + angles.getY() + " " + angles.getZ()); 102 | } 103 | 104 | private void writeLine(String title) throws IOException { 105 | this.writeIndentation() 106 | .write(title + ValveWriter.LINE_BREAK); 107 | } 108 | 109 | private ValveWriter writeIndentation() throws IOException { 110 | for (int i = 0; i < this.indentation; i++) { 111 | this.writer.write(INDENTATION); 112 | } 113 | return this; 114 | } 115 | 116 | private ValveWriter write(String text) throws IOException { 117 | this.writer.write(text); 118 | return this; 119 | } 120 | 121 | public void finish() throws IOException { 122 | this.writer.close(); 123 | } 124 | 125 | public void putBrushID() throws IOException { 126 | this.put(ValveElement.ID_TAG, this.getCounter() 127 | .getNewBrushId()); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity; 2 | 3 | import java.io.IOException; 4 | 5 | import vmfWriter.ValveElement; 6 | import vmfWriter.ValveWriter; 7 | 8 | public abstract class Entity extends ValveElement { 9 | 10 | public static final String ENTITY_TAG = "entity"; 11 | public static final String CLASSNAME_TAG = "classname"; 12 | public static final String ORIGIN_TAG = "origin"; 13 | public static final String LOGICALPOS_TAG = "logicalpos"; 14 | 15 | public String name; 16 | 17 | @Override 18 | public void writeVmf(ValveWriter writer) throws IOException { 19 | this.writeStart(writer); 20 | this.writeVmfSpecific(writer); 21 | this.writeEnd(writer); 22 | } 23 | 24 | protected void writeStart(ValveWriter writer) throws IOException { 25 | this.openEntity(writer); 26 | } 27 | 28 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 29 | 30 | } 31 | 32 | protected void writeEnd(ValveWriter writer) throws IOException { 33 | this.writeEditorWithLogicalpos(writer); 34 | writer.close(); 35 | } 36 | 37 | public ValveWriter openEntity(ValveWriter writer) throws IOException { 38 | return writer.open(ValveElement.ENTITY_TAG) 39 | .put(ValveElement.ID_TAG, writer.getCounter() 40 | .getNewBrushId()) 41 | .put(ValveElement.CLASSNAME_TAG, this.getName()); 42 | } 43 | 44 | public String getName() { 45 | return this.name; 46 | } 47 | 48 | public Entity setName(String name) { // TODO some entities overwrite getName, for others the name is set from extern 49 | this.name = name; 50 | return this; 51 | } 52 | 53 | public void writeEditorWithLogicalpos(ValveWriter writer) throws IOException { 54 | writer.open(ValveElement.EDITOR_TAG) 55 | .put(ValveElement.COLOR, "220 30 220") 56 | .put(ValveElement.VISGROUPSHOWN, 1) 57 | .put(ValveElement.VISGROUPAUTOSHOWN, 1) 58 | .put(Entity.LOGICALPOS_TAG, "[0 1000]") 59 | .close(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/Tf2Team.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity; 2 | 3 | public class Tf2Team { 4 | 5 | public final static int ANY = 0; 6 | public final static int RED = 2; 7 | public final static int BLUE = 3; 8 | } 9 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/NamedPointEntity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity; 2 | 3 | public abstract class NamedPointEntity extends PointEntity { 4 | 5 | private static int nameCount = 0; 6 | 7 | private String targetName; 8 | 9 | public NamedPointEntity() { 10 | this.createName(); 11 | } 12 | 13 | private NamedPointEntity createName() { 14 | NamedPointEntity.nameCount++; 15 | this.targetName = Integer.toString(NamedPointEntity.nameCount); 16 | return this; 17 | } 18 | 19 | public String getTargetName() { 20 | return this.targetName; 21 | } 22 | 23 | public void setTargetName(String name) throws PointEntityNameException { 24 | if (NamedPointEntity.isNumber(name)) { 25 | throw new PointEntityNameException("To avoid name conflicts PointEntities cannot be named after a number."); 26 | } else { 27 | this.targetName = name; 28 | } 29 | } 30 | 31 | public NamedPointEntity createNamedPointEntity(NamedPointEntity result) { 32 | return result.createName(); 33 | } 34 | 35 | private static boolean isNumber(String string) { 36 | for (char c : string.toCharArray()) { 37 | if (!Character.isDigit(c)) { 38 | return false; 39 | } 40 | } 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/PointEntity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.ValveWriter; 7 | import vmfWriter.entity.Entity; 8 | 9 | public abstract class PointEntity extends Entity { 10 | 11 | protected Position origin; 12 | 13 | public PointEntity() { 14 | this.origin = new Position(); 15 | } 16 | 17 | public PointEntity(Position origin) { 18 | this.origin = new Position(origin); 19 | } 20 | 21 | protected void setOrigin(Position origin) { 22 | this.origin = new Position(origin); 23 | } 24 | 25 | public abstract PointEntity create(Position origin); 26 | 27 | @Override 28 | protected void writeEnd(ValveWriter writer) throws IOException { 29 | writer.put(Entity.ORIGIN_TAG, this.origin.getString()); 30 | super.writeEnd(writer); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/PointEntityNameException.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity; 2 | 3 | public class PointEntityNameException extends Throwable { 4 | 5 | private static final long serialVersionUID = -5160827461972511263L; 6 | 7 | public PointEntityNameException(String message) { 8 | super(message); 9 | } 10 | } -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/RotateablePointEntity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.ValveWriter; 7 | 8 | public class RotateablePointEntity extends PointEntity { 9 | 10 | // private int rotation; 11 | 12 | protected Position angle = new Position(); 13 | 14 | public RotateablePointEntity() { 15 | 16 | } 17 | 18 | public RotateablePointEntity setRotation(int rotation) { 19 | this.angle.setY(rotation); 20 | return this; 21 | } 22 | 23 | @Override 24 | public PointEntity create(Position origin) { 25 | RotateablePointEntity result = new RotateablePointEntity(); 26 | result.setName(this.getName()); 27 | result.setOrigin(origin); 28 | result.setAngle(this.angle); 29 | return result; 30 | } 31 | 32 | public RotateablePointEntity setRotation(Position rotation) { 33 | this.angle.setTo(rotation); 34 | return this; 35 | } 36 | 37 | public int getRotation() { 38 | return this.angle.getX(); 39 | } 40 | 41 | public RotateablePointEntity setAngle(Position angle) { 42 | this.angle = angle.copy(); 43 | return this; 44 | } 45 | 46 | protected Position getAngle() { 47 | return this.angle; 48 | } 49 | 50 | @Override 51 | public final void writeVmfSpecific(ValveWriter writer) throws IOException { 52 | writer.put("angles", this.angle); 53 | // writer.put("angles", "0 " + this.getRotation() + " 0"); 54 | this.writeVmfSpecific2(writer); 55 | } 56 | 57 | public void writeVmfSpecific2(ValveWriter writer) throws IOException { 58 | 59 | } 60 | 61 | @Override 62 | public RotateablePointEntity setName(String name) { 63 | this.name = name; 64 | return this; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/CustomPointEntity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import minecraft.Position; 4 | import vmfWriter.entity.pointEntity.PointEntity; 5 | 6 | public class CustomPointEntity extends PointEntity { 7 | 8 | private String name; 9 | 10 | public CustomPointEntity(Position origin, String name) { 11 | super(origin); 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | public CustomPointEntity create(Position origin) { 17 | return new CustomPointEntity(origin, this.name); 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return this.name; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/EnvFire.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.ValveWriter; 7 | import vmfWriter.entity.pointEntity.PointEntity; 8 | 9 | public class EnvFire extends PointEntity { 10 | 11 | private int fireSize = 3; 12 | 13 | public EnvFire() { 14 | super(); 15 | } 16 | 17 | @Override 18 | public EnvFire create(Position origin) { 19 | EnvFire result = new EnvFire(); 20 | result.setOrigin(origin); 21 | return result; 22 | } 23 | 24 | private static final int FIREATTACK = 4; 25 | private static final int FIRETYPE = 0; 26 | 27 | private static final String FIREATTACK_TAG = "fireattack"; 28 | private static final String FIRESIZE_TAG = "firesize"; 29 | private static final String FIRETYPE_TAG = "firetype"; 30 | private static final String HEALTH_TAG = "health"; 31 | private static final String IGNITIONPOINT_TAG = "ignitionpoint"; 32 | private static final String SPAWNFLAGS_TAG = "spawnflags"; 33 | private static final String STARTDISABLED_TAG = "StartDisabled"; 34 | 35 | @Override 36 | public String getName() { 37 | return "env_fire"; 38 | } 39 | 40 | public EnvFire setFireSize(int fireSize) { 41 | this.fireSize = fireSize; 42 | return this; 43 | } 44 | 45 | @Override 46 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 47 | writer.put(FIREATTACK_TAG, FIREATTACK) 48 | .put("damagescale", "1.0") 49 | .put(FIRESIZE_TAG, this.fireSize) // 50 | .put(FIRETYPE_TAG, FIRETYPE) 51 | .put(HEALTH_TAG, 60) 52 | .put(IGNITIONPOINT_TAG, 32) 53 | .put(SPAWNFLAGS_TAG, 21) // 16// 25 54 | .put(STARTDISABLED_TAG, 0); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/InfoParticleSystem.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Angles; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | 10 | public class InfoParticleSystem extends PointEntity { 11 | 12 | private final String effectName; 13 | private final int angleX; 14 | private final int angleY; 15 | private final int angleZ; 16 | 17 | public InfoParticleSystem(String effectName, int angleX, int angleY, int angleZ) { 18 | this.effectName = effectName; 19 | this.angleX = angleX; 20 | this.angleY = angleY; 21 | this.angleZ = angleZ; 22 | } 23 | 24 | @Override 25 | public InfoParticleSystem create(Position origin) { 26 | InfoParticleSystem result = new InfoParticleSystem(this.effectName, this.angleX, this.angleY, this.angleZ); 27 | result.setOrigin(origin); 28 | return result; 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return "info_particle_system"; 34 | } 35 | 36 | @Override 37 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 38 | Angles angles = new Angles(this.angleX, this.angleY, this.angleZ); 39 | writer.put("angles", angles) 40 | .put("cpoint1_parent", 0) 41 | .put("cpoint2_parent", 0) 42 | .put("cpoint3_parent", 0) 43 | .put("cpoint4_parent", 0) 44 | .put("cpoint5_parent", 0) 45 | .put("cpoint6_parent", 0) 46 | .put("cpoint7_parent", 0) 47 | .put("effect_name", this.effectName) 48 | .put("flag_as_weather", false) 49 | .put("start_active", true); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/InfoPlayerCT.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import minecraft.Position; 4 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 5 | 6 | public class InfoPlayerCT extends RotateablePointEntity { 7 | 8 | @Override 9 | public InfoPlayerCT create(Position origin) { 10 | InfoPlayerCT result = new InfoPlayerCT(); 11 | result.setRotation(this.getRotation()); 12 | result.setOrigin(origin); 13 | return result; 14 | } 15 | 16 | @Override 17 | public String getName() { 18 | return "info_player_counterterrorist"; 19 | } 20 | 21 | // @Override 22 | // public void writeVmfSpecific(ValveWriter writer) throws IOException { 23 | // writer.put("angles", "0 " + this.getRotation() + " 0"); 24 | // } 25 | } 26 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/InfoPlayerStart.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import minecraft.Position; 4 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 5 | 6 | public class InfoPlayerStart extends RotateablePointEntity { 7 | 8 | @Override 9 | public InfoPlayerStart create(Position origin) { 10 | InfoPlayerStart result = new InfoPlayerStart(); 11 | result.setRotation(this.getRotation()); 12 | result.setOrigin(origin); 13 | return result; 14 | } 15 | 16 | @Override 17 | public String getName() { 18 | return "info_player_start"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/InfoPlayerT.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import minecraft.Position; 4 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 5 | 6 | public class InfoPlayerT extends RotateablePointEntity { 7 | 8 | @Override 9 | public InfoPlayerT create(Position origin) { 10 | InfoPlayerT result = new InfoPlayerT(); 11 | result.setRotation(this.getRotation()); 12 | result.setOrigin(origin); 13 | return result; 14 | } 15 | 16 | @Override 17 | public String getName() { 18 | return "info_player_terrorist"; 19 | } 20 | 21 | // @Override 22 | // public void writeVmfSpecific(ValveWriter writer) throws IOException { 23 | // writer.put("angles", "0 " + this.getRotation() + " 0"); 24 | // } 25 | } 26 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/InfoPlayerTeamSpawn.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.ValveWriter; 7 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 8 | 9 | public class InfoPlayerTeamSpawn extends RotateablePointEntity { 10 | 11 | private int tf2Team = 0; 12 | 13 | public InfoPlayerTeamSpawn setTeamNumber(int teamNumber) { 14 | this.tf2Team = teamNumber; 15 | return this; 16 | } 17 | 18 | @Override 19 | public InfoPlayerTeamSpawn create(Position origin) { 20 | InfoPlayerTeamSpawn result = new InfoPlayerTeamSpawn(); 21 | result.setRotation(this.getRotation()); 22 | result.setTeamNum(this.getTeamNum()); 23 | result.setOrigin(origin); 24 | return result; 25 | } 26 | 27 | public int getTeamNum() { 28 | return this.tf2Team; 29 | } 30 | 31 | public InfoPlayerTeamSpawn setTeamNum(int teamNum) { 32 | this.tf2Team = teamNum; 33 | return this; 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return "info_player_teamspawn"; 39 | } 40 | 41 | @Override 42 | public void writeVmfSpecific2(ValveWriter writer) throws IOException { 43 | // writer.put("angles", "0 " + this.getRotation() + " 0") 44 | writer.put("StartDisabled", 0) 45 | .put("TeamNum", this.tf2Team); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/Light.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Color; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | 10 | public class Light extends PointEntity { 11 | 12 | private Color color; 13 | private int distance50; 14 | private int distance100; 15 | 16 | public Light(Color color, int distance50, int distance100) { 17 | this.color = color; 18 | this.distance50 = distance50; 19 | this.distance100 = distance100; 20 | } 21 | 22 | @Override 23 | public Light create(Position origin) { 24 | Light result = new Light(this.color, this.distance50, this.distance100); 25 | result.setOrigin(origin); 26 | return result; 27 | } 28 | 29 | @Override 30 | public String getName() { 31 | return "light"; 32 | } 33 | 34 | @Override 35 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 36 | writer.put("_constant_attn", 0) 37 | .put("_distance", 0) 38 | .put("_fifty_percent_distance", this.distance50) 39 | .put("_hardfalloff", 0) 40 | .put("_light", 41 | this.color.getRed() + " " + this.color.getGreen() + " " + this.color.getBlue() + " " 42 | + this.color.getAlpha()) 43 | .put("_lightHDR", "-1 -1 -1 1") 44 | .put("_lightscaleHDR", 1) 45 | .put("_linear_attn", 0) 46 | .put("_quadratic_attn", 1) 47 | .put("_zero_percent_distance", this.distance100) 48 | .put("style", 0); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/LightEnvironment.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Color; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | 10 | public class LightEnvironment extends PointEntity { 11 | 12 | private Color light; 13 | private Color ambient; 14 | 15 | public LightEnvironment(Position origin, Color light, Color ambient) { 16 | super(origin); 17 | this.light = light.copy(); 18 | this.ambient = ambient.copy(); 19 | } 20 | 21 | @Override 22 | public LightEnvironment create(Position origin) { 23 | return new LightEnvironment(origin, this.light.copy(), this.ambient.copy()); 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return "light_environment"; 29 | } 30 | 31 | @Override 32 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 33 | writer.putTransparentColor("_ambient", this.ambient) 34 | .put("_ambientHDR", "-1 -1 -1 1") 35 | .put("_AmbientScaleHDR", 1) 36 | .put("angles", "-70 356 0") 37 | .put("pitch", -70) 38 | .put("SunSpreadAngle", 0); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/NamedRotateablePointEntity.java: -------------------------------------------------------------------------------- 1 | //package vmfWriter.entity.pointEntity.pointEntity; 2 | // 3 | //import minecraft.Position; 4 | //import vmfWriter.entity.pointEntity.RotateablePointEntity; 5 | // 6 | //public class NamedRotateablePointEntity extends RotateablePointEntity { 7 | // 8 | // private String name; 9 | // 10 | // @Override 11 | // public NamedRotateablePointEntity create(Position origin) { 12 | // NamedRotateablePointEntity result = new NamedRotateablePointEntity(); 13 | // result.setName(this.getName()); 14 | // result.setRotation(this.getRotation()); 15 | // result.setOrigin(origin); 16 | // return result; 17 | // } 18 | // 19 | // public NamedRotateablePointEntity setName(String name) { 20 | // this.name = name; 21 | // return this; 22 | // } 23 | // 24 | // @Override 25 | // public String getName() { 26 | // return name; 27 | // } 28 | // 29 | //// @Override 30 | //// public void writeVmfSpecific(ValveWriter writer) throws IOException { 31 | //// writer.put("angles", "0 " + this.getRotation() + " 0"); 32 | //// } 33 | // 34 | //} 35 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/PropDynamic.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Color; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.RotateablePointEntity; 9 | 10 | public class PropDynamic extends RotateablePointEntity { 11 | 12 | private String model; 13 | // private int angleX = 0; 14 | // private int angleY = 0; 15 | // private int angleZ = 0; 16 | 17 | public PropDynamic(String model, int angleX, int angleY, int angleZ) { 18 | this(model, new Position(angleX, angleY, angleZ)); 19 | } 20 | 21 | public PropDynamic(String model, Position angle) { 22 | this.model = model; 23 | this.setRotation(angle); 24 | } 25 | 26 | @Override 27 | public PropDynamic create(Position origin) { 28 | PropDynamic result = new PropDynamic(this.model, this.angle); 29 | result.setOrigin(origin); 30 | return result; 31 | // return (PropDynamic) super.createPointEntity(result); 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return "prop_dynamic"; 37 | } 38 | 39 | @Override 40 | public void writeVmfSpecific2(ValveWriter writer) throws IOException { 41 | // writer.put("angles", this.angleX + " " + this.angleY + " " + this.angleZ) 42 | writer.put("DisableBoneFollowers", false) 43 | .put("disablereceiveshadows", false) 44 | .put("disableshadows", false) 45 | .put("ExplodeDamage", 0) 46 | .put("ExplodeRadius", 0) 47 | .put("fademaxdist", 0) 48 | .put("fademindist", -1) 49 | .put("fadescale", 1) 50 | .put("MaxAnimTime", 10) 51 | .put("maxdxlevel", 0) 52 | .put("MinAnimTime", 5) 53 | .put("mindxlevel", 0) 54 | .put("model", this.model) 55 | .put("screenspacefade", 0) 56 | .put("PerformanceMode", 0) 57 | .put("pressuredelay", 0) 58 | .put("RandomAnimation", 0) 59 | .put("renderamt", 255) 60 | .put("rendercolor", Color.FULL) 61 | .put("renderfx", 0) 62 | .put("rendermode", 0) 63 | .put("SetBodyGroup", 0) 64 | .put("skin", 0) 65 | .put("solid", 0) 66 | .put("spawnflags", 0) 67 | // .put("targetname", this.getTargetName()) 68 | ; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/PropStatic.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Angles; 7 | import vmfWriter.entity.pointEntity.PointEntity; 8 | 9 | public class PropStatic extends PointEntity { 10 | 11 | private String model; 12 | private Angles angles; 13 | 14 | public PropStatic(String model) { 15 | this(model, new Angles()); 16 | } 17 | 18 | public PropStatic(String model, Angles angles) { 19 | this.model = model; 20 | this.angles = angles.copy(); 21 | } 22 | 23 | public Angles getAngles() { 24 | return this.angles; 25 | } 26 | 27 | public void setModel(String model) { 28 | this.model = model; 29 | } 30 | 31 | @Override 32 | public PropStatic create(Position origin) { 33 | PropStatic result = new PropStatic(this.model, this.angles); 34 | result.setOrigin(origin); 35 | return result; 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return "prop_static"; 41 | } 42 | 43 | @Override 44 | public void writeVmfSpecific(vmfWriter.ValveWriter writer) throws IOException { 45 | writer.put("angles", this.angles) 46 | .put("disableselfshadowing", false) 47 | .put("disableshadows", false) 48 | .put("disablevertexlighting", false) 49 | .put("fademaxdist", 0) 50 | .put("fademindist", -1) 51 | .put("fadescale", 1) 52 | .put("ignorenormals", false) 53 | .put("maxdxlevel", 0) 54 | .put("mindxlevel", 0) 55 | .put("model", this.model) 56 | .put("screenspacefade", 0) 57 | .put("skin", 0) 58 | .put("solid", 0); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/pointEntity/pointEntity/ShadowControl.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.pointEntity.pointEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import minecraft.Position; 6 | import vmfWriter.Color; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | 10 | public class ShadowControl extends PointEntity { 11 | 12 | private Color shadow; 13 | 14 | public ShadowControl(Position origin, Color shadowNew) { 15 | super(origin); 16 | this.shadow = new Color(shadowNew); 17 | } 18 | 19 | @Override 20 | public ShadowControl create(Position origin) { 21 | return new ShadowControl(origin, this.shadow); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return "shadow_control"; 27 | } 28 | 29 | @Override 30 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 31 | writer.put("angles", "-70 356 0") 32 | .put("color", this.shadow) 33 | .put("disableallshadows", false) 34 | .put("distance", 75); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/BombTarget.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import converter.Skins; 6 | import vmfWriter.Cuboid; 7 | import vmfWriter.ValveWriter; 8 | 9 | public class BombTarget extends SolidEntity { 10 | 11 | private static final String HEISTBOMB = "heistbomb"; 12 | 13 | public BombTarget(String name, Cuboid s) { 14 | super(s); 15 | s.setSkin(Skins.TRIGGER); 16 | } 17 | 18 | @Override 19 | public String getName() { 20 | return "func_bomb_target"; 21 | } 22 | 23 | @Override 24 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 25 | writer.put(BombTarget.HEISTBOMB, 0); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/Buyzone.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import converter.Skins; 6 | import vmfWriter.Solid; 7 | import vmfWriter.ValveWriter; 8 | 9 | public class Buyzone extends SolidEntity { 10 | 11 | private static final String TEAM_NUM_TAG = "TeamNum"; 12 | 13 | private static final int TERRORIST = 2; 14 | private static final int COUNTER_TERRORIST = 3; 15 | 16 | int teamnumber; 17 | 18 | public Buyzone(Solid s, boolean police) { 19 | super(s); 20 | s.setSkin(Skins.TRIGGER); 21 | if (police) { 22 | this.teamnumber = COUNTER_TERRORIST; 23 | } else { 24 | this.teamnumber = TERRORIST; 25 | } 26 | } 27 | 28 | @Override 29 | public String getName() { 30 | return "func_bomb_target"; 31 | } 32 | 33 | @Override 34 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 35 | writer.put(TEAM_NUM_TAG, this.teamnumber); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/FuncDetail.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import vmfWriter.Solid; 6 | import vmfWriter.ValveWriter; 7 | 8 | /** 9 | * 10 | * 11 | */ 12 | public class FuncDetail extends SolidEntity { 13 | 14 | public FuncDetail(Solid solid) { 15 | super(solid); 16 | } 17 | 18 | public FuncDetail(Solid[] solids) { 19 | super(solids); 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "func_detail"; 25 | } 26 | 27 | @Override 28 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 29 | // nothing specific 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/FuncIllusionary.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import vmfWriter.Solid; 6 | import vmfWriter.ValveWriter; 7 | 8 | public class FuncIllusionary extends SolidEntity { 9 | 10 | public FuncIllusionary(Solid solid) { 11 | super(solid); 12 | } 13 | 14 | @Override 15 | public String getName() { 16 | return "func_illusionary"; 17 | } 18 | 19 | @Override 20 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 21 | writer.put("disablereceiveshadows", 0) 22 | .put("disableshadows", 0) 23 | .put("origin", "0 0 0") 24 | .put("renderamt", 255) 25 | .put("rendercolor", "255 255 255") 26 | .put("renderfx", 0) 27 | .put("rendermode", 0); 28 | } 29 | } -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/FuncRegenerate.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import converter.Skins; 6 | import vmfWriter.Solid; 7 | import vmfWriter.ValveWriter; 8 | import vmfWriter.entity.pointEntity.PointEntity; 9 | 10 | public class FuncRegenerate extends SolidEntity { 11 | 12 | private int tf2Team; 13 | private String target; 14 | 15 | public FuncRegenerate(Solid solid, int tf2Team, PointEntity target) { 16 | super(solid); 17 | solid.setSkin(Skins.TRIGGER); 18 | this.tf2Team = tf2Team; 19 | this.target = target.getName(); 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "func_regenerate"; 25 | } 26 | 27 | @Override 28 | public void writeVmfSpecific(ValveWriter writer) throws IOException { 29 | writer.put("associatedmodel", this.target); 30 | writer.put("StartDisabled", 0); 31 | writer.put("TeamNum", this.tf2Team); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/vmfWriter/entity/solidEntity/SolidEntity.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.entity.solidEntity; 2 | 3 | import java.io.IOException; 4 | 5 | import vmfWriter.Solid; 6 | import vmfWriter.ValveWriter; 7 | import vmfWriter.entity.Entity; 8 | 9 | public abstract class SolidEntity extends Entity { 10 | 11 | protected Solid solids[]; 12 | 13 | public SolidEntity(Solid solid) { 14 | this.solids = new Solid[1]; 15 | this.solids[0] = solid; 16 | } 17 | 18 | public SolidEntity(Solid[] solids) { 19 | this.solids = solids; 20 | } 21 | 22 | public void writeSolids(ValveWriter writer) throws IOException { 23 | for (Solid solid : this.solids) { 24 | solid.writeVmf(writer); 25 | } 26 | } 27 | 28 | @Override 29 | protected void writeEnd(ValveWriter writer) throws IOException { 30 | this.writeSolids(writer); 31 | super.writeEnd(writer); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/vmfWriter/texture/ValveTexture.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.texture; 2 | 3 | import java.awt.Color; 4 | import java.io.IOException; 5 | 6 | import vmfWriter.ValveElement; 7 | import vmfWriter.ValveWriter; 8 | 9 | public class ValveTexture extends ValveElement { 10 | 11 | private static final String COLOR = "$color"; 12 | private static final String TRANSLUCENT = "$translucent"; 13 | private static final String SURFACE_PROP = "$surfaceprop"; 14 | private static final String BASE_TEXTURE = "$basetexture"; 15 | private String baseTexture; 16 | private String surfaceProp = "brick"; 17 | private boolean translucent; 18 | private Color color; 19 | 20 | public ValveTexture(String baseTexture) { 21 | this.baseTexture = baseTexture; 22 | this.translucent = false; 23 | this.color = null; 24 | } 25 | 26 | public ValveTexture setTranslucent(boolean translucent) { 27 | this.translucent = translucent; 28 | return this; 29 | } 30 | 31 | public ValveTexture setColor(Color color) { 32 | this.color = color; 33 | return this; 34 | } 35 | 36 | @Override 37 | public void writeVmf(ValveWriter writer) throws IOException { 38 | writer.open("\"LightmappedGeneric\"") 39 | .put(BASE_TEXTURE, this.baseTexture) 40 | .put(SURFACE_PROP, this.surfaceProp) 41 | .put(TRANSLUCENT, this.translucent) 42 | .putInBrackets(COLOR, this.color) 43 | .close(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/vmfWriter/texture/VmtGenerator.java: -------------------------------------------------------------------------------- 1 | package vmfWriter.texture; 2 | 3 | import java.awt.Color; 4 | import java.io.File; 5 | import java.io.IOException; 6 | 7 | import vmfWriter.ValveWriter; 8 | 9 | public class VmtGenerator { 10 | private static final Color GRASS_COLOR = new Color(102, 255, 51); 11 | 12 | public static void main(String[] args) { 13 | try { 14 | File directory = new File("textures" + File.separator + "minecraft_original"); 15 | for (File subFile : directory.listFiles()) { 16 | if (!subFile.getName() 17 | .endsWith(".vtf")) { 18 | continue; 19 | } 20 | System.out.println(subFile.getName() 21 | .substring(0, subFile.getName() 22 | .length() - 4)); 23 | String vtfName = subFile.getName(); 24 | String plainName = vtfName.substring(0, vtfName.lastIndexOf('.')); 25 | ValveWriter writer = new ValveWriter(new File(directory, plainName + ".vmt")); 26 | ValveTexture texture = new ValveTexture("minecraft_original" + "/" + plainName); 27 | if (plainName.equals("mob_spawner")) { 28 | texture.setTranslucent(true); 29 | } else if (plainName.startsWith("leaves")) { 30 | texture.setTranslucent(true); 31 | texture.setColor(GRASS_COLOR); 32 | } else if (plainName.equals("grass_top") || plainName.equals("grass_side_overlay")) { 33 | texture.setColor(GRASS_COLOR); 34 | } 35 | texture.writeVmf(writer); 36 | writer.finish(); 37 | } 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | } 43 | --------------------------------------------------------------------------------