Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. interconnected meteor loose ends and code cleanup #66

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 46 additions & 30 deletions src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWateryGrave;
import WayofTime.alchemicalWizardry.common.spell.simple.SpellWindGust;
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.MeteorRegistry;
import WayofTime.alchemicalWizardry.common.tileEntity.TEAlchemicCalcinator;
import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar;
import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar;
Expand Down Expand Up @@ -308,6 +308,8 @@ public class AlchemicalWizardry {

public static boolean parseTextFiles = false;

public static int defaultMeteorCost = 1000000;
public static String defaultMeteorBlock;
public static boolean doMeteorsDestroyBlocks = true;
public static String[] allowedCrushedOresArray;

Expand Down Expand Up @@ -621,35 +623,12 @@ public Item getTabIconItem() {

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
File bmDirectory = new File("config/BloodMagic/schematics");

if (!bmDirectory.exists() && bmDirectory.mkdirs()) {
try {
InputStream in = AlchemicalWizardry.class
.getResourceAsStream("/assets/alchemicalwizardry/schematics/building/buildings.zip");
logger.info("none yet!");
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) {}
}
generateDefaultConfig(
"config/BloodMagic/schematics",
"/assets/alchemicalwizardry/schematics/building/buildings.zip");
generateDefaultConfig("config/BloodMagic/meteors", "/assets/alchemicalwizardry/meteors/meteors.zip");
generateDefaultConfig("config/BloodMagic/meteors/reagents", "/assets/alchemicalwizardry/meteors/reagents.zip");

TEDemonPortal.loadBuildingList();

Expand Down Expand Up @@ -708,6 +687,42 @@ public void preInit(FMLPreInitializationEvent event) {
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
public void load(FMLInitializationEvent event) {
int craftingConstant = OreDictionary.WILDCARD_VALUE;
Expand Down Expand Up @@ -3321,7 +3336,8 @@ public void postInit(FMLPostInitializationEvent event) {
BloodMagicConfiguration.loadCustomLPValues();

DemonVillageLootRegistry.init();
Meteor.loadConfig();

MeteorRegistry.loadConfig();
MeteorReagentRegistry.loadConfig();

this.initCompressionHandlers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath;
import WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal;
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.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
Expand Down Expand Up @@ -102,6 +103,23 @@ public static void syncConfig() {

AlchemicalWizardry.doMeteorsDestroyBlocks = config.get("meteor", "doMeteorsDestroyBlocks", 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(
"oreCrushing",
"allowedOres",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.google.common.base.Joiner;

import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigm;
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigmComponent;
import WayofTime.alchemicalWizardry.common.summoning.meteor.Meteor;
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorComponent;
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
Expand All @@ -38,55 +38,56 @@ public class CachedMeteorRecipe extends CachedRecipe {
private final int radius;
private Point focus;

public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) {
this.input.add(new PositionedStack(meteor.focusStack, 74, 4));
public CachedMeteorRecipe(Meteor meteor, ItemStack focusStack) {
this.input.add(new PositionedStack(meteor.focusItem, 74, 4));
int row = 0;
int col = 0;

float totalComponentWeight = meteor.getTotalListWeight(meteor.componentList);
int fillerChance = meteor.fillerChance;
List<MeteorParadigmComponent> sortedComponents = new ArrayList<>(meteor.componentList);
float totalComponentWeight = MeteorComponent.getTotalListWeight(meteor.ores);
float fillerChance = meteor.fillerChance;
List<MeteorComponent> sortedComponents = new ArrayList<>(meteor.ores);
sortedComponents.sort(Comparator.comparingInt(c -> -c.getWeight()));

float fillerRatio = (float) (fillerChance / 100.0);
float componentRatio = 1 - fillerRatio;

for (MeteorParadigmComponent component : sortedComponents) {
ItemStack stack = component.getBlock();
int xPos = 3 + 18 * col;
int yPos = 37 + 18 * row;

List<String> tooltips = new ArrayList<>();
float chance = component.getWeight() / totalComponentWeight * componentRatio;
tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(chance)));
tooltips.add(I18n.format("nei.recipe.meteor.amount", getEstimatedAmount(chance, meteor.radius)));
if (!component.getRequiredReagents().isEmpty()) {
tooltips.add(I18n.format("nei.recipe.meteor.reagent", getReagentStrings(component)));
}
this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips));
if (fillerChance < 100) {
for (MeteorComponent component : sortedComponents) {
ItemStack stack = component.getBlock();
int xPos = 3 + 18 * col;
int yPos = 37 + 18 * row;

col++;
if (col > 8) {
col = 0;
row++;
}
List<String> tooltips = new ArrayList<>();
float chance = component.getWeight() / totalComponentWeight * componentRatio;
tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(chance)));
tooltips.add(I18n.format("nei.recipe.meteor.amount", getEstimatedAmount(chance, meteor.radius)));
if (!component.getRequiredReagents().isEmpty()) {
tooltips.add(I18n.format("nei.recipe.meteor.reagent", getReagentStrings(component)));
}
this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips));

if (matchItem(focusStack, stack)) {
this.focus = new Point(xPos - 1, yPos - 1);
col++;
if (col > 8) {
col = 0;
row++;
}

if (matchItem(focusStack, stack)) {
this.focus = new Point(xPos - 1, yPos - 1);
}
}
}

if (fillerChance > 0) {
if (col != 0) {
col = 0;
row++;
}

List<MeteorParadigmComponent> sortedFiller = new ArrayList<>(meteor.fillerList);
List<MeteorComponent> sortedFiller = new ArrayList<>(meteor.filler);
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();
int xPos = 3 + 18 * col;
int yPos = 37 + 18 * row;
Expand Down Expand Up @@ -117,7 +118,7 @@ public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) {
this.cost = meteor.cost;
}

private String getReagentStrings(MeteorParadigmComponent component) {
private String getReagentStrings(MeteorComponent component) {
ArrayList<Reagent> reagents = component.getRequiredReagents();
ArrayList<String> reagentNames = new ArrayList<>();
for (Reagent r : reagents) {
Expand Down Expand Up @@ -158,7 +159,7 @@ public void loadTransferRects() {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals(getOverlayIdentifier()) && getClass() == NEIMeteorRecipeHandler.class) {
for (MeteorParadigm meteor : getSortedMeteors()) {
for (Meteor meteor : getSortedMeteors()) {
arecipes.add(new CachedMeteorRecipe(meteor, null));
}
} else {
Expand All @@ -168,20 +169,20 @@ public void loadCraftingRecipes(String outputId, Object... results) {

@Override
public void loadCraftingRecipes(ItemStack result) {
for (MeteorParadigm meteor : getSortedMeteors()) {
if (meteor.componentList.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
for (Meteor meteor : getSortedMeteors()) {
if (meteor.ores.stream().anyMatch(m -> matchItem(result, m.getBlock()))) {
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));
}
}
}

@Override
public void loadUsageRecipes(ItemStack ingredient) {
for (MeteorParadigm meteor : getSortedMeteors()) {
if (matchItem(ingredient, meteor.focusStack)) {
for (Meteor meteor : getSortedMeteors()) {
if (matchItem(ingredient, meteor.focusItem)) {
arecipes.add(new CachedMeteorRecipe(meteor, null));
}
}
Expand Down Expand Up @@ -255,8 +256,8 @@ public String getRecipeName() {
return I18n.format("nei.recipe.meteor.category");
}

private List<MeteorParadigm> getSortedMeteors() {
return MeteorRegistry.paradigmList.stream().sorted(Comparator.comparing(m -> m.cost))
private List<Meteor> getSortedMeteors() {
return MeteorRegistry.meteorList.stream().sorted(Comparator.comparing(m -> m.cost))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void performEffect(IMasterRitualStone ritualStone) {
if (entities == null) return;

for (EntityItem entityItem : entities) {
if (entityItem != null && MeteorRegistry.isValidParadigmItem(entityItem.getEntityItem())) {
int meteorID = MeteorRegistry.getParadigmIDForItem(entityItem.getEntityItem());
int cost = MeteorRegistry.paradigmList.get(meteorID).cost;
if (entityItem != null && MeteorRegistry.isValidMeteorFocusItem(entityItem.getEntityItem())) {
int meteorID = MeteorRegistry.getMeteorIDForItem(entityItem.getEntityItem());
int cost = MeteorRegistry.meteorList.get(meteorID).cost;

if (currentEssence < cost) {
EntityPlayer entityOwner = SpellHelper.getPlayerForUsername(owner);
Expand Down
Loading