From ba0a0e33570292bb7803d382fc6077b7e39f2c5b Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Fri, 22 Nov 2024 11:38:56 -0500 Subject: [PATCH] Readd Meteor Filler (#60) --- .../client/nei/NEIMeteorRecipeHandler.java | 53 +++++- .../common/summoning/meteor/Meteor.java | 21 ++- .../summoning/meteor/MeteorParadigm.java | 161 ++++++++---------- .../meteor/MeteorParadigmComponent.java | 10 +- .../summoning/meteor/MeteorRegistry.java | 19 ++- .../common/tweaker/FallingTower.java | 23 ++- .../assets/alchemicalwizardry/lang/en_US.lang | 1 + 7 files changed, 176 insertions(+), 112 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java index a93e9212b..536f16029 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java @@ -31,6 +31,7 @@ public class CachedMeteorRecipe extends CachedRecipe { private final List input = new ArrayList<>(); private final List outputs = new ArrayList<>(); + private final List filler = new ArrayList<>(); private final int cost; private final int radius; private Point focus; @@ -40,9 +41,13 @@ public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) { int row = 0; int col = 0; - float totalMeteorWeight = meteor.getTotalMeteorWeight(); + float totalComponentWeight = meteor.getTotalListWeight(meteor.componentList); + int fillerChance = meteor.fillerChance; List sortedComponents = new ArrayList<>(meteor.componentList); - sortedComponents.sort(Comparator.comparingInt(c -> -c.getChance())); + sortedComponents.sort(Comparator.comparingInt(c -> -c.getWeight())); + + float fillerRatio = (float) (fillerChance / 100.0); + float componentRatio = 1 - fillerRatio; for (MeteorParadigmComponent component : sortedComponents) { ItemStack stack = component.getValidBlockParadigm(); @@ -50,7 +55,7 @@ public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) { int yPos = 37 + 18 * row; List tooltips = new ArrayList<>(); - float chance = component.getChance() / totalMeteorWeight; + 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))); this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips)); @@ -61,10 +66,45 @@ public CachedMeteorRecipe(MeteorParadigm meteor, ItemStack focusStack) { row++; } - if (focusStack != null && matchItem(focusStack, stack)) { + if (matchItem(focusStack, stack)) { this.focus = new Point(xPos - 1, yPos - 1); } } + + if (fillerChance > 0) { + if (col != 0) { + col = 0; + row++; + } + + List sortedFiller = new ArrayList<>(meteor.fillerList); + sortedFiller.sort(Comparator.comparingInt(c -> -c.getWeight())); + float totalFillerWeight = meteor.getTotalListWeight(meteor.fillerList); + + for (MeteorParadigmComponent filler : sortedFiller) { + ItemStack stack = filler.getValidBlockParadigm(); + int xPos = 3 + 18 * col; + int yPos = 37 + 18 * row; + + List tooltips = new ArrayList<>(); + float chance = filler.getWeight() / totalFillerWeight * fillerRatio; + 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.filler")); + this.outputs.add(new TooltipStack(stack, xPos, yPos, tooltips)); + + col++; + if (col > 8) { + col = 0; + row++; + } + + if (matchItem(focusStack, stack)) { + this.focus = new Point(xPos - 1, yPos - 1); + } + } + } + this.radius = meteor.radius; this.cost = meteor.cost; } @@ -115,6 +155,9 @@ public void loadCraftingRecipes(ItemStack result) { if (meteor.componentList.stream().anyMatch(m -> matchItem(result, m.getValidBlockParadigm()))) { arecipes.add(new CachedMeteorRecipe(meteor, result)); } + if (meteor.fillerList.stream().anyMatch(m -> matchItem(result, m.getValidBlockParadigm()))) { + arecipes.add(new CachedMeteorRecipe(meteor, result)); + } } } @@ -205,6 +248,6 @@ private String getFormattedChance(float chance) { } private int getEstimatedAmount(float chance, int radius) { - return (int) Math.ceil(4f / 3 * Math.PI * Math.pow(radius, 3) * chance); + return (int) Math.ceil(4f / 3 * Math.PI * Math.pow(radius + 0.5, 3) * chance); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java index c8fa6427f..e251acf85 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java @@ -10,17 +10,20 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; import cpw.mods.fml.common.registry.GameRegistry; public class Meteor { - public String[] ores; - public int radius; - public int cost; - public String focusModId; - public String focusName; - public int focusMeta; + private String[] ores; + private int radius; + private int cost; + private String focusModId; + private String focusName; + private int focusMeta; + private String[] filler; + private int fillerChance; public static void loadConfig() { Gson gson = new GsonBuilder().setPrettyPrinting().create(); @@ -35,9 +38,11 @@ public static void loadConfig() { findItemStack(m.focusModId, m.focusName, m.focusMeta), m.ores, m.radius, - m.cost); + m.cost, + m.filler, + m.fillerChance); } - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | JsonSyntaxException e) { e.printStackTrace(); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigm.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigm.java index 8111d6ea3..d837f2791 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigm.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigm.java @@ -21,16 +21,23 @@ public class MeteorParadigm { public List componentList = new ArrayList<>(); + public List 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) { + new MeteorParadigm(focusStack, radius, cost, 0); + } + + 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 @@ -38,12 +45,13 @@ public MeteorParadigm(ItemStack focusStack, int radius, int cost) { // OREDICT:oreDictName:weight private static final Pattern oredictPattern = Pattern.compile("OREDICT:(.*):(\\d+)"); - public void parseStringArray(String[] oreArray) { - for (int i = 0; i < oreArray.length; ++i) { - String oreName = oreArray[i]; + public static List parseStringArray(String[] blockArray) { + List addList = new ArrayList<>(); + for (int i = 0; i < blockArray.length; ++i) { + String blockName = blockArray[i]; boolean success = false; - Matcher matcher = itemNamePattern.matcher(oreName); + Matcher matcher = itemNamePattern.matcher(blockName); if (matcher.matches()) { String modID = matcher.group(1); String itemName = matcher.group(2); @@ -53,18 +61,18 @@ public void parseStringArray(String[] oreArray) { ItemStack stack = GameRegistry.findItemStack(modID, itemName, 1); if (stack != null && stack.getItem() instanceof ItemBlock) { stack.setItemDamage(meta); - componentList.add(new MeteorParadigmComponent(stack, weight)); + addList.add(new MeteorParadigmComponent(stack, weight)); success = true; } - } else if ((matcher = oredictPattern.matcher(oreName)).matches()) { + } else if ((matcher = oredictPattern.matcher(blockName)).matches()) { String oreDict = matcher.group(1); int weight = Integer.parseInt(matcher.group(2)); List list = OreDictionary.getOres(oreDict); for (ItemStack stack : list) { if (stack != null && stack.getItem() instanceof ItemBlock) { - componentList.add(new MeteorParadigmComponent(stack, weight)); + addList.add(new MeteorParadigmComponent(stack, weight)); success = true; break; } @@ -72,13 +80,13 @@ public void parseStringArray(String[] oreArray) { } else { // Legacy config - String oreDict = oreName; - int weight = Integer.parseInt(oreArray[++i]); + String oreDict = blockName; + int weight = Integer.parseInt(blockArray[++i]); List list = OreDictionary.getOres(oreDict); for (ItemStack stack : list) { if (stack != null && stack.getItem() instanceof ItemBlock) { - componentList.add(new MeteorParadigmComponent(stack, weight)); + addList.add(new MeteorParadigmComponent(stack, weight)); success = true; break; } @@ -86,17 +94,18 @@ public void parseStringArray(String[] oreArray) { } if (!success) { - AlchemicalWizardry.logger.warn("Unable to add Meteor Paradigm \"" + oreName + "\""); + AlchemicalWizardry.logger.warn("Unable to add Meteor Paradigm \"" + blockName + "\""); } } + return addList; } - public int getTotalMeteorWeight() { - int totalMeteorWeight = 0; - for (MeteorParadigmComponent mpc : componentList) { - totalMeteorWeight += mpc.getChance(); + public int getTotalListWeight(List blockList) { + int totalWeight = 0; + for (MeteorParadigmComponent mpc : blockList) { + totalWeight += mpc.getWeight(); } - return totalMeteorWeight; + return totalWeight; } public void createMeteorImpact(World world, int x, int y, int z, boolean[] flags) { @@ -115,22 +124,41 @@ public void createMeteorImpact(World world, int x, int y, int z, boolean[] flags } int newRadius = radius; - + int fillerChance = this.fillerChance; if (hasOrbisTerrae) { newRadius += 2; + fillerChance *= 1.12; } else if (hasTerrae) { newRadius += 1; + fillerChance *= 1.06; + } + if (fillerChance > 100) { + fillerChance = 100; } world.createExplosion(null, x, y, z, newRadius * 4, AlchemicalWizardry.doMeteorsDestroyBlocks); - float iceChance = hasCrystallos ? 1 : 0; - float soulChance = hasIncendium ? 1 : 0; - float obsidChance = hasTennebrae ? 1 : 0; + List fillerList; - float totalChance = iceChance + soulChance + obsidChance; + if (hasCrystallos || hasIncendium || hasTennebrae) { + fillerList = new ArrayList<>(); + if (hasCrystallos) { + fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.ice), 180)); // 180 = 2^2 * 3^2 * 5 + } + if (hasIncendium) { + fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.netherrack), 60)); + fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.soul_sand), 60)); + fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.glowstone), 60)); + } + if (hasTennebrae) { + fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.obsidian), 180)); + } + } else { + fillerList = this.fillerList; + } - int totalMeteorWeight = getTotalMeteorWeight(); + int totalComponentWeight = getTotalListWeight(componentList); + int totalFillerWeight = getTotalListWeight(fillerList); for (int i = -newRadius; i <= newRadius; i++) { for (int j = -newRadius; j <= newRadius; j++) { @@ -143,75 +171,30 @@ public void createMeteorImpact(World world, int x, int y, int z, boolean[] flags continue; } - int randNum = world.rand.nextInt(totalMeteorWeight); - - boolean hasPlacedBlock = false; - - for (MeteorParadigmComponent mpc : componentList) { - randNum -= mpc.getChance(); - - if (randNum < 0) { - ItemStack blockStack = mpc.getValidBlockParadigm(); - if (blockStack != null && blockStack.getItem() instanceof ItemBlock) { - ((ItemBlock) blockStack.getItem()).placeBlockAt( - blockStack, - null, - world, - x + i, - y + j, - z + k, - 0, - 0, - 0, - 0, - blockStack.getItemDamage()); - if (AlchemicalWizardry.isGregTechLoaded) - setGTOresNaturalIfNeeded(world, x + i, y + j, z + k); - world.markBlockForUpdate(x + i, y + j, z + k); - hasPlacedBlock = true; - break; - } - // world.setBlock(x + i, y + j, z + k, - // Block.getBlockById(Item.getIdFromItem(blockStack.getItem())), blockStack.getItemDamage(), - // 3); - // hasPlacedBlock = true; - // break; - } + 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); } + } + } + } + } - if (!hasPlacedBlock) { - float randChance = rand.nextFloat() * totalChance; - - if (randChance < iceChance) { - world.setBlock(x + i, y + j, z + k, Blocks.ice, 0, 3); - } else { - randChance -= iceChance; - - if (randChance < soulChance) { - switch (rand.nextInt(3)) { - case 0: - world.setBlock(x + i, y + j, z + k, Blocks.soul_sand, 0, 3); - break; - case 1: - world.setBlock(x + i, y + j, z + k, Blocks.glowstone, 0, 3); - break; - case 2: - world.setBlock(x + i, y + j, z + k, Blocks.netherrack, 0, 3); - break; - } - } else { - randChance -= soulChance; - - if (randChance < obsidChance) { - world.setBlock(x + i, y + j, z + k, Blocks.obsidian, 0, 3); - } else { - randChance -= obsidChance; - - world.setBlock(x + i, y + j, z + k, Blocks.stone, 0, 3); - } - } - } - } + private void setMeteorBlock(int x, int y, int z, World world, List blockList, + int totalListWeight) { + int randNum = world.rand.nextInt(totalListWeight); + for (MeteorParadigmComponent mpc : blockList) { + randNum -= mpc.getWeight(); + + if (randNum < 0) { + ItemStack blockStack = mpc.getValidBlockParadigm(); + 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; } } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigmComponent.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigmComponent.java index 8a83e11c2..925a5c00b 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigmComponent.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorParadigmComponent.java @@ -4,16 +4,16 @@ public class MeteorParadigmComponent { - protected int chance; + protected int weight; protected ItemStack itemStack; - public MeteorParadigmComponent(ItemStack stack, int chance) { + public MeteorParadigmComponent(ItemStack stack, int weight) { this.itemStack = stack; - this.chance = chance; + this.weight = weight; } - public int getChance() { - return this.chance; + public int getWeight() { + return this.weight; } public ItemStack getValidBlockParadigm() { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java index d338a194a..fc63bc4fc 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; @@ -15,10 +16,20 @@ public static void registerMeteorParadigm(MeteorParadigm paradigm) { paradigmList.add(paradigm); } - public static void registerMeteorParadigm(ItemStack stack, String[] oreList, int radius, int cost) { - if (stack != null && oreList != null) { - MeteorParadigm meteor = new MeteorParadigm(stack, radius, cost); - meteor.parseStringArray(oreList); + public static void registerMeteorParadigm(ItemStack stack, String[] componentList, int radius, int cost) { + registerMeteorParadigm(stack, componentList, radius, cost, null, 0); + } + + public static void registerMeteorParadigm(ItemStack stack, String[] componentList, int radius, int cost, + String[] fillerList, int fillerChance) { + if (stack != null && componentList != null) { + MeteorParadigm meteor = new MeteorParadigm(stack, radius, cost, fillerChance); + meteor.componentList = MeteorParadigm.parseStringArray(componentList); + if (fillerList != null && fillerList.length > 0) { + meteor.fillerList = MeteorParadigm.parseStringArray(fillerList); + } else { + meteor.fillerList.add(new MeteorParadigmComponent(new ItemStack(Blocks.stone), 1)); + } paradigmList.add(meteor); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tweaker/FallingTower.java b/src/main/java/WayofTime/alchemicalWizardry/common/tweaker/FallingTower.java index b15266dac..677d5c8cc 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tweaker/FallingTower.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tweaker/FallingTower.java @@ -41,6 +41,19 @@ public static void addFocus(IItemStack stack, int radius, int cost, String compo MineTweakerAPI.apply(new Add(toStack(stack), radius, cost, components.split("\\s*,\\s*"))); } + @ZenMethod + public static void addFocus(IItemStack stack, int radius, int cost, String components, String filler, + int fillerChance) { + MineTweakerAPI.apply( + new Add( + toStack(stack), + radius, + cost, + components.split("\\s*,\\s*"), + filler.split("\\s*,\\s*"), + fillerChance)); + } + @ZenMethod public static void removeFocus(IItemStack output) { MineTweakerAPI.apply(new Remove(toStack(output))); @@ -51,8 +64,16 @@ private static class Add implements IUndoableAction { private MeteorParadigm paradigm; public Add(ItemStack stack, int radius, int cost, String[] components) { + new Add(stack, radius, cost, components, null, 0); + } + + public Add(ItemStack stack, int radius, int cost, String[] components, String[] filler, int fillerChance) { paradigm = new MeteorParadigm(stack, radius, cost); - paradigm.parseStringArray(components); + paradigm.componentList = MeteorParadigm.parseStringArray(components); + if (filler != null) { + paradigm.fillerList = MeteorParadigm.parseStringArray(filler); + } + paradigm.fillerChance = fillerChance; } @Override diff --git a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang index 7ff3b5c74..f87966289 100644 --- a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang +++ b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang @@ -267,6 +267,7 @@ nei.recipe.meteor.cost=Cost: %s LP nei.recipe.meteor.radius=Radius: %s nei.recipe.meteor.chance=Chance: %s%% nei.recipe.meteor.amount=Estimated amount: %s +nei.recipe.meteor.filler=ยง7Filler block #Rituals ritual.AW001Water.name=Ritual of the Full Spring