Initial json's for machines, gui blocks are broken

This commit is contained in:
modmuss50 2016-04-24 21:49:22 +01:00
parent b55c0a3c8e
commit 61c7815f3b
92 changed files with 2032 additions and 11 deletions

View file

@ -1,5 +1,6 @@
package techreborn.command;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -105,7 +106,12 @@ public class TechRebornDevCommand extends CommandBase
((EntityPlayer) sender).addChatComponentMessage(new TextComponentString("hold an item!"));
}
} else if ("gen".equals(args[0])) { //TODO DO NOT SHIP!!!
try {
new JsonGenerator().generate();
} catch (IOException e) {
e.printStackTrace();
sender.addChatMessage(new TextComponentString(e.getLocalizedMessage()));
}
}
}
}

View file

@ -1,14 +1,17 @@
package techreborn.dev;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.common.registry.GameData;
import reborncore.RebornCore;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.LogHelper;
import techreborn.Core;
import techreborn.api.TechRebornAPI;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.*;
import java.util.Scanner;
/**
* Created by Mark on 24/04/2016.
@ -17,7 +20,7 @@ import java.io.Writer;
//TODO DO NOT SHIP THIS!
public class JsonGenerator {
public void generate(){
public void generate() throws IOException {
File mcDir = new File(".");
File exportFolder = new File(mcDir, "export");
if(!exportFolder.exists()){
@ -47,19 +50,52 @@ public class JsonGenerator {
if(!itemModles.exists()){
itemModles.mkdir();
}
File baseJsonFiles = new File(mcDir, "basejsons");
if(!baseJsonFiles.exists()){
Core.logHelper.error("Could not find base jsons dir!");
throw new FileNotFoundException();
}
File machineBaseFile = new File(baseJsonFiles, "machineBase.json");
String machineBase = Files.toString(machineBaseFile, Charsets.UTF_8);
File machineModelBaseFile = new File(baseJsonFiles, "machineModelBase.json");
String machineModelBase = Files.toString(machineModelBaseFile, Charsets.UTF_8);
for(Object object : RebornCore.jsonDestroyer.objectsToDestroy){
if(object instanceof BlockMachineBase){
BlockMachineBase base = (BlockMachineBase) object;
File state = new File(blockstates, base.getUnlocalizedName() + ".json");
String name = GameData.getBlockRegistry().getNameForObject(base).getResourcePath().replace("tile.techreborn.", "");
File state = new File(blockstates, name + ".json");
if(state.exists()){
state.delete();
}
String output = machineBase;
output = output.replaceAll("%MODEL%", "techreborn:" + base.getUnlocalizedName());
output = output.replaceAll("%OFF_TEXTURE%", base.getTextureNameFromState(base.getDefaultState(), EnumFacing.NORTH));
output = output.replaceAll("%ON_TEXTURE%", base.getTextureNameFromState(base.getDefaultState().withProperty(BlockMachineBase.ACTIVE, true), EnumFacing.NORTH));
try {
state.createNewFile();
FileOutputStream is = new FileOutputStream(state);
OutputStreamWriter osw = new OutputStreamWriter(is);
Writer w = new BufferedWriter(osw);
w.write("{");
w.write(output);
w.close();
} catch (IOException e) {
e.printStackTrace();
}
File model = new File(blockModels, base.getUnlocalizedName() + ".json");
if(model.exists()){
model.delete();
}
String modelOutput = machineModelBase;
modelOutput = modelOutput.replaceAll("%MODEL%", base.getUnlocalizedName() );
modelOutput = modelOutput.replaceAll("%OFF_TEXTURE%", base.getTextureNameFromState(base.getDefaultState(), EnumFacing.NORTH));
modelOutput = modelOutput.replaceAll("%ON_TEXTURE%", base.getTextureNameFromState(base.getDefaultState().withProperty(BlockMachineBase.ACTIVE, true), EnumFacing.NORTH));
modelOutput = modelOutput.replaceAll("%SIDE_TEXTURE%", base.getTextureNameFromState(base.getDefaultState(), EnumFacing.EAST));
modelOutput = modelOutput.replaceAll("%TOP_TEXTURE%", base.getTextureNameFromState(base.getDefaultState(), EnumFacing.UP));
try {
FileOutputStream is = new FileOutputStream(model);
OutputStreamWriter osw = new OutputStreamWriter(is);
Writer w = new BufferedWriter(osw);
w.write(modelOutput);
w.close();
} catch (IOException e) {
e.printStackTrace();
@ -69,5 +105,4 @@ public class JsonGenerator {
}
}