mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-27 15:23:06 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0b4b797c8 | ||
|
|
bd584c6d52 | ||
|
|
ac50cfc691 | ||
|
|
7e607b4c58 | ||
|
|
e629d04310 |
No files matched your search
+2
-2
@@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api("com.github.GTNewHorizons:waila:1.8.2:dev")
|
api("com.github.GTNewHorizons:waila:1.8.2:dev")
|
||||||
api("com.github.GTNewHorizons:NotEnoughItems:2.7.22-GTNH:dev")
|
api("com.github.GTNewHorizons:NotEnoughItems:2.7.25-GTNH:dev")
|
||||||
|
|
||||||
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.79:dev") {transitive = false }
|
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.89:dev") {transitive = false }
|
||||||
|
|
||||||
compileOnly("com.github.GTNewHorizons:Botania:1.12.5-GTNH:api") {transitive = false }
|
compileOnly("com.github.GTNewHorizons:Botania:1.12.5-GTNH:api") {transitive = false }
|
||||||
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.1:api") {transitive = false }
|
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.1:api") {transitive = false }
|
||||||
|
|||||||
@@ -250,8 +250,8 @@ import WayofTime.alchemicalWizardry.common.spell.simple.SpellTeleport;
|
|||||||
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWateryGrave;
|
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWateryGrave;
|
||||||
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWindGust;
|
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWindGust;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.SummoningHelperAW;
|
import WayofTime.alchemicalWizardry.common.summoning.SummoningHelperAW;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.Meteor;
|
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorReagentRegistry;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorReagentRegistry;
|
||||||
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
|
||||||
import WayofTime.alchemicalWizardry.common.tileEntity.TEAlchemicCalcinator;
|
import WayofTime.alchemicalWizardry.common.tileEntity.TEAlchemicCalcinator;
|
||||||
import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar;
|
import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar;
|
||||||
import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar;
|
import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar;
|
||||||
@@ -308,6 +308,8 @@ public class AlchemicalWizardry {
|
|||||||
|
|
||||||
public static boolean parseTextFiles = false;
|
public static boolean parseTextFiles = false;
|
||||||
|
|
||||||
|
public static int defaultMeteorCost = 1000000;
|
||||||
|
public static String defaultMeteorBlock;
|
||||||
public static boolean doMeteorsDestroyBlocks = true;
|
public static boolean doMeteorsDestroyBlocks = true;
|
||||||
public static String[] allowedCrushedOresArray;
|
public static String[] allowedCrushedOresArray;
|
||||||
|
|
||||||
@@ -621,35 +623,12 @@ public class AlchemicalWizardry {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
File bmDirectory = new File("config/BloodMagic/schematics");
|
|
||||||
|
|
||||||
if (!bmDirectory.exists() && bmDirectory.mkdirs()) {
|
generateDefaultConfig(
|
||||||
try {
|
"config/BloodMagic/schematics",
|
||||||
InputStream in = AlchemicalWizardry.class
|
"/assets/alchemicalwizardry/schematics/building/buildings.zip");
|
||||||
.getResourceAsStream("/assets/alchemicalwizardry/schematics/building/buildings.zip");
|
generateDefaultConfig("config/BloodMagic/meteors", "/assets/alchemicalwizardry/meteors/meteors.zip");
|
||||||
logger.info("none yet!");
|
generateDefaultConfig("config/BloodMagic/meteors/reagents", "/assets/alchemicalwizardry/meteors/reagents.zip");
|
||||||
if (in != null) {
|
|
||||||
logger.info("I have found a zip!");
|
|
||||||
ZipInputStream zipStream = new ZipInputStream(in);
|
|
||||||
ZipEntry entry;
|
|
||||||
|
|
||||||
while ((entry = zipStream.getNextEntry()) != null) {
|
|
||||||
File file = new File(bmDirectory, entry.getName());
|
|
||||||
if (file.exists() && file.length() > 3L) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
int len;
|
|
||||||
while ((len = zipStream.read(buffer)) != -1) {
|
|
||||||
out.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEDemonPortal.loadBuildingList();
|
TEDemonPortal.loadBuildingList();
|
||||||
|
|
||||||
@@ -708,6 +687,42 @@ public class AlchemicalWizardry {
|
|||||||
ModAchievements.init();
|
ModAchievements.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to generate default configs at the given destination using a zip located at the given source.
|
||||||
|
*
|
||||||
|
* @param destination The destination path for the config, starting inside .minecraft.
|
||||||
|
* @param source The source path for the config's zip, starting in src/main/resources/
|
||||||
|
*/
|
||||||
|
private static void generateDefaultConfig(String destination, String source) {
|
||||||
|
File destinationDirectory = new File(destination);
|
||||||
|
if (!destinationDirectory.exists() && destinationDirectory.mkdirs()) {
|
||||||
|
try {
|
||||||
|
InputStream in = AlchemicalWizardry.class.getResourceAsStream(source);
|
||||||
|
logger.info("Attempting to load default config for {}", destinationDirectory);
|
||||||
|
if (in != null) {
|
||||||
|
logger.info("Unpacking zip found at {}", source);
|
||||||
|
ZipInputStream zipStream = new ZipInputStream(in);
|
||||||
|
ZipEntry entry;
|
||||||
|
|
||||||
|
while ((entry = zipStream.getNextEntry()) != null) {
|
||||||
|
File file = new File(destinationDirectory, entry.getName());
|
||||||
|
if (file.exists() && file.length() > 3L) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int len;
|
||||||
|
while ((len = zipStream.read(buffer)) != -1) {
|
||||||
|
out.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void load(FMLInitializationEvent event) {
|
public void load(FMLInitializationEvent event) {
|
||||||
int craftingConstant = OreDictionary.WILDCARD_VALUE;
|
int craftingConstant = OreDictionary.WILDCARD_VALUE;
|
||||||
@@ -3321,7 +3336,8 @@ public class AlchemicalWizardry {
|
|||||||
BloodMagicConfiguration.loadCustomLPValues();
|
BloodMagicConfiguration.loadCustomLPValues();
|
||||||
|
|
||||||
DemonVillageLootRegistry.init();
|
DemonVillageLootRegistry.init();
|
||||||
Meteor.loadConfig();
|
|
||||||
|
MeteorRegistry.loadConfig();
|
||||||
MeteorReagentRegistry.loadConfig();
|
MeteorReagentRegistry.loadConfig();
|
||||||
|
|
||||||
this.initCompressionHandlers();
|
this.initCompressionHandlers();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import WayofTime.alchemicalWizardry.common.AlchemicalWizardryEventHooks;
|
|||||||
import WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath;
|
import WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath;
|
||||||
import WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal;
|
import WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal;
|
||||||
import WayofTime.alchemicalWizardry.common.items.armour.BoundArmour;
|
import WayofTime.alchemicalWizardry.common.items.armour.BoundArmour;
|
||||||
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
@@ -102,6 +103,23 @@ public class BloodMagicConfiguration {
|
|||||||
|
|
||||||
AlchemicalWizardry.doMeteorsDestroyBlocks = config.get("meteor", "doMeteorsDestroyBlocks", true)
|
AlchemicalWizardry.doMeteorsDestroyBlocks = config.get("meteor", "doMeteorsDestroyBlocks", true)
|
||||||
.getBoolean(true);
|
.getBoolean(true);
|
||||||
|
AlchemicalWizardry.defaultMeteorCost = config.getInt(
|
||||||
|
"defaultMeteorCost",
|
||||||
|
"meteor",
|
||||||
|
1000000,
|
||||||
|
0,
|
||||||
|
Integer.MAX_VALUE,
|
||||||
|
"The default LP cost to use for meteors if the \"cost\" property is not present in its config file.\n");
|
||||||
|
AlchemicalWizardry.defaultMeteorBlock = config.getString(
|
||||||
|
"defaultMeteorBlock",
|
||||||
|
"meteor",
|
||||||
|
"",
|
||||||
|
"The block to use for filler in meteors if none is provided in the meteor's config file and "
|
||||||
|
+ "that\nmeteor's fillerChance is greater than 0. Also used as a fallback for empty ore "
|
||||||
|
+ "lists in meteor configs.\nSpecify the block with the "
|
||||||
|
+ "format:\n\"modId:itemName:meta\"\nDefaults to minecraft:stone:0 if no block is provided or "
|
||||||
|
+ "the provided block cannot be found.");
|
||||||
|
MeteorComponent.setDefaultMeteorBlock();
|
||||||
AlchemicalWizardry.allowedCrushedOresArray = config.get(
|
AlchemicalWizardry.allowedCrushedOresArray = config.get(
|
||||||
"oreCrushing",
|
"oreCrushing",
|
||||||
"allowedOres",
|
"allowedOres",
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import org.lwjgl.opengl.GL11;
|
|||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigm;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.Meteor;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigmComponent;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
|
||||||
import codechicken.lib.gui.GuiDraw;
|
import codechicken.lib.gui.GuiDraw;
|
||||||
import codechicken.nei.NEIServerUtils;
|
import codechicken.nei.NEIServerUtils;
|
||||||
@@ -38,55 +38,56 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
private final int radius;
|
private final int radius;
|
||||||
private Point focus;
|
private Point focus;
|
||||||
|
|
||||||
public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) {
|
public CachedMeteorRecipe(Meteor meteor, ItemStack focusStack) {
|
||||||
this.input.add(new PositionedStack(meteor.focusStack, 74, 4));
|
this.input.add(new PositionedStack(meteor.focusItem, 74, 4));
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
float totalComponentWeight = meteor.getTotalListWeight(meteor.componentList);
|
float totalComponentWeight = MeteorComponent.getTotalListWeight(meteor.ores);
|
||||||
int fillerChance = meteor.fillerChance;
|
float fillerChance = meteor.fillerChance;
|
||||||
List<MeteorParadigmComponent> sortedComponents = new ArrayList<>(meteor.componentList);
|
List<MeteorComponent> sortedComponents = new ArrayList<>(meteor.ores);
|
||||||
sortedComponents.sort(Comparator.comparingInt(c -> -c.getWeight()));
|
sortedComponents.sort(Comparator.comparingInt(c -> -c.getWeight()));
|
||||||
|
|
||||||
float fillerRatio = (float) (fillerChance / 100.0);
|
float fillerRatio = (float) (fillerChance / 100.0);
|
||||||
float componentRatio = 1 - fillerRatio;
|
float componentRatio = 1 - fillerRatio;
|
||||||
|
|
||||||
for (MeteorParadigmComponent component : sortedComponents) {
|
if (fillerChance < 100) {
|
||||||
ItemStack stack = component.getBlock();
|
for (MeteorComponent component : sortedComponents) {
|
||||||
int xPos = 3 + 18 * col;
|
ItemStack stack = component.getBlock();
|
||||||
int yPos = 37 + 18 * row;
|
int xPos = 3 + 18 * col;
|
||||||
|
int yPos = 37 + 18 * row;
|
||||||
|
|
||||||
List<String> tooltips = new ArrayList<>();
|
List<String> tooltips = new ArrayList<>();
|
||||||
float chance = component.getWeight() / totalComponentWeight * componentRatio;
|
float chance = component.getWeight() / totalComponentWeight * componentRatio;
|
||||||
tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(chance)));
|
tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(chance)));
|
||||||
tooltips.add(I18n.format("nei.recipe.meteor.amount", getEstimatedAmount(chance, meteor.radius)));
|
tooltips.add(I18n.format("nei.recipe.meteor.amount", getEstimatedAmount(chance, meteor.radius)));
|
||||||
if (!component.getRequiredReagents().isEmpty()) {
|
if (!component.getRequiredReagents().isEmpty()) {
|
||||||
tooltips.add(I18n.format("nei.recipe.meteor.reagent", getReagentStrings(component)));
|
tooltips.add(I18n.format("nei.recipe.meteor.reagent", getReagentStrings(component)));
|
||||||
}
|
}
|
||||||
this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips));
|
this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips));
|
||||||
|
|
||||||
col++;
|
col++;
|
||||||
if (col > 8) {
|
if (col > 8) {
|
||||||
col = 0;
|
col = 0;
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchItem(focusStack, stack)) {
|
if (matchItem(focusStack, stack)) {
|
||||||
this.focus = new Point(xPos - 1, yPos - 1);
|
this.focus = new Point(xPos - 1, yPos - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fillerChance > 0) {
|
if (fillerChance > 0) {
|
||||||
if (col != 0) {
|
if (col != 0) {
|
||||||
col = 0;
|
col = 0;
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MeteorParadigmComponent> sortedFiller = new ArrayList<>(meteor.fillerList);
|
List<MeteorComponent> sortedFiller = new ArrayList<>(meteor.filler);
|
||||||
sortedFiller.sort(Comparator.comparingInt(c -> -c.getWeight()));
|
sortedFiller.sort(Comparator.comparingInt(c -> -c.getWeight()));
|
||||||
float totalFillerWeight = meteor.getTotalListWeight(meteor.fillerList);
|
float totalFillerWeight = MeteorComponent.getTotalListWeight(meteor.filler);
|
||||||
|
|
||||||
for (MeteorParadigmComponent filler : sortedFiller) {
|
for (MeteorComponent filler : sortedFiller) {
|
||||||
ItemStack stack = filler.getBlock();
|
ItemStack stack = filler.getBlock();
|
||||||
int xPos = 3 + 18 * col;
|
int xPos = 3 + 18 * col;
|
||||||
int yPos = 37 + 18 * row;
|
int yPos = 37 + 18 * row;
|
||||||
@@ -117,7 +118,7 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
this.cost = meteor.cost;
|
this.cost = meteor.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getReagentStrings(MeteorParadigmComponent component) {
|
private String getReagentStrings(MeteorComponent component) {
|
||||||
ArrayList<Reagent> reagents = component.getRequiredReagents();
|
ArrayList<Reagent> reagents = component.getRequiredReagents();
|
||||||
ArrayList<String> reagentNames = new ArrayList<>();
|
ArrayList<String> reagentNames = new ArrayList<>();
|
||||||
for (Reagent r : reagents) {
|
for (Reagent r : reagents) {
|
||||||
@@ -158,7 +159,7 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||||
if (outputId.equals(getOverlayIdentifier()) && getClass() == NEIMeteorRecipeHandler.class) {
|
if (outputId.equals(getOverlayIdentifier()) && getClass() == NEIMeteorRecipeHandler.class) {
|
||||||
for (MeteorParadigm meteor : getSortedMeteors()) {
|
for (Meteor meteor : getSortedMeteors()) {
|
||||||
arecipes.add(new CachedMeteorRecipe(meteor, null));
|
arecipes.add(new CachedMeteorRecipe(meteor, null));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -168,11 +169,11 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadCraftingRecipes(ItemStack result) {
|
public void loadCraftingRecipes(ItemStack result) {
|
||||||
for (MeteorParadigm meteor : getSortedMeteors()) {
|
for (Meteor meteor : getSortedMeteors()) {
|
||||||
if (meteor.componentList.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
|
if (meteor.ores.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
|
||||||
arecipes.add(new CachedMeteorRecipe(meteor, result));
|
arecipes.add(new CachedMeteorRecipe(meteor, result));
|
||||||
}
|
}
|
||||||
if (meteor.fillerList.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
|
if (meteor.filler.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
|
||||||
arecipes.add(new CachedMeteorRecipe(meteor, result));
|
arecipes.add(new CachedMeteorRecipe(meteor, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,8 +181,8 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUsageRecipes(ItemStack ingredient) {
|
public void loadUsageRecipes(ItemStack ingredient) {
|
||||||
for (MeteorParadigm meteor : getSortedMeteors()) {
|
for (Meteor meteor : getSortedMeteors()) {
|
||||||
if (matchItem(ingredient, meteor.focusStack)) {
|
if (matchItem(ingredient, meteor.focusItem)) {
|
||||||
arecipes.add(new CachedMeteorRecipe(meteor, null));
|
arecipes.add(new CachedMeteorRecipe(meteor, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,8 +256,8 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
|||||||
return I18n.format("nei.recipe.meteor.category");
|
return I18n.format("nei.recipe.meteor.category");
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MeteorParadigm> getSortedMeteors() {
|
private List<Meteor> getSortedMeteors() {
|
||||||
return MeteorRegistry.paradigmList.stream().sorted(Comparator.comparing(m -> m.cost))
|
return MeteorRegistry.meteorList.stream().sorted(Comparator.comparing(m -> m.cost))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -44,9 +44,9 @@ public class RitualEffectSummonMeteor extends RitualEffect {
|
|||||||
if (entities == null) return;
|
if (entities == null) return;
|
||||||
|
|
||||||
for (EntityItem entityItem : entities) {
|
for (EntityItem entityItem : entities) {
|
||||||
if (entityItem != null && MeteorRegistry.isValidParadigmItem(entityItem.getEntityItem())) {
|
if (entityItem != null && MeteorRegistry.isValidMeteorFocusItem(entityItem.getEntityItem())) {
|
||||||
int meteorID = MeteorRegistry.getParadigmIDForItem(entityItem.getEntityItem());
|
int meteorID = MeteorRegistry.getMeteorIDForItem(entityItem.getEntityItem());
|
||||||
int cost = MeteorRegistry.paradigmList.get(meteorID).cost;
|
int cost = MeteorRegistry.meteorList.get(meteorID).cost;
|
||||||
|
|
||||||
if (currentEssence < cost) {
|
if (currentEssence < cost) {
|
||||||
EntityPlayer entityOwner = SpellHelper.getPlayerForUsername(owner);
|
EntityPlayer entityOwner = SpellHelper.getPlayerForUsername(owner);
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
|
class ItemStackAdapter extends TypeAdapter<ItemStack> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack read(JsonReader reader) throws IOException {
|
||||||
|
String str = reader.nextString();
|
||||||
|
String[] input = str.split(":");
|
||||||
|
if (input.length < 2) {
|
||||||
|
AlchemicalWizardry.logger
|
||||||
|
.warn("Unable to read item stack \"{}\". Valid format is \"modid:name(:meta optional)\"", str);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemStack itemStack = GameRegistry.findItemStack(input[0], input[1], 1);
|
||||||
|
if (itemStack == null) {
|
||||||
|
AlchemicalWizardry.logger.warn("Unable to find item stack \"{}\".", str);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (input.length < 3) {
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
itemStack.setItemDamage(Integer.parseInt(input[2]));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
AlchemicalWizardry.logger
|
||||||
|
.warn("Invalid metadata value {} for item stack {}:{}", input[2], input[0], input[1]);
|
||||||
|
}
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter writer, ItemStack mpc) throws IOException {
|
||||||
|
// Not implemented because it is not needed.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,60 +1,238 @@
|
|||||||
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import static WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent.defaultMeteorBlock;
|
||||||
import java.io.File;
|
import static WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent.getTotalListWeight;
|
||||||
import java.io.FileNotFoundException;
|
import static WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorReagentRegistry.getFillerList;
|
||||||
import java.io.FileReader;
|
|
||||||
|
|
||||||
import net.minecraft.init.Items;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
import com.google.gson.GsonBuilder;
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import cpw.mods.fml.common.Optional;
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
import gregtech.common.blocks.TileEntityOres;
|
||||||
|
|
||||||
public class Meteor {
|
public class Meteor {
|
||||||
|
|
||||||
public String[] ores;
|
public List<MeteorComponent> ores;
|
||||||
|
public List<MeteorComponent> filler;
|
||||||
public int radius;
|
public int radius;
|
||||||
public int cost;
|
public int cost;
|
||||||
public String focusModId;
|
public float fillerChance; // Out of 100.0
|
||||||
public String focusName;
|
public ItemStack focusItem;
|
||||||
public int focusMeta;
|
private String focusModId;
|
||||||
private String[] filler;
|
private String focusName;
|
||||||
private int fillerChance;
|
private int focusMeta;
|
||||||
|
private int maxWeight;
|
||||||
|
|
||||||
public static void loadConfig() {
|
public static Random rand = new Random();
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
File file = new File("config/BloodMagic/meteors");
|
public Meteor() {
|
||||||
File[] files = file.listFiles();
|
this.radius = 1;
|
||||||
if (files != null) {
|
this.cost = AlchemicalWizardry.defaultMeteorCost;
|
||||||
try {
|
this.fillerChance = 0;
|
||||||
for (File f : files) {
|
this.maxWeight = 0;
|
||||||
if (f.isDirectory()) {
|
this.preventNullLists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Meteor(ItemStack focusStack, int radius, int cost, int fillerChance, List<MeteorComponent> oreList,
|
||||||
|
List<MeteorComponent> fillerList) {
|
||||||
|
this.focusItem = focusStack;
|
||||||
|
this.radius = radius;
|
||||||
|
this.cost = cost;
|
||||||
|
this.fillerChance = fillerChance;
|
||||||
|
this.ores = oreList;
|
||||||
|
this.filler = fillerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createMeteorImpact(World world, int x, int y, int z, List<Reagent> reagents) {
|
||||||
|
int radius = getNewRadius(this.radius, reagents);
|
||||||
|
float fillerChance = getNewFillerChance(this.fillerChance, reagents);
|
||||||
|
|
||||||
|
if (MeteorReagentRegistry.doExplosions(reagents)) {
|
||||||
|
world.createExplosion(null, x, y, z, radius * 4, MeteorReagentRegistry.doMeteorsDestroyBlocks(reagents));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MeteorComponent> oreList = removeBlocksMissingRequiredReagents(this.ores, reagents);
|
||||||
|
List<MeteorComponent> fillerList = getNewFillerList(this.filler, reagents);
|
||||||
|
|
||||||
|
int totalComponentWeight = MeteorComponent.getTotalListWeight(oreList);
|
||||||
|
int totalFillerWeight = MeteorComponent.getTotalListWeight(fillerList);
|
||||||
|
|
||||||
|
for (int i = -radius; i <= radius; i++) {
|
||||||
|
for (int j = -radius; j <= radius; j++) {
|
||||||
|
for (int k = -radius; k <= radius; k++) {
|
||||||
|
if (i * i + j * j + k * k >= (radius + 0.50f) * (radius + 0.50f)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BufferedReader br = new BufferedReader(new FileReader(f));
|
|
||||||
Meteor m = gson.fromJson(br, Meteor.class);
|
if (!world.isAirBlock(x + i, y + j, z + k)) {
|
||||||
MeteorRegistry.registerMeteorParadigm(
|
continue;
|
||||||
findItemStack(m.focusModId, m.focusName, m.focusMeta),
|
}
|
||||||
m.ores,
|
|
||||||
m.radius,
|
if (fillerChance < 100 && (fillerChance <= 0 || world.rand.nextFloat() * 100 >= fillerChance)) {
|
||||||
m.cost,
|
setMeteorBlock(x + i, y + j, z + k, world, oreList, totalComponentWeight);
|
||||||
m.filler,
|
} else {
|
||||||
m.fillerChance);
|
setMeteorBlock(x + i, y + j, z + k, world, fillerList, totalFillerWeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException | JsonSyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack findItemStack(String modid, String name, int meta) {
|
private int getNewRadius(int radius, List<Reagent> reagents) {
|
||||||
ItemStack is = GameRegistry.findItemStack(modid, name, 1);
|
radius += MeteorReagentRegistry.getLargestRadiusIncrease(reagents);
|
||||||
if (is == null) return null;
|
radius += MeteorReagentRegistry.getLargestRadiusDecrease(reagents);
|
||||||
Items.feather.setDamage(is, meta);
|
return Math.max(radius, 1);
|
||||||
return is;
|
}
|
||||||
|
|
||||||
|
private float getNewFillerChance(float fillerChance, List<Reagent> reagents) {
|
||||||
|
// Don't add filler to meteors that have none
|
||||||
|
if (fillerChance <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float increase = MeteorReagentRegistry.getLargestFillerChanceIncrease(reagents);
|
||||||
|
float decrease = MeteorReagentRegistry.getLargestFillerChanceDecrease(reagents);
|
||||||
|
// Avoid division by zero
|
||||||
|
if (decrease == -100) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fillerChance += MeteorReagentRegistry.getLargestRawFillerChanceIncrease(reagents);
|
||||||
|
fillerChance += MeteorReagentRegistry.getLargestRawFillerChanceDecrease(reagents);
|
||||||
|
if (increase > 0) {
|
||||||
|
fillerChance = 100 * (fillerChance + increase) / (100 + increase);
|
||||||
|
} else if (decrease < 0) {
|
||||||
|
fillerChance = 100 * (fillerChance + decrease) / (100 + decrease);
|
||||||
|
}
|
||||||
|
return Math.max(0, Math.min(fillerChance, 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a new filler list. The original list is entirely replaced if any of the supplied reagents have a filler
|
||||||
|
* config.
|
||||||
|
*/
|
||||||
|
private List<MeteorComponent> getNewFillerList(List<MeteorComponent> fillerList, List<Reagent> reagents) {
|
||||||
|
List<MeteorComponent> reagentFillers = getFillerList(reagents);
|
||||||
|
reagentFillers = removeBlocksMissingRequiredReagents(reagentFillers, reagents);
|
||||||
|
if (!reagentFillers.isEmpty() && reagentFillers.get(0) != defaultMeteorBlock) {
|
||||||
|
return reagentFillers;
|
||||||
|
}
|
||||||
|
return removeBlocksMissingRequiredReagents(fillerList, reagents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MeteorComponent> removeBlocksMissingRequiredReagents(List<MeteorComponent> blockList,
|
||||||
|
List<Reagent> reagents) {
|
||||||
|
ArrayList<MeteorComponent> newList = new ArrayList<>();
|
||||||
|
for (MeteorComponent component : blockList) {
|
||||||
|
if (component.checkForReagent(reagents)) {
|
||||||
|
newList.add(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newList.isEmpty()) { // Use the default if every filler requires a reagent
|
||||||
|
newList.add(defaultMeteorBlock);
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a randomly chosen block from blocklist according to the MeteorComponent weights at position x, y, z in the
|
||||||
|
* provided world.
|
||||||
|
*/
|
||||||
|
private void setMeteorBlock(int x, int y, int z, World world, List<MeteorComponent> blockList,
|
||||||
|
int totalListWeight) {
|
||||||
|
int randNum = world.rand.nextInt(totalListWeight);
|
||||||
|
for (MeteorComponent component : blockList) {
|
||||||
|
randNum -= component.getWeight();
|
||||||
|
|
||||||
|
if (randNum < 0) {
|
||||||
|
ItemStack blockStack = component.getBlock();
|
||||||
|
if (blockStack != null && blockStack.getItem() instanceof ItemBlock) {
|
||||||
|
((ItemBlock) blockStack.getItem())
|
||||||
|
.placeBlockAt(blockStack, null, world, x, y, z, 0, 0, 0, 0, blockStack.getItemDamage());
|
||||||
|
if (AlchemicalWizardry.isGregTechLoaded) setGTOresNaturalIfNeeded(world, x, y, z);
|
||||||
|
world.markBlockForUpdate(x, y, z);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validate() {
|
||||||
|
this.preventNullLists();
|
||||||
|
this.clampNumericalValues();
|
||||||
|
this.buildFocusItem();
|
||||||
|
this.maxWeightToFillerChance();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preventNullLists() {
|
||||||
|
if (ores == null || ores.isEmpty()) {
|
||||||
|
ores = new ArrayList<>();
|
||||||
|
ores.add(defaultMeteorBlock);
|
||||||
|
}
|
||||||
|
while (ores.contains(null)) {
|
||||||
|
ores.remove(null);
|
||||||
|
}
|
||||||
|
if (filler == null || filler.isEmpty()) {
|
||||||
|
filler = new ArrayList<>();
|
||||||
|
filler.add(defaultMeteorBlock);
|
||||||
|
}
|
||||||
|
while (filler.contains(null)) {
|
||||||
|
filler.remove(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clamps all numerical values to their minimum/maximum values.
|
||||||
|
*/
|
||||||
|
private void clampNumericalValues() {
|
||||||
|
radius = Math.max(1, radius);
|
||||||
|
cost = Math.max(0, cost);
|
||||||
|
fillerChance = Math.max(0f, Math.min(fillerChance, 100.0f));
|
||||||
|
focusMeta = Math.max(0, focusMeta);
|
||||||
|
maxWeight = Math.max(0, maxWeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the focus item for this meteor from its modid, name, and metadata if using the old config format.
|
||||||
|
*/
|
||||||
|
private void buildFocusItem() {
|
||||||
|
if (this.focusItem != null) return;
|
||||||
|
this.focusItem = GameRegistry.findItemStack(this.focusModId, this.focusName, 1);
|
||||||
|
if (this.focusItem == null) return;
|
||||||
|
this.focusItem.setItemDamage(this.focusMeta);
|
||||||
|
AlchemicalWizardry.logger.warn(
|
||||||
|
"Setting focusModId, focusName, and focusMeta individually in meteor"
|
||||||
|
+ "configs has been deprecated. Set \"focusItem\" with format \"modId:name(:meta optional)\""
|
||||||
|
+ " instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn the maximum weight into an equivalent filler chance based on the provided block list. Does NOT restrict
|
||||||
|
* blocks over the max weight like the old weight system! Specify required reagents for the blocks you want to
|
||||||
|
* restrict in the ores tag for the meteor's config instead! This is used for the default meteors which include
|
||||||
|
* certain ores which may not be present in all environments.
|
||||||
|
*/
|
||||||
|
private void maxWeightToFillerChance() {
|
||||||
|
if (maxWeight <= 0 || fillerChance > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.fillerChance = Math.max(0f, Math.min(100f * (1 - ((float) getTotalListWeight(ores) / maxWeight)), 100.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Optional.Method(modid = "gregtech")
|
||||||
|
private static void setGTOresNaturalIfNeeded(World world, int x, int y, int z) {
|
||||||
|
final TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||||
|
if (tileEntity instanceof TileEntityOres) {
|
||||||
|
((TileEntityOres) tileEntity).mNatural = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
|
public class MeteorComponent {
|
||||||
|
|
||||||
|
private final int weight;
|
||||||
|
private final ItemStack itemStack;
|
||||||
|
private final ArrayList<Reagent> reagent;
|
||||||
|
public static MeteorComponent defaultMeteorBlock;
|
||||||
|
|
||||||
|
public static void setDefaultMeteorBlock() {
|
||||||
|
String string = AlchemicalWizardry.defaultMeteorBlock;
|
||||||
|
String[] split = string.split(":");
|
||||||
|
ItemStack stack = null;
|
||||||
|
if (!string.isEmpty() && split.length >= 3) {
|
||||||
|
stack = GameRegistry.findItemStack(split[0], split[1], 1);
|
||||||
|
}
|
||||||
|
if (stack != null) {
|
||||||
|
Items.feather.setDamage(stack, Integer.parseInt(split[2]));
|
||||||
|
} else {
|
||||||
|
stack = new ItemStack(Blocks.stone);
|
||||||
|
}
|
||||||
|
defaultMeteorBlock = new MeteorComponent(stack, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeteorComponent(ItemStack stack, int weight) {
|
||||||
|
this(stack, weight, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeteorComponent(ItemStack stack, int weight, ArrayList<Reagent> reagent) {
|
||||||
|
this.itemStack = stack;
|
||||||
|
this.weight = weight;
|
||||||
|
this.reagent = reagent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<MeteorComponent> parseStringArray(String[] blockArray) {
|
||||||
|
List<MeteorComponent> addList = new ArrayList<>();
|
||||||
|
if (blockArray == null) {
|
||||||
|
return addList;
|
||||||
|
}
|
||||||
|
for (String blockName : blockArray) {
|
||||||
|
MeteorComponent component = parseString(blockName);
|
||||||
|
if (component != null) {
|
||||||
|
addList.add(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return addList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// modId:itemName:meta:weight(:reagent1, reagent2, ... optional)
|
||||||
|
private static final Pattern itemNamePattern = Pattern.compile("(.*):(.*):(\\d+):(\\d+)(:.*)?");
|
||||||
|
// OREDICT:oreDictName:weight(:reagent1, reagent2, ... optional)
|
||||||
|
private static final Pattern oredictPattern = Pattern.compile("OREDICT:(.*):(\\d+)(:.*)?");
|
||||||
|
|
||||||
|
public static MeteorComponent parseString(String blockName) {
|
||||||
|
Matcher matcher = itemNamePattern.matcher(blockName);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
String modID = matcher.group(1);
|
||||||
|
String itemName = matcher.group(2);
|
||||||
|
int meta = Integer.parseInt(matcher.group(3));
|
||||||
|
int weight = Integer.parseInt(matcher.group(4));
|
||||||
|
String reagent = matcher.group(5);
|
||||||
|
|
||||||
|
ArrayList<Reagent> reagentList = MeteorReagent.parseReagents(reagent, blockName);
|
||||||
|
|
||||||
|
ItemStack stack = GameRegistry.findItemStack(modID, itemName, 1);
|
||||||
|
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
||||||
|
stack.setItemDamage(meta);
|
||||||
|
return new MeteorComponent(stack, weight, reagentList);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ((matcher = oredictPattern.matcher(blockName)).matches()) {
|
||||||
|
String oreDict = matcher.group(1);
|
||||||
|
int weight = Integer.parseInt(matcher.group(2));
|
||||||
|
String reagent = matcher.group(3);
|
||||||
|
|
||||||
|
ArrayList<Reagent> reagentList = MeteorReagent.parseReagents(reagent, blockName);
|
||||||
|
|
||||||
|
List<ItemStack> list = OreDictionary.getOres(oreDict);
|
||||||
|
for (ItemStack stack : list) {
|
||||||
|
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
||||||
|
return new MeteorComponent(stack, weight, reagentList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
AlchemicalWizardry.logger.warn("Unable to add Meteor Component \"{}\"", blockName);
|
||||||
|
AlchemicalWizardry.logger.warn(
|
||||||
|
"Valid formats are \"modId:itemName:meta:weight(:reagent1, reagent2, ... optional)\" and \"OREDICT:oreDictName:weight(:reagent1, reagent2, ... optional)\".");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return this.weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTotalListWeight(List<MeteorComponent> blockList) {
|
||||||
|
int totalWeight = 0;
|
||||||
|
for (MeteorComponent component : blockList) {
|
||||||
|
totalWeight += component.getWeight();
|
||||||
|
}
|
||||||
|
return totalWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getBlock() {
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Reagent> getRequiredReagents() {
|
||||||
|
return reagent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkForReagent(List<Reagent> reagentList) {
|
||||||
|
if (reagent.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (Reagent r1 : reagentList) {
|
||||||
|
for (Reagent r2 : reagent) {
|
||||||
|
if (r1.equals(r2)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
class MeteorComponentAdapter extends TypeAdapter<MeteorComponent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MeteorComponent read(JsonReader reader) throws IOException {
|
||||||
|
return MeteorComponent.parseString(reader.nextString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter writer, MeteorComponent component) throws IOException {
|
||||||
|
// Not implemented because it is not needed.
|
||||||
|
}
|
||||||
|
}
|
||||||
-236
@@ -1,236 +0,0 @@
|
|||||||
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
|
||||||
|
|
||||||
import static WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorReagentRegistry.getFillerList;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
|
||||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
|
||||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
|
|
||||||
import cpw.mods.fml.common.Optional;
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
import gregtech.common.blocks.TileEntityOres;
|
|
||||||
|
|
||||||
public class MeteorParadigm {
|
|
||||||
|
|
||||||
public List<MeteorParadigmComponent> componentList = new ArrayList<>();
|
|
||||||
public List<MeteorParadigmComponent> fillerList = new ArrayList<>();
|
|
||||||
public ItemStack focusStack;
|
|
||||||
public int radius;
|
|
||||||
public int cost;
|
|
||||||
public int fillerChance; // Out of 100
|
|
||||||
|
|
||||||
public static Random rand = new Random();
|
|
||||||
|
|
||||||
public MeteorParadigm(ItemStack focusStack, int radius, int cost, int fillerChance) {
|
|
||||||
this.focusStack = focusStack;
|
|
||||||
this.radius = radius;
|
|
||||||
this.cost = cost;
|
|
||||||
this.fillerChance = fillerChance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// modId:itemName:meta:weight(:reagent1, reagent2, ... optional)
|
|
||||||
private static final Pattern itemNamePattern = Pattern.compile("(.*):(.*):(\\d+):(\\d+)(:.*)?");
|
|
||||||
// OREDICT:oreDictName:weight(:reagent1, reagent2, ... optional)
|
|
||||||
private static final Pattern oredictPattern = Pattern.compile("OREDICT:(.*):(\\d+)(:.*)?");
|
|
||||||
|
|
||||||
public static List<MeteorParadigmComponent> parseStringArray(String[] blockArray) {
|
|
||||||
List<MeteorParadigmComponent> addList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < blockArray.length; ++i) {
|
|
||||||
String blockName = blockArray[i];
|
|
||||||
boolean success = false;
|
|
||||||
|
|
||||||
Matcher matcher = itemNamePattern.matcher(blockName);
|
|
||||||
if (matcher.matches()) {
|
|
||||||
String modID = matcher.group(1);
|
|
||||||
String itemName = matcher.group(2);
|
|
||||||
int meta = Integer.parseInt(matcher.group(3));
|
|
||||||
int weight = Integer.parseInt(matcher.group(4));
|
|
||||||
String reagent = matcher.group(5);
|
|
||||||
|
|
||||||
ArrayList<Reagent> reagentList = getReagents(reagent, blockName);
|
|
||||||
|
|
||||||
ItemStack stack = GameRegistry.findItemStack(modID, itemName, 1);
|
|
||||||
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
|
||||||
stack.setItemDamage(meta);
|
|
||||||
addList.add(new MeteorParadigmComponent(stack, weight, reagentList));
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if ((matcher = oredictPattern.matcher(blockName)).matches()) {
|
|
||||||
String oreDict = matcher.group(1);
|
|
||||||
int weight = Integer.parseInt(matcher.group(2));
|
|
||||||
String reagent = matcher.group(3);
|
|
||||||
|
|
||||||
ArrayList<Reagent> reagentList = getReagents(reagent, blockName);
|
|
||||||
|
|
||||||
List<ItemStack> list = OreDictionary.getOres(oreDict);
|
|
||||||
for (ItemStack stack : list) {
|
|
||||||
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
|
||||||
addList.add(new MeteorParadigmComponent(stack, weight, reagentList));
|
|
||||||
success = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
AlchemicalWizardry.logger.warn("Unable to add Meteor Paradigm \"{}\"", blockName);
|
|
||||||
AlchemicalWizardry.logger.warn(
|
|
||||||
"Valid formats are \"modId:itemName:meta:weight(:reagent1, reagent2, ... optional)\" and \"OREDICT:oreDictName:weight(:reagent1, reagent2, ... optional)\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return addList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ArrayList<Reagent> getReagents(String reagent, String blockName) {
|
|
||||||
ArrayList<Reagent> reagentList = new ArrayList<>();
|
|
||||||
if (reagent != null) {
|
|
||||||
String[] reagents = reagent.substring(1).split(", ?");
|
|
||||||
for (String str : reagents) {
|
|
||||||
Reagent r = ReagentRegistry.getReagentForKey(str);
|
|
||||||
if (r == null) {
|
|
||||||
AlchemicalWizardry.logger.warn("Unable to add reagent \"{}\" for {}.", str, blockName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
reagentList.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return reagentList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalListWeight(List<MeteorParadigmComponent> blockList) {
|
|
||||||
int totalWeight = 0;
|
|
||||||
for (MeteorParadigmComponent mpc : blockList) {
|
|
||||||
totalWeight += mpc.getWeight();
|
|
||||||
}
|
|
||||||
return totalWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createMeteorImpact(World world, int x, int y, int z, List<Reagent> reagents) {
|
|
||||||
int radius = getNewRadius(this.radius, reagents);
|
|
||||||
int fillerChance = getNewFillerChance(this.fillerChance, reagents);
|
|
||||||
|
|
||||||
if (MeteorReagentRegistry.doExplosions(reagents)) {
|
|
||||||
world.createExplosion(null, x, y, z, radius * 4, MeteorReagentRegistry.doMeteorsDestroyBlocks(reagents));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MeteorParadigmComponent> componentList = removeBlocksMissingRequiredReagents(this.componentList, reagents);
|
|
||||||
List<MeteorParadigmComponent> fillerList = getNewFillerList(this.fillerList, reagents);
|
|
||||||
|
|
||||||
int totalComponentWeight = getTotalListWeight(componentList);
|
|
||||||
int totalFillerWeight = getTotalListWeight(fillerList);
|
|
||||||
|
|
||||||
for (int i = -radius; i <= radius; i++) {
|
|
||||||
for (int j = -radius; j <= radius; j++) {
|
|
||||||
for (int k = -radius; k <= radius; k++) {
|
|
||||||
if (i * i + j * j + k * k >= (radius + 0.50f) * (radius + 0.50f)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!world.isAirBlock(x + i, y + j, z + k)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fillerChance <= 0 || world.rand.nextInt(100) >= fillerChance) {
|
|
||||||
setMeteorBlock(x + i, y + j, z + k, world, componentList, totalComponentWeight);
|
|
||||||
} else {
|
|
||||||
setMeteorBlock(x + i, y + j, z + k, world, fillerList, totalFillerWeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNewRadius(int radius, List<Reagent> reagents) {
|
|
||||||
radius += MeteorReagentRegistry.getLargestRadiusIncrease(reagents);
|
|
||||||
radius += MeteorReagentRegistry.getLargestRadiusDecrease(reagents);
|
|
||||||
return Math.max(radius, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNewFillerChance(int fillerChance, List<Reagent> reagents) {
|
|
||||||
// Don't add filler to meteors with none
|
|
||||||
if (fillerChance <= 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int increase = MeteorReagentRegistry.getLargestFillerChanceIncrease(reagents);
|
|
||||||
int decrease = MeteorReagentRegistry.getLargestFillerChanceDecrease(reagents);
|
|
||||||
// Avoid division by zero
|
|
||||||
if (decrease == -100) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fillerChance += MeteorReagentRegistry.getLargestRawFillerChanceIncrease(reagents);
|
|
||||||
fillerChance += MeteorReagentRegistry.getLargestRawFillerChanceDecrease(reagents);
|
|
||||||
if (increase > 0) {
|
|
||||||
fillerChance = (fillerChance + increase) * 100 / (100 + increase);
|
|
||||||
} else if (decrease < 0) {
|
|
||||||
fillerChance = (fillerChance + decrease) * 100 / (100 + decrease);
|
|
||||||
}
|
|
||||||
return Math.max(0, Math.min(fillerChance, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MeteorParadigmComponent> getNewFillerList(List<MeteorParadigmComponent> fillerList,
|
|
||||||
List<Reagent> reagents) {
|
|
||||||
List<MeteorParadigmComponent> reagentFillers = getFillerList(reagents);
|
|
||||||
reagentFillers = removeBlocksMissingRequiredReagents(reagentFillers, reagents);
|
|
||||||
if (!reagentFillers.isEmpty()) {
|
|
||||||
return reagentFillers;
|
|
||||||
}
|
|
||||||
List<MeteorParadigmComponent> newFillers = removeBlocksMissingRequiredReagents(fillerList, reagents);
|
|
||||||
if (newFillers.isEmpty()) { // Use the default if every filler requires a reagent
|
|
||||||
newFillers.add(MeteorRegistry.getDefaultMeteorParadigmComponent());
|
|
||||||
}
|
|
||||||
return newFillers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MeteorParadigmComponent> removeBlocksMissingRequiredReagents(List<MeteorParadigmComponent> blockList,
|
|
||||||
List<Reagent> reagents) {
|
|
||||||
ArrayList<MeteorParadigmComponent> newList = new ArrayList<>();
|
|
||||||
for (MeteorParadigmComponent mpc : blockList) {
|
|
||||||
if (mpc.checkForReagent(reagents)) {
|
|
||||||
newList.add(mpc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMeteorBlock(int x, int y, int z, World world, List<MeteorParadigmComponent> blockList,
|
|
||||||
int totalListWeight) {
|
|
||||||
int randNum = world.rand.nextInt(totalListWeight);
|
|
||||||
for (MeteorParadigmComponent mpc : blockList) {
|
|
||||||
randNum -= mpc.getWeight();
|
|
||||||
|
|
||||||
if (randNum < 0) {
|
|
||||||
ItemStack blockStack = mpc.getBlock();
|
|
||||||
if (blockStack != null && blockStack.getItem() instanceof ItemBlock) {
|
|
||||||
((ItemBlock) blockStack.getItem())
|
|
||||||
.placeBlockAt(blockStack, null, world, x, y, z, 0, 0, 0, 0, blockStack.getItemDamage());
|
|
||||||
if (AlchemicalWizardry.isGregTechLoaded) setGTOresNaturalIfNeeded(world, x, y, z);
|
|
||||||
world.markBlockForUpdate(x, y, z);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Optional.Method(modid = "gregtech")
|
|
||||||
private static void setGTOresNaturalIfNeeded(World world, int x, int y, int z) {
|
|
||||||
final TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
||||||
if (tileEntity instanceof TileEntityOres) {
|
|
||||||
((TileEntityOres) tileEntity).mNatural = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
|
||||||
|
|
||||||
public class MeteorParadigmComponent {
|
|
||||||
|
|
||||||
protected int weight;
|
|
||||||
protected ItemStack itemStack;
|
|
||||||
protected ArrayList<Reagent> reagent = new ArrayList<>();
|
|
||||||
|
|
||||||
public MeteorParadigmComponent(ItemStack stack, int weight) {
|
|
||||||
this(stack, weight, new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MeteorParadigmComponent(ItemStack stack, int weight, ArrayList<Reagent> reagent) {
|
|
||||||
this.itemStack = stack;
|
|
||||||
this.weight = weight;
|
|
||||||
this.reagent = reagent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWeight() {
|
|
||||||
return this.weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getBlock() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Reagent> getRequiredReagents() {
|
|
||||||
return reagent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkForReagent(List<Reagent> reagentList) {
|
|
||||||
if (reagent.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (Reagent r1 : reagentList) {
|
|
||||||
for (Reagent r2 : reagent) {
|
|
||||||
if (r1.equals(r2)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+21
-3
@@ -3,14 +3,32 @@ package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
||||||
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
|
||||||
|
|
||||||
public class MeteorReagent {
|
public class MeteorReagent {
|
||||||
|
|
||||||
public boolean disableExplosions = false;
|
public boolean disableExplosions = false;
|
||||||
public boolean invertExplosionBlockDamage = false;
|
public boolean invertExplosionBlockDamage = false;
|
||||||
public int radiusChange = 0;
|
public int radiusChange = 0;
|
||||||
public int fillerChanceChange = 0;
|
public int fillerChanceChange = 0;
|
||||||
public int rawFillerChanceChange = 0;
|
public float rawFillerChanceChange = 0;
|
||||||
public String[] filler = {};
|
public List<MeteorComponent> filler = new ArrayList<>();
|
||||||
public List<MeteorParadigmComponent> parsedFiller = new ArrayList<>();
|
|
||||||
|
|
||||||
|
public static ArrayList<Reagent> parseReagents(String reagent, String blockName) {
|
||||||
|
ArrayList<Reagent> reagentList = new ArrayList<>();
|
||||||
|
if (reagent != null) {
|
||||||
|
String[] reagents = reagent.substring(1).split(", ?");
|
||||||
|
for (String str : reagents) {
|
||||||
|
Reagent r = ReagentRegistry.getReagentForKey(str);
|
||||||
|
if (r == null) {
|
||||||
|
AlchemicalWizardry.logger.warn("Unable to add reagent \"{}\" for {}.", str, blockName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
reagentList.add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reagentList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+43
-62
@@ -6,13 +6,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
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;
|
||||||
@@ -30,15 +24,13 @@ public class MeteorReagentRegistry {
|
|||||||
public static Map<Reagent, MeteorReagent> reagents = new HashMap<>();
|
public static Map<Reagent, MeteorReagent> reagents = new HashMap<>();
|
||||||
|
|
||||||
public static void loadConfig() {
|
public static void loadConfig() {
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting()
|
||||||
|
.registerTypeAdapter(MeteorComponent.class, new MeteorComponentAdapter()).create();
|
||||||
File file = new File("config/BloodMagic/meteors/reagents/");
|
File file = new File("config/BloodMagic/meteors/reagents/");
|
||||||
if (!file.isDirectory()) {
|
|
||||||
MeteorReagentRegistry.generateDefaultConfig();
|
|
||||||
}
|
|
||||||
File[] files = file.listFiles();
|
File[] files = file.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
try {
|
for (String reagent : reagentList.keySet()) {
|
||||||
for (String reagent : reagentList.keySet()) {
|
try {
|
||||||
File f = new File("config/BloodMagic/meteors/reagents/" + reagent + ".json");
|
File f = new File("config/BloodMagic/meteors/reagents/" + reagent + ".json");
|
||||||
if (!f.isFile()) {
|
if (!f.isFile()) {
|
||||||
continue;
|
continue;
|
||||||
@@ -48,18 +40,18 @@ public class MeteorReagentRegistry {
|
|||||||
if (r == null) {
|
if (r == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (r.filler.length > 0) {
|
|
||||||
r.parsedFiller = MeteorParadigm.parseStringArray(r.filler);
|
|
||||||
}
|
|
||||||
reagents.put(ReagentRegistry.getReagentForKey(reagent), r);
|
reagents.put(ReagentRegistry.getReagentForKey(reagent), r);
|
||||||
|
} catch (FileNotFoundException | JsonSyntaxException e) {
|
||||||
|
AlchemicalWizardry.logger.warn("Error adding reagent {}", reagent);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException | JsonSyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest radius increase (positive config).
|
/**
|
||||||
|
* @return the one largest radius increase from all given reagents (positive value in config).
|
||||||
|
*/
|
||||||
public static int getLargestRadiusIncrease(List<Reagent> reagentList) {
|
public static int getLargestRadiusIncrease(List<Reagent> reagentList) {
|
||||||
int increase = 0;
|
int increase = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
@@ -74,7 +66,9 @@ public class MeteorReagentRegistry {
|
|||||||
return increase;
|
return increase;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest radius decrease (negative config).
|
/**
|
||||||
|
* @return the one largest radius decrease from all given reagents (negative value in config).
|
||||||
|
*/
|
||||||
public static int getLargestRadiusDecrease(List<Reagent> reagentList) {
|
public static int getLargestRadiusDecrease(List<Reagent> reagentList) {
|
||||||
int decrease = 0;
|
int decrease = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
@@ -89,7 +83,9 @@ public class MeteorReagentRegistry {
|
|||||||
return decrease;
|
return decrease;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest filler chance increase (positive config).
|
/**
|
||||||
|
* @return the one largest filler chance increase from all given reagents (positive value in config).
|
||||||
|
*/
|
||||||
public static int getLargestFillerChanceIncrease(List<Reagent> reagentList) {
|
public static int getLargestFillerChanceIncrease(List<Reagent> reagentList) {
|
||||||
int increase = 0;
|
int increase = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
@@ -104,7 +100,9 @@ public class MeteorReagentRegistry {
|
|||||||
return increase;
|
return increase;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest filler chance decrease (negative config).
|
/**
|
||||||
|
* @return the one largest filler chance decrease from all given reagents (negative value in config).
|
||||||
|
*/
|
||||||
public static int getLargestFillerChanceDecrease(List<Reagent> reagentList) {
|
public static int getLargestFillerChanceDecrease(List<Reagent> reagentList) {
|
||||||
int decrease = 0;
|
int decrease = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
@@ -119,14 +117,16 @@ public class MeteorReagentRegistry {
|
|||||||
return decrease;
|
return decrease;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest raw filler chance increase (positive config).
|
/**
|
||||||
public static int getLargestRawFillerChanceIncrease(List<Reagent> reagentList) {
|
* @return the one largest raw filler chance increase from all given reagents (positive value in config).
|
||||||
int increase = 0;
|
*/
|
||||||
|
public static float getLargestRawFillerChanceIncrease(List<Reagent> reagentList) {
|
||||||
|
float increase = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
if (!reagents.containsKey(r)) {
|
if (!reagents.containsKey(r)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int change = reagents.get(r).rawFillerChanceChange;
|
float change = reagents.get(r).rawFillerChanceChange;
|
||||||
if (change > increase) {
|
if (change > increase) {
|
||||||
increase = change;
|
increase = change;
|
||||||
}
|
}
|
||||||
@@ -134,14 +134,16 @@ public class MeteorReagentRegistry {
|
|||||||
return increase;
|
return increase;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the one largest raw filler chance decrease (negative config).
|
/**
|
||||||
public static int getLargestRawFillerChanceDecrease(List<Reagent> reagentList) {
|
* @return the one largest raw filler chance decrease from all given reagents (negative value in config).
|
||||||
int decrease = 0;
|
*/
|
||||||
|
public static float getLargestRawFillerChanceDecrease(List<Reagent> reagentList) {
|
||||||
|
float decrease = 0;
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
if (!reagents.containsKey(r)) {
|
if (!reagents.containsKey(r)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int change = reagents.get(r).rawFillerChanceChange;
|
float change = reagents.get(r).rawFillerChanceChange;
|
||||||
if (change < decrease) {
|
if (change < decrease) {
|
||||||
decrease = change;
|
decrease = change;
|
||||||
}
|
}
|
||||||
@@ -149,14 +151,16 @@ public class MeteorReagentRegistry {
|
|||||||
return decrease;
|
return decrease;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of the blocks that the given reagents will use to replace filler.
|
/**
|
||||||
public static List<MeteorParadigmComponent> getFillerList(List<Reagent> reagentList) {
|
* @return a list of the MeteorComponents that the given reagents will use to replace filler.
|
||||||
List<MeteorParadigmComponent> fillerList = new ArrayList<>();
|
*/
|
||||||
|
public static List<MeteorComponent> getFillerList(List<Reagent> reagentList) {
|
||||||
|
List<MeteorComponent> fillerList = new ArrayList<>();
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
if (!reagents.containsKey(r)) {
|
if (!reagents.containsKey(r)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<MeteorParadigmComponent> filler = reagents.get(r).parsedFiller;
|
List<MeteorComponent> filler = reagents.get(r).filler;
|
||||||
if (filler != null && !filler.isEmpty()) {
|
if (filler != null && !filler.isEmpty()) {
|
||||||
fillerList.addAll(filler);
|
fillerList.addAll(filler);
|
||||||
}
|
}
|
||||||
@@ -164,7 +168,9 @@ public class MeteorReagentRegistry {
|
|||||||
return fillerList;
|
return fillerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns false if any of the given reagents disable explosions, otherwise true
|
/**
|
||||||
|
* @return false if any of the given reagents disable explosions, otherwise true
|
||||||
|
*/
|
||||||
public static boolean doExplosions(List<Reagent> reagentList) {
|
public static boolean doExplosions(List<Reagent> reagentList) {
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
if (!reagents.containsKey(r)) {
|
if (!reagents.containsKey(r)) {
|
||||||
@@ -178,9 +184,9 @@ public class MeteorReagentRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the config AlchemicalWizardry.doMeteorsDestroyBlocks if no reagent inverts explosion block
|
* @return the value of the config AlchemicalWizardry.doMeteorsDestroyBlocks if no reagent inverts explosion block
|
||||||
* damage Returns the inverse of the value of AlchemicalWizardry.doMeteorsDestroyBlocks if any reagent inverts
|
* damage. If any reagent inverts explosion block damage, the inverse of the config
|
||||||
* explosion block damage
|
* AlchemicalWizardry.doMeteorsDestroyBlocks is returned.
|
||||||
*/
|
*/
|
||||||
public static boolean doMeteorsDestroyBlocks(List<Reagent> reagentList) {
|
public static boolean doMeteorsDestroyBlocks(List<Reagent> reagentList) {
|
||||||
for (Reagent r : reagentList) {
|
for (Reagent r : reagentList) {
|
||||||
@@ -193,29 +199,4 @@ public class MeteorReagentRegistry {
|
|||||||
}
|
}
|
||||||
return AlchemicalWizardry.doMeteorsDestroyBlocks;
|
return AlchemicalWizardry.doMeteorsDestroyBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateDefaultConfig() {
|
|
||||||
Map<String, String[]> lineMap = new HashMap<>();
|
|
||||||
lineMap.put("terrae", new String[] { "{", " \"radiusChange\": 1,", " \"fillerChanceChange\": 10", "}", });
|
|
||||||
lineMap.put(
|
|
||||||
"orbisTerrae",
|
|
||||||
new String[] { "{", " \"radiusChange\": 2,", " \"fillerChanceChange\": 20", "}", });
|
|
||||||
lineMap.put("tenebrae", new String[] { "{", " \"filler\": [\"minecraft:obsidian:0:180\"]", "}", });
|
|
||||||
lineMap.put(
|
|
||||||
"incendium",
|
|
||||||
new String[] { "{", " \"filler\": [", " \"minecraft:netherrack:0:60\",",
|
|
||||||
" \"minecraft:glowstone:0:60\",", " \"minecraft:soul_sand:0:60\"", " ]", "}", });
|
|
||||||
lineMap.put("crystallos", new String[] { "{", " \"filler\": [\"minecraft:ice:0:180\"]", "}", });
|
|
||||||
try {
|
|
||||||
Files.createDirectories(Paths.get("config/BloodMagic/meteors/reagents/"));
|
|
||||||
String[] reagents = { "terrae", "orbisTerrae", "tenebrae", "incendium", "crystallos" };
|
|
||||||
for (String reagent : reagents) {
|
|
||||||
Path path = Paths.get("config/BloodMagic/meteors/reagents/" + reagent + ".json");
|
|
||||||
Files.createFile(path);
|
|
||||||
Files.write(path, Arrays.asList(lineMap.get(reagent)), StandardOpenOption.WRITE);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+53
-30
@@ -1,58 +1,81 @@
|
|||||||
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
|
||||||
|
|
||||||
public class MeteorRegistry {
|
public class MeteorRegistry {
|
||||||
|
|
||||||
public static List<MeteorParadigm> paradigmList = new ArrayList<>();
|
public static List<Meteor> meteorList = new ArrayList<>();
|
||||||
|
|
||||||
public static void registerMeteorParadigm(MeteorParadigm paradigm) {
|
public static void loadConfig() {
|
||||||
paradigmList.add(paradigm);
|
Gson gson = new GsonBuilder().setPrettyPrinting()
|
||||||
}
|
.registerTypeAdapter(MeteorComponent.class, new MeteorComponentAdapter())
|
||||||
|
.registerTypeAdapter(ItemStack.class, new ItemStackAdapter()).create();
|
||||||
public static void registerMeteorParadigm(ItemStack stack, String[] componentList, int radius, int cost) {
|
File file = new File("config/BloodMagic/meteors");
|
||||||
registerMeteorParadigm(stack, componentList, radius, cost, null, 0);
|
File[] files = file.listFiles();
|
||||||
}
|
if (files != null) {
|
||||||
|
for (File f : files) {
|
||||||
public static void registerMeteorParadigm(ItemStack stack, String[] componentList, int radius, int cost,
|
try {
|
||||||
String[] fillerList, int fillerChance) {
|
if (f.isDirectory() || !f.getName().endsWith(".json")) {
|
||||||
if (stack != null && componentList != null) {
|
continue;
|
||||||
MeteorParadigm meteor = new MeteorParadigm(stack, radius, cost, fillerChance);
|
}
|
||||||
meteor.componentList = MeteorParadigm.parseStringArray(componentList);
|
BufferedReader br = new BufferedReader(new FileReader(f));
|
||||||
if (fillerList != null && fillerList.length > 0) {
|
Meteor m = gson.fromJson(br, Meteor.class);
|
||||||
meteor.fillerList = MeteorParadigm.parseStringArray(fillerList);
|
MeteorRegistry.registerMeteor(m);
|
||||||
} else {
|
} catch (FileNotFoundException | JsonSyntaxException e) {
|
||||||
meteor.fillerList.add(getDefaultMeteorParadigmComponent());
|
AlchemicalWizardry.logger.warn("Error adding meteor {}", f.getName());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
paradigmList.add(meteor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MeteorParadigmComponent getDefaultMeteorParadigmComponent() {
|
public static void registerMeteor(Meteor meteor) {
|
||||||
return new MeteorParadigmComponent(new ItemStack(Blocks.stone), 1);
|
meteor.validate();
|
||||||
|
meteorList.add(meteor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createMeteorImpact(World world, int x, int y, int z, int paradigmID, List<Reagent> reagents) {
|
public static void registerMeteor(ItemStack stack, String[] componentList, int radius, int cost) {
|
||||||
if (paradigmID < paradigmList.size()) {
|
registerMeteor(stack, MeteorComponent.parseStringArray(componentList), radius, cost, null, 0);
|
||||||
paradigmList.get(paradigmID).createMeteorImpact(world, x, y, z, reagents);
|
}
|
||||||
|
|
||||||
|
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, int radius, int cost,
|
||||||
|
List<MeteorComponent> fillerList, int fillerChance) {
|
||||||
|
if (stack != null && componentList != null) {
|
||||||
|
Meteor meteor = new Meteor(stack, radius, cost, fillerChance, componentList, fillerList);
|
||||||
|
meteor.validate();
|
||||||
|
meteorList.add(meteor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getParadigmIDForItem(ItemStack stack) {
|
public static void createMeteorImpact(World world, int x, int y, int z, int meteorID, List<Reagent> reagents) {
|
||||||
|
if (meteorID < meteorList.size()) {
|
||||||
|
meteorList.get(meteorID).createMeteorImpact(world, x, y, z, reagents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMeteorIDForItem(ItemStack stack) {
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < paradigmList.size(); i++) {
|
for (int i = 0; i < meteorList.size(); i++) {
|
||||||
ItemStack focusStack = paradigmList.get(i).focusStack;
|
ItemStack focusStack = meteorList.get(i).focusItem;
|
||||||
|
|
||||||
if (focusStack != null && focusStack.getItem() == stack.getItem()
|
if (focusStack != null && focusStack.getItem() == stack.getItem()
|
||||||
&& (focusStack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
&& (focusStack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||||
@@ -64,7 +87,7 @@ public class MeteorRegistry {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidParadigmItem(ItemStack stack) {
|
public static boolean isValidMeteorFocusItem(ItemStack stack) {
|
||||||
return getParadigmIDForItem(stack) != -1;
|
return getMeteorIDForItem(stack) != -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,8 @@ import java.util.Iterator;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigm;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.Meteor;
|
||||||
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent;
|
||||||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
|
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
|
||||||
import minetweaker.IUndoableAction;
|
import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
@@ -61,43 +62,46 @@ public class FallingTower {
|
|||||||
|
|
||||||
private static class Add implements IUndoableAction {
|
private static class Add implements IUndoableAction {
|
||||||
|
|
||||||
private MeteorParadigm paradigm;
|
private Meteor meteor;
|
||||||
|
|
||||||
public Add(ItemStack stack, int radius, int cost, String[] components) {
|
public Add(ItemStack stack, int radius, int cost, String[] components) {
|
||||||
new Add(stack, radius, cost, components, null, 0);
|
new Add(stack, radius, cost, components, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Add(ItemStack stack, int radius, int cost, String[] components, String[] filler, int fillerChance) {
|
public Add(ItemStack stack, int radius, int cost, String[] components, String[] filler, int fillerChance) {
|
||||||
paradigm = new MeteorParadigm(stack, radius, cost, fillerChance);
|
meteor = new Meteor(
|
||||||
paradigm.componentList = MeteorParadigm.parseStringArray(components);
|
stack,
|
||||||
if (filler != null) {
|
radius,
|
||||||
paradigm.fillerList = MeteorParadigm.parseStringArray(filler);
|
cost,
|
||||||
}
|
fillerChance,
|
||||||
|
MeteorComponent.parseStringArray(components),
|
||||||
|
MeteorComponent.parseStringArray(filler));
|
||||||
|
meteor.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
MeteorRegistry.registerMeteorParadigm(paradigm);
|
MeteorRegistry.registerMeteor(meteor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return MeteorRegistry.paradigmList != null;
|
return MeteorRegistry.meteorList != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
MeteorRegistry.paradigmList.remove(paradigm);
|
MeteorRegistry.meteorList.remove(meteor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe() {
|
public String describe() {
|
||||||
return "Adding Falling Tower Focus for " + paradigm.focusStack.getDisplayName();
|
return "Adding Falling Tower Focus for " + meteor.focusItem.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return "Removing Falling Tower Focus for " + paradigm.focusStack.getDisplayName();
|
return "Removing Falling Tower Focus for " + meteor.focusItem.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,7 +113,7 @@ public class FallingTower {
|
|||||||
private static class Remove implements IUndoableAction {
|
private static class Remove implements IUndoableAction {
|
||||||
|
|
||||||
private final ItemStack focus;
|
private final ItemStack focus;
|
||||||
private MeteorParadigm paradigm;
|
private Meteor paradigm;
|
||||||
|
|
||||||
public Remove(ItemStack focus) {
|
public Remove(ItemStack focus) {
|
||||||
this.focus = focus;
|
this.focus = focus;
|
||||||
@@ -117,9 +121,9 @@ public class FallingTower {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
for (Iterator<MeteorParadigm> itr = MeteorRegistry.paradigmList.iterator(); itr.hasNext();) {
|
for (Iterator<Meteor> itr = MeteorRegistry.meteorList.iterator(); itr.hasNext();) {
|
||||||
MeteorParadigm paradigm = itr.next();
|
Meteor paradigm = itr.next();
|
||||||
if (OreDictionary.itemMatches(paradigm.focusStack, focus, false)) {
|
if (OreDictionary.itemMatches(paradigm.focusItem, focus, false)) {
|
||||||
this.paradigm = paradigm;
|
this.paradigm = paradigm;
|
||||||
itr.remove();
|
itr.remove();
|
||||||
break;
|
break;
|
||||||
@@ -129,12 +133,12 @@ public class FallingTower {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return MeteorRegistry.paradigmList != null && paradigm != null;
|
return MeteorRegistry.meteorList != null && paradigm != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
MeteorRegistry.paradigmList.add(paradigm);
|
MeteorRegistry.meteorList.add(paradigm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user