mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
small config tweaks, fallout JSON reader
This commit is contained in:
parent
596decb191
commit
69cd33a3d2
@ -1,6 +1,7 @@
|
||||
package com.hbm.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -9,6 +10,9 @@ import java.util.Random;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.inventory.RecipesCommon.MetaBlock;
|
||||
@ -28,17 +32,25 @@ public class FalloutConfigJSON {
|
||||
public static final Gson gson = new Gson();
|
||||
|
||||
public static void initialize() {
|
||||
File folder = MainRegistry.configDir;
|
||||
|
||||
File folder = MainRegistry.configHbmDir;
|
||||
|
||||
File config = new File(folder.getAbsolutePath() + File.separatorChar + "hbmFallout.json");
|
||||
File template = new File(folder.getAbsolutePath() + File.separatorChar + "_hbmFallout.json");
|
||||
|
||||
initDefault();
|
||||
|
||||
if(!config.exists()) {
|
||||
writeDefault(config);
|
||||
writeDefault(template);
|
||||
} else {
|
||||
List<FalloutEntry> conf = readConfig(config);
|
||||
|
||||
if(conf != null) {
|
||||
entries.clear();
|
||||
entries.addAll(conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void initDefault() {
|
||||
entries.add(new FalloutEntry()
|
||||
.mB(Blocks.leaves)
|
||||
@ -139,6 +151,23 @@ public class FalloutConfigJSON {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<FalloutEntry> readConfig(File config) {
|
||||
|
||||
try {
|
||||
JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class);
|
||||
JsonArray recipes = json.get("recipes").getAsJsonArray();
|
||||
List<FalloutEntry> conf = new ArrayList();
|
||||
|
||||
for(JsonElement recipe : recipes) {
|
||||
conf.add(FalloutEntry.readEntry(recipe));
|
||||
}
|
||||
return conf;
|
||||
|
||||
} catch(Exception ex) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class FalloutEntry {
|
||||
private Block matchesBlock = null;
|
||||
private int matchesMeta = -1;
|
||||
@ -157,6 +186,7 @@ public class FalloutConfigJSON {
|
||||
public FalloutEntry mB(Block block) { this.matchesBlock = block; return this; }
|
||||
public FalloutEntry mM(int meta) { this.matchesMeta = meta; return this; }
|
||||
public FalloutEntry mMa(Material mat) { this.matchesMaterial = mat; return this; }
|
||||
public FalloutEntry mO(boolean opaque) { this.matchesOpaque = opaque; return this; }
|
||||
|
||||
public FalloutEntry prim(Triplet<Block, Integer, Integer>... blocks) { this.primaryBlocks = blocks; return this; }
|
||||
public FalloutEntry sec(Triplet<Block, Integer, Integer>... blocks) { this.secondaryBlocks = blocks; return this; }
|
||||
@ -234,7 +264,21 @@ public class FalloutConfigJSON {
|
||||
if(primaryChance != 1D) writer.name("chance").value(primaryChance);
|
||||
}
|
||||
|
||||
private void writeMetaArray(JsonWriter writer, Triplet<Block, Integer, Integer>[] array) throws IOException {
|
||||
private static FalloutEntry readEntry(JsonElement recipe) {
|
||||
FalloutEntry entry = new FalloutEntry();
|
||||
if(!recipe.isJsonObject()) return null;
|
||||
|
||||
JsonObject obj = recipe.getAsJsonObject();
|
||||
|
||||
if(obj.has("matchesBlock")) entry.mB((Block) Block.blockRegistry.getObject(obj.get("matchesBlock").getAsString()));
|
||||
if(obj.has("matchesMeta")) entry.mM(obj.get("matchesMeta").getAsInt());
|
||||
if(obj.has("mustBeOpaque")) entry.mO(obj.get("mustBeOpaque").getAsBoolean());
|
||||
if(obj.has("matchesMaterial")) entry.mMa(matNames.get(obj.get("mustBeOpaque").getAsString()));
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
private static void writeMetaArray(JsonWriter writer, Triplet<Block, Integer, Integer>[] array) throws IOException {
|
||||
writer.beginArray();
|
||||
writer.setIndent("");
|
||||
|
||||
@ -249,6 +293,10 @@ public class FalloutConfigJSON {
|
||||
writer.endArray();
|
||||
writer.setIndent(" ");
|
||||
}
|
||||
|
||||
private static Triplet<Block, Integer, Integer>[] readMetaArray(JsonObject obj) {
|
||||
return null; //TODO
|
||||
}
|
||||
}
|
||||
|
||||
public static HashBiMap<String, Material> matNames = HashBiMap.create();
|
||||
|
||||
@ -6,34 +6,33 @@ import com.hbm.explosion.ExplosionNukeGeneric;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityOrangeFX extends EntityModFX {
|
||||
|
||||
public EntityOrangeFX(World world) {
|
||||
super(world, 0, 0, 0);
|
||||
}
|
||||
super(world, 0, 0, 0);
|
||||
}
|
||||
|
||||
public EntityOrangeFX(World p_i1225_1_, double p_i1225_2_, double p_i1225_4_, double p_i1225_6_, double p_i1225_8_, double p_i1225_10_, double p_i1225_12_)
|
||||
{
|
||||
this(p_i1225_1_, p_i1225_2_, p_i1225_4_, p_i1225_6_, p_i1225_8_, p_i1225_10_, p_i1225_12_, 1.0F);
|
||||
}
|
||||
public EntityOrangeFX(World p_i1225_1_, double p_i1225_2_, double p_i1225_4_, double p_i1225_6_, double p_i1225_8_, double p_i1225_10_, double p_i1225_12_) {
|
||||
this(p_i1225_1_, p_i1225_2_, p_i1225_4_, p_i1225_6_, p_i1225_8_, p_i1225_10_, p_i1225_12_, 1.0F);
|
||||
}
|
||||
|
||||
public EntityOrangeFX(World p_i1226_1_, double p_i1226_2_, double p_i1226_4_, double p_i1226_6_, double p_i1226_8_, double p_i1226_10_, double p_i1226_12_, float p_i1226_14_)
|
||||
{
|
||||
super(p_i1226_1_, p_i1226_2_, p_i1226_4_, p_i1226_6_, 0.0D, 0.0D, 0.0D);
|
||||
this.motionX *= 0.10000000149011612D;
|
||||
this.motionY *= 0.10000000149011612D;
|
||||
this.motionZ *= 0.10000000149011612D;
|
||||
this.motionX += p_i1226_8_;
|
||||
this.motionY += p_i1226_10_;
|
||||
this.motionZ += p_i1226_12_;
|
||||
this.particleRed = this.particleGreen = this.particleBlue = (float)(Math.random() * 0.30000001192092896D);
|
||||
this.particleScale *= 0.75F;
|
||||
this.particleScale *= p_i1226_14_;
|
||||
this.smokeParticleScale = this.particleScale;
|
||||
this.noClip = false;
|
||||
}
|
||||
public EntityOrangeFX(World p_i1226_1_, double p_i1226_2_, double p_i1226_4_, double p_i1226_6_, double p_i1226_8_, double p_i1226_10_, double p_i1226_12_, float p_i1226_14_) {
|
||||
super(p_i1226_1_, p_i1226_2_, p_i1226_4_, p_i1226_6_, 0.0D, 0.0D, 0.0D);
|
||||
this.motionX *= 0.1D;
|
||||
this.motionY *= 0.1D;
|
||||
this.motionZ *= 0.1D;
|
||||
this.motionX += p_i1226_8_;
|
||||
this.motionY += p_i1226_10_;
|
||||
this.motionZ += p_i1226_12_;
|
||||
this.particleRed = this.particleGreen = this.particleBlue = (float) (Math.random() * 0.3D);
|
||||
this.particleScale *= 0.75F;
|
||||
this.particleScale *= p_i1226_14_;
|
||||
this.smokeParticleScale = this.particleScale;
|
||||
this.noClip = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
@ -42,45 +41,40 @@ public class EntityOrangeFX extends EntityModFX {
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
if (maxAge < 900) {
|
||||
if(maxAge < 900) {
|
||||
maxAge = rand.nextInt(301) + 900;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && rand.nextInt(50) == 0)
|
||||
if(!worldObj.isRemote && rand.nextInt(50) == 0)
|
||||
ExplosionChaos.poison(worldObj, (int) posX, (int) posY, (int) posZ, 2);
|
||||
|
||||
this.particleAge++;
|
||||
|
||||
if (this.particleAge >= maxAge) {
|
||||
if(this.particleAge >= maxAge) {
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
this.motionX *= 0.8599999785423279D;
|
||||
this.motionY *= 0.8599999785423279D;
|
||||
this.motionZ *= 0.8599999785423279D;
|
||||
this.motionX *= 0.86D;
|
||||
this.motionY *= 0.86D;
|
||||
this.motionZ *= 0.86D;
|
||||
|
||||
if (this.onGround) {
|
||||
this.motionX *= 0.699999988079071D;
|
||||
this.motionZ *= 0.699999988079071D;
|
||||
}
|
||||
|
||||
this.motionY -= 0.1;
|
||||
|
||||
|
||||
double subdivisions = 4;
|
||||
|
||||
|
||||
for(int i = 0; i < subdivisions; i++) {
|
||||
|
||||
this.posX += this.motionX/subdivisions;
|
||||
this.posY += this.motionY/subdivisions;
|
||||
this.posZ += this.motionZ/subdivisions;
|
||||
|
||||
|
||||
this.posX += this.motionX / subdivisions;
|
||||
this.posY += this.motionY / subdivisions;
|
||||
this.posZ += this.motionZ / subdivisions;
|
||||
|
||||
if(worldObj.getBlock((int) posX, (int) posY, (int) posZ).getMaterial() != Material.air) {
|
||||
this.setDead();
|
||||
|
||||
|
||||
for(int a = -1; a < 2; a++) {
|
||||
for(int b = -1; b < 2; b++) {
|
||||
for(int c = -1; c < 2; c++) {
|
||||
|
||||
|
||||
Block bl = worldObj.getBlock((int) posX + a, (int) posY + b, (int) posZ + c);
|
||||
if(bl == Blocks.grass) {
|
||||
worldObj.setBlock((int) posX + a, (int) posY + b, (int) posZ + c, Blocks.dirt, 1, 3);
|
||||
@ -93,4 +87,13 @@ public class EntityOrangeFX extends EntityModFX {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean writeToNBTOptional(NBTTagCompound nbt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
super.readEntityFromNBT(nbt);
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,6 +234,7 @@ public class MainRegistry {
|
||||
|
||||
public static long startupTime = 0;
|
||||
public static File configDir;
|
||||
public static File configHbmDir;
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
@ -242,6 +243,9 @@ public class MainRegistry {
|
||||
|
||||
startupTime = System.currentTimeMillis();
|
||||
configDir = PreEvent.getModConfigurationDirectory();
|
||||
configHbmDir = new File(configDir.getAbsolutePath() + File.separatorChar + "hbmConfig");
|
||||
|
||||
if(!configHbmDir.exists()) configHbmDir.mkdir();
|
||||
|
||||
logger.info("Let us celebrate the fact that the logger finally works again!");
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.tileentity.machine.TileEntitySolarBoiler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@ -37,7 +38,7 @@ public class RenderSolarBoiler extends TileEntitySpecialRenderer {
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
if(te instanceof TileEntitySolarBoiler) {
|
||||
if(te instanceof TileEntitySolarBoiler && Minecraft.getMinecraft().gameSettings.particleSetting < 2) {
|
||||
TileEntitySolarBoiler boiler = (TileEntitySolarBoiler) te;
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user