From 739a1573e168c3b7e72eb448c7f67344a28bb5db Mon Sep 17 00:00:00 2001 From: WinDanesz <31292708+WinDanesz@users.noreply.github.com> Date: Sat, 10 Sep 2022 02:01:49 +0200 Subject: [PATCH] feat: added support for custom Elements --- .../wizardry/api/WizardryEnumHelper.java | 8 +++++--- .../wizardry/constants/Element.java | 19 +++++++++++++++++-- .../entity/living/EntityEvilWizard.java | 3 ++- .../wizardry/entity/living/EntityWizard.java | 3 ++- .../wizardry/worldgen/WorldGenObelisk.java | 6 ++++-- .../wizardry/worldgen/WorldGenShrine.java | 9 +++++---- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main/java/electroblob/wizardry/api/WizardryEnumHelper.java b/src/main/java/electroblob/wizardry/api/WizardryEnumHelper.java index 4c73f606..52b0236c 100644 --- a/src/main/java/electroblob/wizardry/api/WizardryEnumHelper.java +++ b/src/main/java/electroblob/wizardry/api/WizardryEnumHelper.java @@ -18,7 +18,7 @@ public final class WizardryEnumHelper { // Make sure these are updated if the relevant constructors are updated! // Can't we do some kind of reflection to access them and generate these arrays? private static final Class[] TIER_ARGUMENTS = new Class[]{Integer.class, Integer.class, Integer.class, Style.class, String.class}; - private static final Class[] ELEMENT_ARGUMENTS = new Class[]{Style.class, String.class, String.class}; + private static final Class[] ELEMENT_ARGUMENTS = new Class[]{Style.class, String.class, String.class, boolean.class, boolean.class}; private static final Class[] SPELL_TYPE_ARGUMENTS = new Class[]{String.class}; private static final Class[] SPELL_CONTEXT_ARGUMENTS = new Class[]{String.class}; @@ -55,12 +55,14 @@ public final class WizardryEnumHelper { * @param colour The colour of text associated with this element, as a style object. * @param name The unlocalised name of this element, as used in translation keys. * @param modID The mod ID of the mod that added this element, for icon rendering purposes. + * @param worldgen Whether this element should have obelisks and shrines. + * @param wizards Whether this element should have naturally occurring evil and good wizards. * @return The resulting {@code Element} enum constant. */ // This is the only one that needs the mod ID argument because elements are the only ones that have icons // For some reason Minecraft doesn't seem to care about the resource domain for lang files, it just pools them - public static Element addElement(String codeName, Style colour, String name, String modID){ - return EnumHelper.addEnum(Element.class, codeName, ELEMENT_ARGUMENTS, colour, name, modID); + public static Element addElement(String codeName, Style colour, String name, String modID, boolean worldgen, boolean wizards){ + return EnumHelper.addEnum(Element.class, codeName, ELEMENT_ARGUMENTS, colour, name, modID, worldgen, wizards); } /** diff --git a/src/main/java/electroblob/wizardry/constants/Element.java b/src/main/java/electroblob/wizardry/constants/Element.java index 45658f06..3c518fbc 100644 --- a/src/main/java/electroblob/wizardry/constants/Element.java +++ b/src/main/java/electroblob/wizardry/constants/Element.java @@ -30,14 +30,23 @@ public enum Element implements IStringSerializable { /** The {@link ResourceLocation} for this element's 8x8 icon (displayed in the arcane workbench GUI) */ private final ResourceLocation icon; + private String modid; + /** true if this element should have worldgen structures generated (Obelisk, Shrine) */ + private final boolean worldgen; + /** true if evil/good wizards of this element should naturally spawn */ + private final boolean wizards; + Element(Style colour, String name){ - this(colour, name, Wizardry.MODID); + this(colour, name, Wizardry.MODID, true, true); } - Element(Style colour, String name, String modid){ + Element(Style colour, String name, String modid, boolean worldgen, boolean wizards){ this.colour = colour; this.unlocalisedName = name; this.icon = new ResourceLocation(modid, "textures/gui/container/element_icon_" + unlocalisedName + ".png"); + this.modid = modid; + this.worldgen = worldgen; + this.wizards = wizards; } /** Returns the element with the given name, or throws an {@link java.lang.IllegalArgumentException} if no such @@ -93,4 +102,10 @@ public enum Element implements IStringSerializable { public ResourceLocation getIcon(){ return icon; } + + public boolean hasWorldgen() { return worldgen; } + + public boolean hasWizards() { return wizards; } + + public String getModid() { return modid; } } diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java index baa211f0..4ed203f4 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java @@ -365,7 +365,8 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity if(getElement() == null){ if(rand.nextBoolean()){ - this.setElement(Element.values()[rand.nextInt(Element.values().length - 1) + 1]); + Element[] elements = (Element[]) Arrays.stream(Element.values()).filter(Element::hasWizards).toArray(); + this.setElement(elements[rand.nextInt(elements.length - 1) + 1]); }else{ this.setElement(Element.MAGIC); } diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java index 06d34db5..ac04fb51 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java @@ -747,7 +747,8 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp textureIndex = this.rand.nextInt(6); if(rand.nextBoolean()){ - this.setElement(Element.values()[rand.nextInt(Element.values().length - 1) + 1]); + Element[] elements = (Element[]) Arrays.stream(Element.values()).filter(Element::hasWizards).toArray(); + this.setElement(elements[rand.nextInt(elements.length - 1) + 1]); }else{ this.setElement(Element.MAGIC); } diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java index acb7610c..5a9b4ce3 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java @@ -21,6 +21,7 @@ import net.minecraft.world.gen.structure.template.Template; import net.minecraftforge.fml.common.registry.ForgeRegistries; import org.apache.commons.lang3.ArrayUtils; +import java.util.Arrays; import java.util.Map; import java.util.Random; @@ -59,8 +60,9 @@ public class WorldGenObelisk extends WorldGenSurfaceStructure { @Override public void spawnStructure(Random random, World world, BlockPos origin, Template template, PlacementSettings settings, ResourceLocation structureFile){ - final Element element = Element.values()[1 + random.nextInt(Element.values().length-1)]; - Block runeStone = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Wizardry.MODID, element.getName().toLowerCase() + "_runestone")); + Element[] elements = (Element[]) Arrays.stream(Element.values()).filter(Element::hasWorldgen).toArray(); + final Element element = elements[1 + random.nextInt(elements.length-1)]; + Block runeStone = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(element.getModid(), element.getName().toLowerCase() + "_runestone")); ITemplateProcessor processor = (w, p, i) -> i.blockState.getBlock() instanceof BlockRunestone ? new Template.BlockInfo( i.pos, runeStone.getDefaultState(), i.tileentityData) : i; diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java index 1b8170f6..b4b99c0d 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java @@ -1,11 +1,10 @@ package electroblob.wizardry.worldgen; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.block.BlockRunestonePedestal; import electroblob.wizardry.block.BlockRunestone; +import electroblob.wizardry.block.BlockRunestonePedestal; import electroblob.wizardry.constants.Element; import electroblob.wizardry.integration.antiqueatlas.WizardryAntiqueAtlasIntegration; -import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.spell.ArcaneLock; import electroblob.wizardry.tileentity.TileEntityShrineCore; import net.minecraft.block.Block; @@ -19,6 +18,7 @@ import net.minecraft.world.gen.structure.template.Template; import net.minecraftforge.fml.common.registry.ForgeRegistries; import org.apache.commons.lang3.ArrayUtils; +import java.util.Arrays; import java.util.Map; import java.util.Random; import java.util.UUID; @@ -51,8 +51,9 @@ public class WorldGenShrine extends WorldGenSurfaceStructure { @Override public void spawnStructure(Random random, World world, BlockPos origin, Template template, PlacementSettings settings, ResourceLocation structureFile){ - final Element element = Element.values()[1 + random.nextInt(Element.values().length-1)]; - Block runeStone = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Wizardry.MODID, element.getName().toLowerCase() + "_runestone")); + Element[] elements = (Element[]) Arrays.stream(Element.values()).filter(Element::hasWorldgen).toArray(); + final Element element = elements[1 + random.nextInt(elements.length-1)]; + Block runeStone = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(element.getModid(), element.getName().toLowerCase() + "_runestone")); ITemplateProcessor processor = (w, p, i) -> i.blockState.getBlock() instanceof BlockRunestone ? new Template.BlockInfo( i.pos, runeStone.getDefaultState(), i.tileentityData) : i;