Add metadata support to block/item list config options, fixes #353
This commit is contained in:
@@ -16,6 +16,7 @@ import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -125,7 +126,7 @@ public final class Settings {
|
||||
new ResourceLocation(Wizardry.MODID, "shrine_6"),
|
||||
new ResourceLocation(Wizardry.MODID, "shrine_7")};
|
||||
/** <b>[Server-only]</b> List of solid blocks (usually trees) which are ignored by the structure generators. */
|
||||
public ResourceLocation[] treeBlocks = toResourceLocations(DEFAULT_TREE_BLOCKS);
|
||||
public Pair<ResourceLocation, Short>[] treeBlocks = parseItemMetaStrings(DEFAULT_TREE_BLOCKS);
|
||||
/** <b>[Server-only]</b> The chance for wizard towers to generate with an evil wizard and chest inside. */
|
||||
public double evilWizardChance = 0.2;
|
||||
/** <b>[Server-only]</b> List of dimension ids in which to generate crystal ore. */
|
||||
@@ -190,15 +191,15 @@ public final class Settings {
|
||||
* <b>[Server-only]</b> List of registry names of items which cannot be smelted by the pocket furnace spell, in
|
||||
* addition to armour, tools and weapons.
|
||||
*/
|
||||
public ResourceLocation[] pocketFurnaceItemBlacklist = toResourceLocations("cobblestone", "netherrack");
|
||||
public Pair<ResourceLocation, Short>[] pocketFurnaceItemBlacklist = parseItemMetaStrings("cobblestone", "netherrack");
|
||||
/** <b>[Server-only]</b> List of registry names of blocks which can be detected by the divination spell. */
|
||||
public ResourceLocation[] divinationOreWhitelist = {};
|
||||
public Pair<ResourceLocation, Short>[] divinationOreWhitelist = parseItemMetaStrings(); // That works I guess
|
||||
/** <b>[Server-only]</b> List of registry names of items which count as swords for imbuement spells. */
|
||||
public ResourceLocation[] swordItemWhitelist = {};
|
||||
public Pair<ResourceLocation, Short>[] swordItemWhitelist = parseItemMetaStrings();
|
||||
/** <b>[Server-only]</b> List of registry names of items which count as bows for imbuement spells. */
|
||||
public ResourceLocation[] bowItemWhitelist = {};
|
||||
public Pair<ResourceLocation, Short>[] bowItemWhitelist = parseItemMetaStrings();
|
||||
/** <b>[Server-only]</b> Map of items to values which wizard trades may use as currency. */
|
||||
public Map<ResourceLocation, Integer> currencyItems = new HashMap<>();
|
||||
public Map<Pair<ResourceLocation, Short>, Integer> currencyItems = new HashMap<>();
|
||||
/** <b>[Server-only]</b> Global damage scaling factor for all player magic damage. */
|
||||
public double playerDamageScale = 1.0;
|
||||
/** <b>[Server-only]</b> Global damage scaling factor for all npc magic damage. */
|
||||
@@ -652,41 +653,42 @@ public final class Settings {
|
||||
"List of registry names of blocks or items which cannot be smelted by the pocket furnace spell, in addition to armour, tools and weapons. Block/item names are not case sensitive. For mod items, prefix with the mod ID (e.g. " + Wizardry.MODID + ":crystal_ore).");
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".pocket_furnace_item_blacklist");
|
||||
property.setRequiresWorldRestart(true);
|
||||
pocketFurnaceItemBlacklist = getResourceLocationList(property);
|
||||
pocketFurnaceItemBlacklist = parseItemMetaStrings(property.getStringList());
|
||||
propOrder.add(property.getName());
|
||||
|
||||
property = config.get(GAMEPLAY_CATEGORY, "divinationOreWhitelist", new String[0], "List of registry names of ore blocks which can be detected by the divination spell. Block names are not case sensitive. For mod blocks, prefix with the mod ID (e.g. " + Wizardry.MODID + ":crystal_ore).");
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".divination_ore_whitelist");
|
||||
property.setRequiresWorldRestart(true);
|
||||
divinationOreWhitelist = getResourceLocationList(property);
|
||||
divinationOreWhitelist = parseItemMetaStrings(property.getStringList());
|
||||
propOrder.add(property.getName());
|
||||
|
||||
property = config.get(GAMEPLAY_CATEGORY, "swordItemWhitelist", new String[0], "List of registry names of items which should count as swords for imbuement spells. Most swords should work automatically, but those that don't can be added manually here. Item names are not case sensitive. For mod items, prefix with the mod ID (e.g. tconstruct:broadsword).");
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".sword_item_whitelist");
|
||||
property.setRequiresWorldRestart(true);
|
||||
swordItemWhitelist = getResourceLocationList(property);
|
||||
swordItemWhitelist = parseItemMetaStrings(property.getStringList());
|
||||
propOrder.add(property.getName());
|
||||
|
||||
property = config.get(GAMEPLAY_CATEGORY, "bowItemWhitelist", new String[0], "List of registry names of items which should count as bows for imbuement spells. Most bows should work automatically, but those that don't can be added manually here. Item names are not case sensitive. For mod items, prefix with the mod ID (e.g. tconstruct:shortbow).");
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".bow_item_whitelist");
|
||||
property.setRequiresWorldRestart(true);
|
||||
bowItemWhitelist = getResourceLocationList(property);
|
||||
bowItemWhitelist = parseItemMetaStrings(property.getStringList());
|
||||
propOrder.add(property.getName());
|
||||
|
||||
property = config.get(GAMEPLAY_CATEGORY, "currencyItems", new String[]{"gold_ingot 3", "emerald 6"}, "List of registry names of items which wizard trades can use as currency (in the first slot; the second slot is unaffected). Each entry in this list should consist of an item registry name, followed by a single space, then an integer which defines the 'value' of the item. Higher values mean fewer of that currency item are required for a given trade.",
|
||||
Pattern.compile("[A-Za-z:_]+ [0-9]+"));
|
||||
Pattern.compile("[A-Za-z0-9:_]+ [0-9]+"));
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".currency_items");
|
||||
property.setRequiresWorldRestart(true);
|
||||
propOrder.add(property.getName());
|
||||
currencyItems = new HashMap<>();
|
||||
for(String string : property.getStringList()){
|
||||
string = string.toLowerCase(Locale.ROOT).trim();
|
||||
String[] args = string.split(" ");
|
||||
if(args.length != 2){
|
||||
Wizardry.logger.warn("Invalid entry in currency items: {}", string);
|
||||
continue; // Ignore invalid entries, the pattern above should ensure this never happens
|
||||
}
|
||||
try {
|
||||
currencyItems.put(new ResourceLocation(args[0]), Integer.parseInt(args[1]));
|
||||
currencyItems.put(parseItemMetaString(args[0]), Integer.parseInt(args[1]));
|
||||
}catch(NumberFormatException e){
|
||||
Wizardry.logger.warn("Invalid integer in currency items: {}", args[1]);
|
||||
}
|
||||
@@ -791,7 +793,7 @@ public final class Settings {
|
||||
property = config.get(GAMEPLAY_CATEGORY, "treeBlocks", DEFAULT_TREE_BLOCKS, "List of registry names of blocks which can be overwritten by wizardry's structure generators, affecting both fast and fancy structure generation. Most tree blocks and other foliage should work automatically, but those that don't can be added manually here. Block names are not case sensitive. For mod blocks, prefix with the mod ID (e.g. dynamictrees:oakbranch).");
|
||||
property.setLanguageKey("config." + Wizardry.MODID + ".tree_blocks");
|
||||
property.setRequiresWorldRestart(true);
|
||||
treeBlocks = getResourceLocationList(property);
|
||||
treeBlocks = parseItemMetaStrings(property.getStringList());
|
||||
propOrder.add(property.getName());
|
||||
|
||||
property = config.get(WORLDGEN_CATEGORY, "oreDimensions", new int[]{0}, "List of dimension ids in which crystal ore will generate. Note that removing the overworld (id 0) from this list will make the mod VERY difficult to play!");
|
||||
@@ -1082,4 +1084,32 @@ public final class Settings {
|
||||
public static ResourceLocation[] toResourceLocations(String... strings){
|
||||
return Arrays.stream(strings).map(s -> new ResourceLocation(s.toLowerCase(Locale.ROOT).trim())).toArray(ResourceLocation[]::new);
|
||||
}
|
||||
|
||||
/** Applies {@link Settings#parseItemMetaString(String)} to each input string and returns and array of the resulting
|
||||
* {@link Pair}s. */
|
||||
@SuppressWarnings("unchecked") // Shut up java
|
||||
public static Pair<ResourceLocation, Short>[] parseItemMetaStrings(String... strings){
|
||||
return Arrays.stream(strings).map(Settings::parseItemMetaString).toArray(Pair[]::new);
|
||||
}
|
||||
|
||||
/** Parses the given input string as an item of the form {@code id:metadata} and returns the resulting
|
||||
* {@link ResourceLocation} ID and metadata value as a {@link Pair} object. */
|
||||
public static Pair<ResourceLocation, Short> parseItemMetaString(String string){
|
||||
|
||||
string = string.toLowerCase(Locale.ROOT).trim();
|
||||
|
||||
String[] itemArgs = string.split(":");
|
||||
String item;
|
||||
short meta;
|
||||
|
||||
try {
|
||||
meta = Short.parseShort(itemArgs[itemArgs.length-1]);
|
||||
item = String.join("", Arrays.copyOfRange(itemArgs, 0, itemArgs.length-2));
|
||||
}catch(NumberFormatException e){ // If no metadata is specified
|
||||
meta = 0;
|
||||
item = string;
|
||||
}
|
||||
|
||||
return Pair.of(new ResourceLocation(item), meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ public final class WizardryEventHandler {
|
||||
EntityLivingBase attacker = (EntityLivingBase)event.getSource().getTrueSource();
|
||||
|
||||
// Players can only ever attack with their main hand, so this is the right method to use here.
|
||||
if(!attacker.getHeldItemMainhand().isEmpty() && ImbueWeapon.isSword(attacker.getHeldItemMainhand().getItem())){
|
||||
if(!attacker.getHeldItemMainhand().isEmpty() && ImbueWeapon.isSword(attacker.getHeldItemMainhand())){
|
||||
|
||||
int level = EnchantmentHelper.getEnchantmentLevel(WizardryEnchantments.flaming_weapon,
|
||||
attacker.getHeldItemMainhand());
|
||||
|
||||
@@ -120,9 +120,9 @@ public interface Imbuement {
|
||||
|
||||
ItemStack bow = archer.getHeldItemMainhand();
|
||||
|
||||
if(!ImbueWeapon.isBow(bow.getItem())){
|
||||
if(!ImbueWeapon.isBow(bow)){
|
||||
bow = archer.getHeldItemOffhand();
|
||||
if(!ImbueWeapon.isBow(bow.getItem())) return;
|
||||
if(!ImbueWeapon.isBow(bow)) return;
|
||||
}
|
||||
|
||||
// Taken directly from ItemBow, so it works exactly the same as the power enchantment.
|
||||
|
||||
@@ -50,6 +50,7 @@ import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@@ -587,12 +588,14 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp
|
||||
|
||||
// TODO: Switch all of this over to some kind of loot pool system?
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ItemStack getRandomPrice(Tier tier){
|
||||
|
||||
Map<ResourceLocation, Integer> map = Wizardry.settings.currencyItems;
|
||||
Map<Pair<ResourceLocation, Short>, Integer> map = Wizardry.settings.currencyItems;
|
||||
// This isn't that efficient but it's not called very often really so it doesn't matter
|
||||
ResourceLocation itemName = map.keySet().toArray(new ResourceLocation[0])[rand.nextInt(map.size())];
|
||||
Item item = Item.REGISTRY.getObject(itemName);
|
||||
Pair<ResourceLocation, Short> itemName = map.keySet().toArray(new Pair[0])[rand.nextInt(map.size())];
|
||||
Item item = Item.REGISTRY.getObject(itemName.getLeft());
|
||||
short meta = itemName.getRight();
|
||||
int value;
|
||||
|
||||
if(item == null){
|
||||
@@ -606,7 +609,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp
|
||||
// ((tier.ordinal() + 1) * 16 + rand.nextInt(6)) gives a 'value' for the item being bought
|
||||
// This is then divided by the value of the currency item to give a price
|
||||
// The absolute maximum stack size that can result from this calculation (with value = 1) is 64.
|
||||
return new ItemStack(item, (8 + tier.ordinal() * 16 + rand.nextInt(9)) / value);
|
||||
return new ItemStack(item, (8 + tier.ordinal() * 16 + rand.nextInt(9)) / value, meta);
|
||||
}
|
||||
|
||||
private ItemStack getRandomItemOfTier(Tier tier){
|
||||
|
||||
@@ -375,7 +375,7 @@ public class ItemArtefact extends Item {
|
||||
if(artefact == WizardryItems.ring_battlemage){
|
||||
|
||||
if(player.getHeldItemOffhand().getItem() instanceof ISpellCastingItem
|
||||
&& ImbueWeapon.isSword(player.getHeldItemMainhand().getItem())){
|
||||
&& ImbueWeapon.isSword(player.getHeldItemMainhand())){
|
||||
modifiers.set(SpellModifiers.POTENCY, 1.1f * potency, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@@ -65,11 +66,14 @@ public class Divination extends Spell {
|
||||
|
||||
List<BlockPos> sphere = WizardryUtilities.getBlockSphere(caster.getPosition(), range);
|
||||
|
||||
sphere.removeIf(b -> !(world.getBlockState(b).getBlock() instanceof BlockOre
|
||||
|| world.getBlockState(b).getBlock() instanceof BlockRedstoneOre
|
||||
|| world.getBlockState(b).getBlock() instanceof BlockCrystalOre
|
||||
|| Arrays.asList(Wizardry.settings.divinationOreWhitelist)
|
||||
.contains(world.getBlockState(b).getBlock().getRegistryName())));
|
||||
sphere.removeIf(b -> {
|
||||
Block block = world.getBlockState(b).getBlock();
|
||||
return !(block instanceof BlockOre
|
||||
|| block instanceof BlockRedstoneOre
|
||||
|| block instanceof BlockCrystalOre
|
||||
|| Arrays.asList(Wizardry.settings.divinationOreWhitelist)
|
||||
.contains(Pair.of(block.getRegistryName(), block.getMetaFromState(world.getBlockState(b)))));
|
||||
});
|
||||
|
||||
Strength strength = Strength.NOTHING;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FlamingWeapon extends Spell {
|
||||
|
||||
for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){
|
||||
|
||||
if((ImbueWeapon.isSword(stack.getItem()) || ImbueWeapon.isBow(stack.getItem()))
|
||||
if((ImbueWeapon.isSword(stack) || ImbueWeapon.isBow(stack))
|
||||
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.flaming_weapon)){
|
||||
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
|
||||
// weird float processing doesn't incorrectly round it down.
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FreezingWeapon extends Spell {
|
||||
|
||||
for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){
|
||||
|
||||
if((ImbueWeapon.isSword(stack.getItem()) || ImbueWeapon.isBow(stack.getItem()))
|
||||
if((ImbueWeapon.isSword(stack) || ImbueWeapon.isBow(stack))
|
||||
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.freezing_weapon)){
|
||||
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
|
||||
// weird float processing doesn't incorrectly round it down.
|
||||
|
||||
@@ -11,9 +11,13 @@ import electroblob.wizardry.util.SpellModifiers;
|
||||
import electroblob.wizardry.util.WizardryUtilities;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemBow;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -32,7 +36,7 @@ public class ImbueWeapon extends Spell {
|
||||
|
||||
for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){
|
||||
|
||||
if(isSword(stack.getItem())
|
||||
if(isSword(stack)
|
||||
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.magic_sword)
|
||||
&& WizardData.get(caster).getImbuementDuration(WizardryEnchantments.magic_sword) <= 0){
|
||||
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
|
||||
@@ -44,7 +48,7 @@ public class ImbueWeapon extends Spell {
|
||||
WizardData.get(caster).setImbuementDuration(WizardryEnchantments.magic_sword,
|
||||
(int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)));
|
||||
|
||||
}else if(isBow(stack.getItem())
|
||||
}else if(isBow(stack)
|
||||
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.magic_bow)
|
||||
&& WizardData.get(caster).getImbuementDuration(WizardryEnchantments.magic_bow) <= 0){
|
||||
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
|
||||
@@ -77,13 +81,13 @@ public class ImbueWeapon extends Spell {
|
||||
}
|
||||
|
||||
/** Returns true if the given item counts as a sword, i.e. it extends {@link ItemSword} or is in the whitelist. */
|
||||
public static boolean isSword(Item item){
|
||||
return item instanceof ItemSword || Arrays.asList(Wizardry.settings.swordItemWhitelist).contains(item.getRegistryName());
|
||||
public static boolean isSword(ItemStack stack){
|
||||
return stack.getItem() instanceof ItemSword || Arrays.asList(Wizardry.settings.swordItemWhitelist).contains(Pair.of(stack.getItem().getRegistryName(), stack.getMetadata()));
|
||||
}
|
||||
|
||||
/** Returns true if the given item counts as a bow, i.e. it extends {@link ItemBow} or is in the whitelist. */
|
||||
public static boolean isBow(Item item){
|
||||
return item instanceof ItemBow || Arrays.asList(Wizardry.settings.bowItemWhitelist).contains(item.getRegistryName());
|
||||
public static boolean isBow(ItemStack stack){
|
||||
return stack.getItem() instanceof ItemBow || Arrays.asList(Wizardry.settings.bowItemWhitelist).contains(Pair.of(stack.getItem().getRegistryName(), stack.getMetadata()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -37,9 +38,9 @@ public class PocketFurnace extends Spell {
|
||||
|
||||
result = FurnaceRecipes.instance().getSmeltingResult(stack);
|
||||
|
||||
if(!result.isEmpty() && !(result.getItem() instanceof ItemTool) && !(result.getItem() instanceof ItemSword)
|
||||
&& !(result.getItem() instanceof ItemArmor)
|
||||
&& !Arrays.asList(Wizardry.settings.pocketFurnaceItemBlacklist).contains(result.getItem().getRegistryName())){
|
||||
if(!result.isEmpty() && !(stack.getItem() instanceof ItemTool) && !(stack.getItem() instanceof ItemSword)
|
||||
&& !(stack.getItem() instanceof ItemArmor)
|
||||
&& !Arrays.asList(Wizardry.settings.pocketFurnaceItemBlacklist).contains(Pair.of(stack.getItem().getRegistryName(), stack.getMetadata()))){
|
||||
|
||||
if(stack.getCount() <= usesLeft){
|
||||
ItemStack stack2 = new ItemStack(result.getItem(), stack.getCount(), result.getItemDamage());
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@@ -298,11 +299,10 @@ public final class WizardryUtilities {
|
||||
* @return True if the given block is a tree block, false if not.
|
||||
*/
|
||||
public static boolean isTreeBlock(World world, BlockPos pos){
|
||||
return world.getBlockState(pos).getBlock() instanceof BlockLog
|
||||
|| world.getBlockState(pos).getBlock() instanceof BlockCactus
|
||||
|| world.getBlockState(pos).getBlock().isLeaves(world.getBlockState(pos), world, pos)
|
||||
|| world.getBlockState(pos).getBlock().isFoliage(world, pos)
|
||||
|| Arrays.asList(Wizardry.settings.treeBlocks).contains(world.getBlockState(pos).getBlock().getRegistryName());
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
return block instanceof BlockLog || block instanceof BlockCactus
|
||||
|| block.isLeaves(world.getBlockState(pos), world, pos) || block.isFoliage(world, pos)
|
||||
|| Arrays.asList(Wizardry.settings.treeBlocks).contains(Pair.of(block.getRegistryName(), block.getMetaFromState(world.getBlockState(pos))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user