Rewrite Meteor system to be fully json (#914)
Also cleans up some other JSON stuff
This commit is contained in:
parent
0bb2fa6002
commit
d1455920ec
|
@ -3,6 +3,7 @@ package WayofTime.bloodmagic;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.meteor.MeteorConfigHandler;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -32,7 +33,6 @@ import WayofTime.bloodmagic.registry.ModBlocks;
|
||||||
import WayofTime.bloodmagic.registry.ModCompatibility;
|
import WayofTime.bloodmagic.registry.ModCompatibility;
|
||||||
import WayofTime.bloodmagic.registry.ModEntities;
|
import WayofTime.bloodmagic.registry.ModEntities;
|
||||||
import WayofTime.bloodmagic.registry.ModItems;
|
import WayofTime.bloodmagic.registry.ModItems;
|
||||||
import WayofTime.bloodmagic.registry.ModMeteors;
|
|
||||||
import WayofTime.bloodmagic.registry.ModPotions;
|
import WayofTime.bloodmagic.registry.ModPotions;
|
||||||
import WayofTime.bloodmagic.registry.ModRecipes;
|
import WayofTime.bloodmagic.registry.ModRecipes;
|
||||||
import WayofTime.bloodmagic.registry.ModRituals;
|
import WayofTime.bloodmagic.registry.ModRituals;
|
||||||
|
@ -127,7 +127,7 @@ public class BloodMagic
|
||||||
ModRecipes.init();
|
ModRecipes.init();
|
||||||
ModRituals.initRituals();
|
ModRituals.initRituals();
|
||||||
ModRituals.initImperfectRituals();
|
ModRituals.initImperfectRituals();
|
||||||
ModMeteors.init();
|
MeteorConfigHandler.init(new File(configDir, "meteors"));
|
||||||
ModArmourTrackers.init();
|
ModArmourTrackers.init();
|
||||||
ModCompatibility.loadCompat(ICompatibility.InitializationPhase.INIT);
|
ModCompatibility.loadCompat(ICompatibility.InitializationPhase.INIT);
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler());
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package WayofTime.bloodmagic;
|
package WayofTime.bloodmagic;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.meteor.MeteorConfigHandler;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -20,7 +21,6 @@ import WayofTime.bloodmagic.annot.Handler;
|
||||||
import WayofTime.bloodmagic.api.BlockStack;
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
import WayofTime.bloodmagic.registry.ModMeteors;
|
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
import WayofTime.bloodmagic.util.Utils;
|
||||||
|
|
||||||
@Handler
|
@Handler
|
||||||
|
@ -322,19 +322,6 @@ public class ConfigHandler
|
||||||
category = "Meteors";
|
category = "Meteors";
|
||||||
config.addCustomCategoryComment(category, "Meteor settings");
|
config.addCustomCategoryComment(category, "Meteor settings");
|
||||||
|
|
||||||
String[] defaultMeteors = ModMeteors.getDefaultMeteors();
|
|
||||||
boolean resyncMeteorOnVersionChange = config.getBoolean("resyncOnVersionChange", category, true, "");
|
|
||||||
Property meteorsProp = config.get(category, "MeteorList", defaultMeteors);
|
|
||||||
meteorsProp.setComment("These are meteors. Huzzah!");
|
|
||||||
if (resyncMeteorOnVersionChange && configVersionChanged)
|
|
||||||
{
|
|
||||||
meteorsProp.set(defaultMeteors);
|
|
||||||
ModMeteors.meteors = defaultMeteors;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
ModMeteors.meteors = meteorsProp.getStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +372,9 @@ public class ConfigHandler
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onConfigChanged(ConfigChangedEvent event)
|
public void onConfigChanged(ConfigChangedEvent event)
|
||||||
{
|
{
|
||||||
if (event.getModID().equals(Constants.Mod.MODID))
|
if (event.getModID().equals(Constants.Mod.MODID)) {
|
||||||
ConfigHandler.syncConfig();
|
syncConfig();
|
||||||
|
MeteorConfigHandler.handleMeteors(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package WayofTime.bloodmagic.gson;
|
|
||||||
|
|
||||||
public class Adapters
|
|
||||||
{
|
|
||||||
public static EnumFacingTypeAdapter adapter = new EnumFacingTypeAdapter();
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package WayofTime.bloodmagic.gson;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
public class EnumFacingTypeAdapter implements JsonDeserializer<EnumFacing>, JsonSerializer<EnumFacing>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public EnumFacing deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
|
||||||
{
|
|
||||||
String str = json.getAsString();
|
|
||||||
|
|
||||||
return EnumFacing.byName(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonElement serialize(EnumFacing src, Type typeOfSrc, JsonSerializationContext context)
|
|
||||||
{
|
|
||||||
// Not necessary, since this is only used for deserialization.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
22
src/main/java/WayofTime/bloodmagic/gson/SerializerBase.java
Normal file
22
src/main/java/WayofTime/bloodmagic/gson/SerializerBase.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package WayofTime.bloodmagic.gson;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public abstract class SerializerBase<T> implements JsonDeserializer<T>, JsonSerializer<T>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
return context.deserialize(json, getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
return context.serialize(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Class<T> getType();
|
||||||
|
}
|
83
src/main/java/WayofTime/bloodmagic/gson/Serializers.java
Normal file
83
src/main/java/WayofTime/bloodmagic/gson/Serializers.java
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
package WayofTime.bloodmagic.gson;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class Serializers
|
||||||
|
{
|
||||||
|
// Serializers
|
||||||
|
public static final SerializerBase<EnumFacing> FACING_SERIALIZER = new SerializerBase<EnumFacing>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Class<EnumFacing> getType()
|
||||||
|
{
|
||||||
|
return EnumFacing.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumFacing deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
return EnumFacing.byName(json.getAsString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final SerializerBase<ResourceLocation> RESOURCELOCATION_SERIALIZER = new SerializerBase<ResourceLocation>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Class<ResourceLocation> getType()
|
||||||
|
{
|
||||||
|
return ResourceLocation.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
String domain = json.getAsJsonObject().get("domain").getAsString();
|
||||||
|
String path = json.getAsJsonObject().get("path").getAsString();
|
||||||
|
return new ResourceLocation(domain, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(ResourceLocation src, Type typeOfSrc, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("domain", src.getResourceDomain());
|
||||||
|
object.addProperty("path", src.getResourcePath());
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final SerializerBase<ItemStack> ITEMMETA_SERIALIZER = new SerializerBase<ItemStack>() {
|
||||||
|
@Override
|
||||||
|
public Class<ItemStack> getType() {
|
||||||
|
return ItemStack.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
ResourceLocation registryName = context.deserialize(json.getAsJsonObject().get("registryName").getAsJsonObject(), ResourceLocation.class);
|
||||||
|
int meta = json.getAsJsonObject().get("meta").getAsInt();
|
||||||
|
return new ItemStack(ForgeRegistries.ITEMS.getValue(registryName), 1, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.add("registryName", context.serialize(src.getItem().getRegistryName()));
|
||||||
|
jsonObject.addProperty("meta", src.getItemDamage());
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Gson GSON = new GsonBuilder()
|
||||||
|
.serializeNulls()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.disableHtmlEscaping()
|
||||||
|
.registerTypeAdapter(FACING_SERIALIZER.getType(), FACING_SERIALIZER)
|
||||||
|
.registerTypeAdapter(RESOURCELOCATION_SERIALIZER.getType(), RESOURCELOCATION_SERIALIZER)
|
||||||
|
.registerTypeAdapter(ITEMMETA_SERIALIZER.getType(), ITEMMETA_SERIALIZER)
|
||||||
|
.create();
|
||||||
|
}
|
|
@ -1,61 +1,50 @@
|
||||||
package WayofTime.bloodmagic.meteor;
|
package WayofTime.bloodmagic.meteor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.Getter;
|
||||||
import net.minecraft.block.Block;
|
import lombok.Setter;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
import WayofTime.bloodmagic.util.Utils;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@Getter
|
||||||
public class MeteorHolder
|
public class Meteor
|
||||||
{
|
{
|
||||||
public static Random rand = new Random();
|
private static final Random RAND = new Random();
|
||||||
public ResourceLocation resourceKey;
|
|
||||||
public int metaKey = 0;
|
|
||||||
public List<MeteorComponent> components = new ArrayList<MeteorComponent>();
|
|
||||||
|
|
||||||
public float explosionStrength = 1;
|
private final ItemStack catalystStack;
|
||||||
public int radius = 1;
|
private final List<MeteorComponent> components;
|
||||||
|
private final float explosionStrength;
|
||||||
|
private final int radius;
|
||||||
|
private final int maxWeight;
|
||||||
|
|
||||||
public int maxWeight = 1000;
|
@Setter
|
||||||
|
public int version;
|
||||||
|
|
||||||
public ItemStack getKeyStack(int meta)
|
public Meteor(ItemStack catalystStack, List<MeteorComponent> components, float explosionStrength, int radius, int maxWeight)
|
||||||
{
|
{
|
||||||
Item item = Utils.getItem(resourceKey);
|
this.catalystStack = catalystStack;
|
||||||
if (item != null)
|
this.components = components;
|
||||||
{
|
this.explosionStrength = explosionStrength;
|
||||||
return new ItemStack(item, 1, meta);
|
this.radius = radius;
|
||||||
} else
|
this.maxWeight = maxWeight;
|
||||||
{
|
|
||||||
Block block = Utils.getBlock(resourceKey);
|
|
||||||
if (block != null)
|
|
||||||
{
|
|
||||||
return new ItemStack(block, 1, meta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateMeteor(World world, BlockPos pos, IBlockState fillerBlock)
|
public void generateMeteor(World world, BlockPos pos, IBlockState fillerBlock)
|
||||||
{
|
{
|
||||||
world.newExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosionStrength, true, true);
|
world.newExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosionStrength, true, true);
|
||||||
|
|
||||||
for (int i = -radius; i <= radius; i++)
|
for (int i = -getRadius(); i <= getRadius(); i++)
|
||||||
{
|
{
|
||||||
for (int j = -radius; j <= radius; j++)
|
for (int j = -getRadius(); j <= getRadius(); j++)
|
||||||
{
|
{
|
||||||
for (int k = -radius; k <= radius; k++)
|
for (int k = -getRadius(); k <= getRadius(); k++)
|
||||||
{
|
{
|
||||||
if (i * i + j * j + k * k > (radius + 0.5) * (radius + 0.5))
|
if (i * i + j * j + k * k > (getRadius() + 0.5) * (getRadius() + 0.5))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -75,9 +64,9 @@ public class MeteorHolder
|
||||||
|
|
||||||
public IBlockState getRandomOreFromComponents(IBlockState fillerBlock)
|
public IBlockState getRandomOreFromComponents(IBlockState fillerBlock)
|
||||||
{
|
{
|
||||||
int goal = rand.nextInt(maxWeight);
|
int goal = RAND.nextInt(getMaxWeight());
|
||||||
|
|
||||||
for (MeteorComponent component : components)
|
for (MeteorComponent component : getComponents())
|
||||||
{
|
{
|
||||||
goal -= component.getWeight();
|
goal -= component.getWeight();
|
||||||
if (goal < 0)
|
if (goal < 0)
|
|
@ -0,0 +1,115 @@
|
||||||
|
package WayofTime.bloodmagic.meteor;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.ConfigHandler;
|
||||||
|
import WayofTime.bloodmagic.gson.Serializers;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MeteorConfigHandler
|
||||||
|
{
|
||||||
|
private static final Map<String, Meteor> DEFAULT_METEORS = new HashMap<String, Meteor>();
|
||||||
|
|
||||||
|
private static File meteorDir;
|
||||||
|
|
||||||
|
public static void init(File meteorDirectory)
|
||||||
|
{
|
||||||
|
meteorDir = meteorDirectory;
|
||||||
|
handleMeteors(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleMeteors(boolean checkNewVersion)
|
||||||
|
{
|
||||||
|
// Clear the meteors so that reloading in-game can be done
|
||||||
|
MeteorRegistry.meteorMap.clear();
|
||||||
|
List<Pair<String, Meteor>> defaultMeteors = getDefaultMeteors();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Create defaults if the folder doesn't exist
|
||||||
|
if (!meteorDir.exists() && meteorDir.mkdir())
|
||||||
|
{
|
||||||
|
for (Pair<String, Meteor> meteor : defaultMeteors)
|
||||||
|
{
|
||||||
|
String json = Serializers.GSON.toJson(meteor.getRight());
|
||||||
|
FileWriter writer = new FileWriter(new File(meteorDir, meteor.getLeft() + ".json"));
|
||||||
|
writer.write(json);
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect all meteors from the files
|
||||||
|
File[] meteorFiles = meteorDir.listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".json"));
|
||||||
|
if (meteorFiles == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<Pair<String, Meteor>> meteors = new ArrayList<Pair<String, Meteor>>();
|
||||||
|
|
||||||
|
// Filter names so we can compare to defaults
|
||||||
|
for (File meteorFile : meteorFiles)
|
||||||
|
{
|
||||||
|
Meteor meteor = Serializers.GSON.fromJson(new FileReader(meteorFile), Meteor.class);
|
||||||
|
meteors.add(Pair.of(FilenameUtils.removeExtension(meteorFile.getName()), meteor));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkNewVersion && ConfigHandler.getConfig().getBoolean("resyncOnVersionChange", "Meteors", true, "Should the default meteors be regenerated if the mod has updated them"))
|
||||||
|
{
|
||||||
|
// Check defaults for new version
|
||||||
|
for (Pair<String, Meteor> meteor : meteors)
|
||||||
|
{
|
||||||
|
Meteor defaultMeteor = DEFAULT_METEORS.get(meteor.getLeft());
|
||||||
|
if (defaultMeteor != null && defaultMeteor.version > meteor.getRight().version)
|
||||||
|
{
|
||||||
|
String json = Serializers.GSON.toJson(defaultMeteor);
|
||||||
|
File meteorFile = new File(meteorDir, meteor.getLeft() + ".json");
|
||||||
|
new PrintWriter(meteorFile).close(); // Clear the file
|
||||||
|
FileWriter fileWriter = new FileWriter(meteorFile);
|
||||||
|
fileWriter.write(json); // Write the new contents
|
||||||
|
fileWriter.close();
|
||||||
|
|
||||||
|
meteors.set(meteors.indexOf(meteor), Pair.of(meteor.getLeft(), defaultMeteor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, register all of our meteors
|
||||||
|
for (Pair<String, Meteor> meteor : meteors)
|
||||||
|
MeteorRegistry.registerMeteor(meteor.getRight().getCatalystStack(), meteor.getRight());
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigHandler.getConfig().save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Pair<String, Meteor>> getDefaultMeteors()
|
||||||
|
{
|
||||||
|
List<Pair<String, Meteor>> holders = new ArrayList<Pair<String, Meteor>>();
|
||||||
|
|
||||||
|
// Iron
|
||||||
|
List<MeteorComponent> ironMeteorList = new ArrayList<MeteorComponent>();
|
||||||
|
ironMeteorList.add(new MeteorComponent(400, "oreIron"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(200, "oreCopper"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(140, "oreTin"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(70, "oreSilver"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(80, "oreLead"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(30, "oreGold"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(60, "oreLapis"));
|
||||||
|
ironMeteorList.add(new MeteorComponent(100, "oreRedstone"));
|
||||||
|
Meteor ironMeteor = new Meteor(new ItemStack(Blocks.IRON_BLOCK), ironMeteorList, 15, 5, 1000);
|
||||||
|
ironMeteor.setVersion(2);
|
||||||
|
holders.add(Pair.of("IronMeteor", ironMeteor));
|
||||||
|
DEFAULT_METEORS.put("IronMeteor", ironMeteor);
|
||||||
|
|
||||||
|
return holders;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,17 +6,15 @@ import java.util.Map;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
|
||||||
|
|
||||||
public class MeteorRegistry
|
public class MeteorRegistry
|
||||||
{
|
{
|
||||||
public static Map<ItemStackWrapper, MeteorHolder> meteorMap = new HashMap<ItemStackWrapper, MeteorHolder>();
|
public static Map<ItemStackWrapper, Meteor> meteorMap = new HashMap<ItemStackWrapper, Meteor>();
|
||||||
|
|
||||||
public static void registerMeteor(ItemStack stack, MeteorHolder holder)
|
public static void registerMeteor(ItemStack stack, Meteor holder)
|
||||||
{
|
{
|
||||||
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
||||||
if (wrapper != null)
|
if (wrapper != null)
|
||||||
|
@ -27,10 +25,7 @@ public class MeteorRegistry
|
||||||
|
|
||||||
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, float explosionStrength, int radius, int maxWeight)
|
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, float explosionStrength, int radius, int maxWeight)
|
||||||
{
|
{
|
||||||
ResourceLocation resource = Utils.getResourceForItem(stack);
|
Meteor holder = new Meteor(stack, componentList, explosionStrength, radius, maxWeight);
|
||||||
|
|
||||||
MeteorHolder holder = new MeteorHolder(resource, stack.getItemDamage(), componentList, explosionStrength, radius, maxWeight);
|
|
||||||
|
|
||||||
registerMeteor(stack, holder);
|
registerMeteor(stack, holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +35,7 @@ public class MeteorRegistry
|
||||||
return wrapper != null && meteorMap.containsKey(wrapper);
|
return wrapper != null && meteorMap.containsKey(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MeteorHolder getMeteorForItem(ItemStack stack)
|
public static Meteor getMeteorForItem(ItemStack stack)
|
||||||
{
|
{
|
||||||
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
||||||
return wrapper != null ? meteorMap.get(wrapper) : null;
|
return wrapper != null ? meteorMap.get(wrapper) : null;
|
||||||
|
@ -48,7 +43,7 @@ public class MeteorRegistry
|
||||||
|
|
||||||
public static void generateMeteorForItem(ItemStack stack, World world, BlockPos pos, IBlockState fillerBlock)
|
public static void generateMeteorForItem(ItemStack stack, World world, BlockPos pos, IBlockState fillerBlock)
|
||||||
{
|
{
|
||||||
MeteorHolder holder = getMeteorForItem(stack);
|
Meteor holder = getMeteorForItem(stack);
|
||||||
if (holder != null)
|
if (holder != null)
|
||||||
{
|
{
|
||||||
holder.generateMeteor(world, pos, fillerBlock);
|
holder.generateMeteor(world, pos, fillerBlock);
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
package WayofTime.bloodmagic.registry;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import WayofTime.bloodmagic.meteor.MeteorComponent;
|
|
||||||
import WayofTime.bloodmagic.meteor.MeteorHolder;
|
|
||||||
import WayofTime.bloodmagic.meteor.MeteorRegistry;
|
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
public class ModMeteors
|
|
||||||
{
|
|
||||||
public static String[] meteors = new String[] {};
|
|
||||||
|
|
||||||
public static void init()
|
|
||||||
{
|
|
||||||
Gson gson = new GsonBuilder().create();
|
|
||||||
|
|
||||||
List<String> properStrings = new ArrayList<String>();
|
|
||||||
String currentString = "";
|
|
||||||
int leftParenths = 0;
|
|
||||||
int rightParenths = 0;
|
|
||||||
|
|
||||||
for (String str : meteors)
|
|
||||||
{
|
|
||||||
currentString += str;
|
|
||||||
for (char c : str.toCharArray())
|
|
||||||
{
|
|
||||||
if (c == '{')
|
|
||||||
{
|
|
||||||
leftParenths++;
|
|
||||||
} else if (c == '}')
|
|
||||||
{
|
|
||||||
rightParenths++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftParenths == rightParenths)
|
|
||||||
{
|
|
||||||
properStrings.add(currentString);
|
|
||||||
currentString = "";
|
|
||||||
leftParenths = 0;
|
|
||||||
rightParenths = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String properString : properStrings)
|
|
||||||
{
|
|
||||||
MeteorHolder holder = gson.fromJson(properString, MeteorHolder.class);
|
|
||||||
if (holder != null)
|
|
||||||
{
|
|
||||||
MeteorRegistry.registerMeteor(holder.getKeyStack(holder.metaKey), holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getDefaultMeteors()
|
|
||||||
{
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
|
|
||||||
List<MeteorHolder> holders = new ArrayList<MeteorHolder>();
|
|
||||||
|
|
||||||
List<MeteorComponent> ironMeteorList = new ArrayList<MeteorComponent>();
|
|
||||||
ironMeteorList.add(new MeteorComponent(400, "oreIron"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(200, "oreCopper"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(140, "oreTin"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(70, "oreSilver"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(80, "oreLead"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(30, "oreGold"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(60, "oreLapis"));
|
|
||||||
ironMeteorList.add(new MeteorComponent(100, "oreRedstone"));
|
|
||||||
MeteorHolder ironMeteorHolder = new MeteorHolder(Utils.getResourceForItem(new ItemStack(Blocks.IRON_BLOCK)), 0, ironMeteorList, 15, 5, 1000);
|
|
||||||
|
|
||||||
holders.add(ironMeteorHolder);
|
|
||||||
|
|
||||||
String[] meteors = new String[holders.size()];
|
|
||||||
for (int i = 0; i < holders.size(); i++)
|
|
||||||
{
|
|
||||||
meteors[i] = gson.toJson(holders.get(i), MeteorHolder.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
return meteors;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,7 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
import WayofTime.bloodmagic.gson.Adapters;
|
import WayofTime.bloodmagic.gson.Serializers;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
@ -35,8 +35,7 @@ public class DungeonRoomLoader
|
||||||
|
|
||||||
public static void saveSingleDungeon(DungeonRoom room)
|
public static void saveSingleDungeon(DungeonRoom room)
|
||||||
{
|
{
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
String json = Serializers.GSON.toJson(room);
|
||||||
String json = gson.toJson(room);
|
|
||||||
|
|
||||||
Writer writer;
|
Writer writer;
|
||||||
try
|
try
|
||||||
|
@ -55,17 +54,15 @@ public class DungeonRoomLoader
|
||||||
|
|
||||||
public static void loadDungeons()
|
public static void loadDungeons()
|
||||||
{
|
{
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(EnumFacing.class, Adapters.adapter).create();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL schematicURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(new ResourceLocation("bloodmagic:Schematics")));
|
URL schematicURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(new ResourceLocation("bloodmagic:Schematics")));
|
||||||
List<String> schematics = gson.fromJson(Resources.toString(schematicURL, Charsets.UTF_8), new TypeToken<List<String>>(){}.getType());
|
List<String> schematics = Serializers.GSON.fromJson(Resources.toString(schematicURL, Charsets.UTF_8), new TypeToken<List<String>>(){}.getType());
|
||||||
for (String schematicKey : schematics)
|
for (String schematicKey : schematics)
|
||||||
{
|
{
|
||||||
ResourceLocation schematic = new ResourceLocation(schematicKey);
|
ResourceLocation schematic = new ResourceLocation(schematicKey);
|
||||||
URL dungeonURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(schematic));
|
URL dungeonURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(schematic));
|
||||||
DungeonRoom dungeonRoom = gson.fromJson(Resources.toString(dungeonURL, Charsets.UTF_8), DungeonRoom.class);
|
DungeonRoom dungeonRoom = Serializers.GSON.fromJson(Resources.toString(dungeonURL, Charsets.UTF_8), DungeonRoom.class);
|
||||||
DungeonRoomRegistry.registerDungeonRoom(dungeonRoom, Math.max(1, dungeonRoom.dungeonWeight));
|
DungeonRoomRegistry.registerDungeonRoom(dungeonRoom, Math.max(1, dungeonRoom.dungeonWeight));
|
||||||
}
|
}
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
|
|
Loading…
Reference in a new issue