Readd Meteor Filler (#60)

This commit is contained in:
koolkrafter5 authored and GitHub committed 2024-11-22 17:38:56 +01:00
1 parent 222ad1645e
commit ba0a0e3357
7 files changed
+175 -111

No files matched your search

@@ -31,6 +31,7 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
private final List<PositionedStack> input = new ArrayList<>();
private final List<PositionedStack> outputs = new ArrayList<>();
private final List<PositionedStack> filler = new ArrayList<>();
private final int cost;
private final int radius;
private Point focus;
@@ -40,9 +41,13 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
int row = 0;
int col = 0;
float totalMeteorWeight = meteor.getTotalMeteorWeight();
float totalComponentWeight = meteor.getTotalListWeight(meteor.componentList);
int fillerChance = meteor.fillerChance;
List<MeteorParadigmComponent> 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 class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
int yPos = 37 + 18 * row;
List<String> 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 class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
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<MeteorParadigmComponent> 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<String> 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 class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
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 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
}
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);
}
}
@@ -10,17 +10,20 @@ import net.minecraft.item.ItemStack;
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 class Meteor {
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();
}
}
@@ -21,16 +21,23 @@ 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) {
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 class MeteorParadigm {
// 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<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(oreName);
Matcher matcher = itemNamePattern.matcher(blockName);
if (matcher.matches()) {
String modID = matcher.group(1);
String itemName = matcher.group(2);
@@ -53,18 +61,18 @@ public class MeteorParadigm {
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<ItemStack> 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 class MeteorParadigm {
} else {
// Legacy config
String oreDict = oreName;
int weight = Integer.parseInt(oreArray[++i]);
String oreDict = blockName;
int weight = Integer.parseInt(blockArray[++i]);
List<ItemStack> 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 class MeteorParadigm {
}
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<MeteorParadigmComponent> 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 class MeteorParadigm {
}
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<MeteorParadigmComponent> 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 class MeteorParadigm {
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;
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 (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);
}
}
}
}
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;
}
}
}
@@ -4,16 +4,16 @@ import net.minecraft.item.ItemStack;
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() {
@@ -3,6 +3,7 @@ package WayofTime.alchemicalWizardry.common.summoning.meteor;
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 class MeteorRegistry {
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);
}
}
@@ -41,6 +41,19 @@ public class FallingTower {
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 @@ public class FallingTower {
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