mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-18 11:19:21 +00:00
New formats for meteor config file. (#50)
This commit is contained in:
1 parent
3037e0f583
commit
1c8ceacb7f
6 files changed
+78
-61
No files matched your search
@@ -11,7 +11,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
||||
|
||||
float totalMeteorWeight = meteor.getTotalMeteorWeight();
|
||||
List<MeteorParadigmComponent> sortedComponents = new ArrayList<>(meteor.componentList);
|
||||
sortedComponents.sort(Comparator.comparingInt(c -> -c.chance));
|
||||
sortedComponents.sort(Comparator.comparingInt(c -> -c.getChance()));
|
||||
|
||||
for (MeteorParadigmComponent component : sortedComponents) {
|
||||
ItemStack stack = component.getValidBlockParadigm();
|
||||
@@ -51,10 +50,6 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler {
|
||||
int yPos = 37 + 18 * row;
|
||||
|
||||
List<String> tooltips = new ArrayList<>();
|
||||
if (stack == null) {
|
||||
stack = new ItemStack(Blocks.fire);
|
||||
tooltips.add(String.format("no entries found for oredict \"%s\"", component.getOreDictName()));
|
||||
}
|
||||
float chance = component.getChance() / totalMeteorWeight;
|
||||
tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(chance)));
|
||||
tooltips.add(I18n.format("nei.recipe.meteor.amount", getEstimatedAmount(chance, meteor.radius)));
|
||||
|
||||
+57
-12
@@ -3,15 +3,19 @@ package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||
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.init.Blocks;
|
||||
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 cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import gregtech.common.blocks.GT_TileEntity_Ores;
|
||||
|
||||
public class MeteorParadigm {
|
||||
@@ -29,22 +33,67 @@ public class MeteorParadigm {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
// modId:itemName:meta:weight
|
||||
private static final Pattern itemNamePattern = Pattern.compile("(.*):(.*):(\\d+):(\\d+)");
|
||||
// OREDICT:oreDictName:weight
|
||||
private static final Pattern oredictPattern = Pattern.compile("OREDICT:(.*):(\\d+)");
|
||||
|
||||
public void parseStringArray(String[] oreArray) {
|
||||
for (int i = 0; i + 1 < oreArray.length; i += 2) {
|
||||
for (int i = 0; i < oreArray.length; ++i) {
|
||||
String oreName = oreArray[i];
|
||||
int oreChance = Integer.parseInt(oreArray[i + 1]);
|
||||
MeteorParadigmComponent mpc = new MeteorParadigmComponent(oreName, oreChance);
|
||||
componentList.add(mpc);
|
||||
boolean success = false;
|
||||
|
||||
Matcher matcher = itemNamePattern.matcher(oreName);
|
||||
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));
|
||||
|
||||
ItemStack stack = GameRegistry.findItemStack(modID, itemName, 1);
|
||||
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
||||
stack.setItemDamage(meta);
|
||||
componentList.add(new MeteorParadigmComponent(stack, weight));
|
||||
success = true;
|
||||
}
|
||||
|
||||
} else if ((matcher = oredictPattern.matcher(oreName)).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));
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Legacy config
|
||||
String oreDict = oreName;
|
||||
int weight = Integer.parseInt(oreArray[++i]);
|
||||
|
||||
List<ItemStack> list = OreDictionary.getOres(oreDict);
|
||||
for (ItemStack stack : list) {
|
||||
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
||||
componentList.add(new MeteorParadigmComponent(stack, weight));
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
AlchemicalWizardry.logger.warn("Unable to add Meteor Paradigm \"" + oreName + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getTotalMeteorWeight() {
|
||||
int totalMeteorWeight = 0;
|
||||
for (MeteorParadigmComponent mpc : componentList) {
|
||||
if (mpc == null || !mpc.isValidBlockParadigm()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
totalMeteorWeight += mpc.getChance();
|
||||
}
|
||||
return totalMeteorWeight;
|
||||
@@ -99,10 +148,6 @@ public class MeteorParadigm {
|
||||
boolean hasPlacedBlock = false;
|
||||
|
||||
for (MeteorParadigmComponent mpc : componentList) {
|
||||
if (mpc == null || !mpc.isValidBlockParadigm()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
randNum -= mpc.getChance();
|
||||
|
||||
if (randNum < 0) {
|
||||
|
||||
+5
-29
@@ -1,46 +1,22 @@
|
||||
package WayofTime.alchemicalWizardry.common.summoning.meteor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class MeteorParadigmComponent {
|
||||
|
||||
public String oreDictName;
|
||||
public int chance;
|
||||
protected int chance;
|
||||
protected ItemStack itemStack;
|
||||
|
||||
public MeteorParadigmComponent(String dictName, int chance) {
|
||||
this.oreDictName = dictName;
|
||||
public MeteorParadigmComponent(ItemStack stack, int chance) {
|
||||
this.itemStack = stack;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public boolean isValidBlockParadigm() {
|
||||
if (this.getValidBlockParadigm() != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getOreDictName() {
|
||||
return this.oreDictName;
|
||||
}
|
||||
|
||||
public int getChance() {
|
||||
return this.chance;
|
||||
}
|
||||
|
||||
public ItemStack getValidBlockParadigm() {
|
||||
List<ItemStack> list = OreDictionary.getOres(getOreDictName());
|
||||
|
||||
for (ItemStack stack : list) {
|
||||
if (stack != null && stack.getItem() instanceof ItemBlock) {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user