Skip to content

Commit

Permalink
Clean up ResourceLocation creation
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jan 1, 2025
1 parent fb123c2 commit 392e321
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 86 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/legobmw99/allomancy/Allomancy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.legobmw99.allomancy.modules.powers.network.Network;
import com.legobmw99.allomancy.util.AllomancyConfig;
import com.legobmw99.allomancy.util.ItemDisplay;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
Expand All @@ -31,6 +32,9 @@ public class Allomancy {

public static final Logger LOGGER = LogManager.getLogger();

public static ResourceLocation rl(String path) {
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}

public Allomancy(IEventBus bus, ModContainer container, Dist dist) {

Expand Down
28 changes: 7 additions & 21 deletions src/main/java/com/legobmw99/allomancy/datagen/Advancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(ConsumeSetup.LERASIUM_NUGGET.get(),
Component.translatable("advancements.dna_entangled.title"),
Component.translatable("advancements.dna_entangled.desc"), null, AdvancementType.TASK, true,
Expand All @@ -58,9 +56,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(CombatSetup.MISTCLOAK.get(), Component.translatable("advancements.become_mistborn.title"),
Component.translatable("advancements.become_mistborn.desc"), null, AdvancementType.CHALLENGE,
true, true, true)
Expand All @@ -76,9 +72,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

var allMetals = Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(vial, Component.translatable("advancements.metallic_collector.title"),
Component.translatable("advancements.metallic_collector.desc"), null,
AdvancementType.CHALLENGE, true, true, false);
Expand All @@ -92,9 +86,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(CombatSetup.COIN_BAG.get(), Component.translatable("advancements.coinshot.title"),
Component.translatable("advancements.coinshot.desc"), null, AdvancementType.TASK, true, true,
false)
Expand All @@ -117,9 +109,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(CombatSetup.ALUMINUM_HELMET.get(), Component.translatable("advancements.tin_foil_hat.title"),
Component.translatable("advancements.tin_foil_hat.desc"), null, AdvancementType.TASK, true,
false, true)
Expand All @@ -139,9 +129,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/metallurgist")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(Blocks.IRON_BLOCK, Component.translatable("advancements.consequences.title"),
Component.translatable("advancements.consequences.desc"), null, AdvancementType.TASK, true,
false, true)
Expand All @@ -156,9 +144,7 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde

Advancement.Builder
.advancement()
.parent(Advancement.Builder
.advancement()
.build(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "main/coinshot")))
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/coinshot")))
.display(Blocks.BELL, Component.translatable("advancements.going_loud.title"),
Component.translatable("advancements.going_loud.desc"), null, AdvancementType.TASK, true,
true, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ private static void add(BiConsumer<ResourceLocation, EquipmentClientInfo> regist

EquipmentClientInfo
.builder()
.addLayers(EquipmentClientInfo.LayerType.HUMANOID, new EquipmentClientInfo.Layer(
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "mistcloak"),
Optional.empty(), false))
.addLayers(EquipmentClientInfo.LayerType.HUMANOID,
new EquipmentClientInfo.Layer(Allomancy.rl("mistcloak"), Optional.empty(),
false))
.build());

registrar.accept(CombatSetup.ALUMINUM.location(),

EquipmentClientInfo
.builder()
.addLayers(EquipmentClientInfo.LayerType.HUMANOID, new EquipmentClientInfo.Layer(
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "aluminum"),
Optional.empty(), false))
.addLayers(EquipmentClientInfo.LayerType.HUMANOID,
new EquipmentClientInfo.Layer(Allomancy.rl("aluminum"), Optional.empty(),
false))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.modules.powers.client.PowersClientSetup;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.common.data.ParticleDescriptionProvider;

class ParticleDescriptions extends ParticleDescriptionProvider {
Expand All @@ -14,8 +13,7 @@ protected ParticleDescriptions(PackOutput output) {

@Override
protected void addDescriptions() {
sprite(PowersClientSetup.SOUND_PARTICLE_TYPE.get(),
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "sound_particle"));
sprite(PowersClientSetup.SOUND_PARTICLE_TYPE.get(), Allomancy.rl("sound_particle"));

}
}
1 change: 0 additions & 1 deletion src/main/java/com/legobmw99/allomancy/datagen/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.*;
import net.minecraft.data.recipes.packs.VanillaRecipeProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public void appendTooltip(ITooltip tooltip, EntityAccessor accessor, IPluginConf

@Override
public ResourceLocation getUid() {
return ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "waila_bronze");
return Allomancy.rl("waila_bronze");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public final class CombatSetup {
Allomancy.MODID, "wool"));


public static final TagKey<Item> REPAIRS_MISTCLOAK =
ItemTags.create(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "repairs_wool_armor"));
public static final TagKey<Item> REPAIRS_MISTCLOAK = ItemTags.create(Allomancy.rl("repairs_wool_armor"));


private static final ArmorMaterial WOOL_ARMOR =
Expand All @@ -74,10 +73,9 @@ public final class CombatSetup {
// note: overrides normal armor, which is fine
.attributes(ItemAttributeModifiers
.builder()
.add(Attributes.MOVEMENT_SPEED, new AttributeModifier(
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID,
"mistcloak_speed"), 0.25,
AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL),
.add(Attributes.MOVEMENT_SPEED,
new AttributeModifier(Allomancy.rl("mistcloak_speed"), 0.25,
AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL),
EquipmentSlotGroup.CHEST)
.build())));

Expand All @@ -89,8 +87,7 @@ public final class CombatSetup {
"aluminum"));


public static final TagKey<Item> REPAIRS_ALUMINUM =
ItemTags.create(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "repairs_aluminum_armor"));
public static final TagKey<Item> REPAIRS_ALUMINUM = ItemTags.create(Allomancy.rl("repairs_aluminum_armor"));

private static final ArmorMaterial ALUMINUM_ARMOR =
new ArmorMaterial(15, Util.make(new EnumMap<>(ArmorType.class), map -> {
Expand Down Expand Up @@ -122,9 +119,7 @@ public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
.setShouldReceiveVelocityUpdates(true)
.setUpdateInterval(20)
.sized(0.25F, 0.25F)
.build(ResourceKey.create(Registries.ENTITY_TYPE,
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID,
"nugget_projectile"))));
.build(ResourceKey.create(Registries.ENTITY_TYPE, Allomancy.rl("nugget_projectile"))));

private CombatSetup() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.legobmw99.allomancy.Allomancy;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
Expand All @@ -19,8 +18,7 @@ public class ObsidianDaggerItem extends SwordItem {
private static final int ATTACK_DAMAGE = 23;
private static final float ATTACK_SPEED = 9.2F;

public static final TagKey<Item> OBSIDIAN_REPAIR =
ItemTags.create(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "obsidian_tool_materials"));
public static final TagKey<Item> OBSIDIAN_REPAIR = ItemTags.create(Allomancy.rl("obsidian_tool_materials"));
private static final ToolMaterial OBSIDIAN =
new ToolMaterial(BlockTags.INCORRECT_FOR_WOODEN_TOOL, 2, ATTACK_SPEED, 1.0F, ATTACK_DAMAGE,
OBSIDIAN_REPAIR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BannerPatternItem;
Expand Down Expand Up @@ -53,7 +52,7 @@ public final class ExtrasSetup {
public static final BlockCapability<IAllomanticallyUsable, Void> ALLOMANTICALLY_USABLE_BLOCK =
BlockCapability.createVoid(
// Provide a name to uniquely identify the capability.
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "allomantically_usable_block"),
Allomancy.rl("allomantically_usable_block"),
// Provide the queried type. Here, we want to look up `IItemHandler` instances.
IAllomanticallyUsable.class);

Expand Down Expand Up @@ -99,12 +98,10 @@ public final class ExtrasSetup {
for (Metal mt : Metal.values()) {

String name = mt.getName();
var pattern = ResourceKey.create(Registries.BANNER_PATTERN,
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, name));
var pattern = ResourceKey.create(Registries.BANNER_PATTERN, Allomancy.rl(name));
PATTERNS.add(pattern);

var pattern_key = TagKey.create(Registries.BANNER_PATTERN,
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, name));
var pattern_key = TagKey.create(Registries.BANNER_PATTERN, Allomancy.rl(name));
PATTERN_KEYS.add(pattern_key);

var pattern_item = ITEMS.registerItem(name + "_pattern",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
LiteralArgumentBuilder<CommandSourceStack> root = Commands.literal("allomancy").requires(permissions(0));
root.then(Commands
.literal("get")
.requires(permissions(0))
.requires(permissions(Commands.LEVEL_ALL))
.executes(ctx -> handleMultiPlayer(ctx, sender(ctx), AllomancyPowerCommand::getPowers))
.then(Commands
.argument("targets", EntityArgument.players())
Expand All @@ -62,7 +62,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {

root.then(Commands
.literal("add")
.requires(permissions(2))
.requires(permissions(Commands.LEVEL_GAMEMASTERS))
.then(Commands
.argument("type", AllomancyPowerType.INSTANCE)
.executes(ctx -> handleMultiPlayer(ctx, sender(ctx),
Expand All @@ -74,7 +74,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {

root.then(Commands
.literal("remove")
.requires(permissions(2))
.requires(permissions(Commands.LEVEL_GAMEMASTERS))
.then(Commands
.argument("type", AllomancyPowerType.INSTANCE)
.executes(ctx -> handleMultiPlayer(ctx, sender(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.api.enums.Metal;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.datafix.fixes.BannerPatternFormatFix;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -37,8 +36,7 @@ private static void onConstruct(CallbackInfo info) {
for (Metal mt : Metal.values()) {
String name = mt.getName();
Allomancy.LOGGER.info("Redirecting banner pattern for {}", name);
patternMap.put("ALLOMANCY" + name.toUpperCase(Locale.ROOT),
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, name).toString());
patternMap.put("ALLOMANCY" + name.toUpperCase(Locale.ROOT), Allomancy.rl(name).toString());
}

PATTERN_ID_MAP = patternMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.valueproviders.UniformInt;
Expand Down Expand Up @@ -49,8 +48,7 @@ private MaterialsSetup() {}
public record OreConfig(String name, int size, int placementCount, int minHeight, int maxHeight) {

<T> ResourceKey<T> getRegistryKey(ResourceKey<Registry<T>> registry, String suffix) {
return ResourceKey.create(registry,
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, this.name + suffix));
return ResourceKey.create(registry, Allomancy.rl(this.name + suffix));
}

@Override
Expand All @@ -66,8 +64,7 @@ public String toString() {
new OreConfig("zinc", 8, 12, 40, 80)};

private static final ResourceKey<BiomeModifier> ADD_ALLOMANCY_ORES =
ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS,
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "overworld_ores"));
ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, Allomancy.rl("overworld_ores"));

public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(Allomancy.MODID);
private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(Allomancy.MODID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
public final class MetalOverlay implements LayeredDraw.Layer {

private static final Point[] Frames = new Point[4];
private static final ResourceLocation meterLoc =
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "textures/gui/overlay/meter.png");
private static final ResourceLocation meterLoc = Allomancy.rl("textures/gui/overlay/meter.png");
private int currentFrame = 0;

static {
Expand All @@ -35,8 +34,7 @@ public final class MetalOverlay implements LayeredDraw.Layer {
private MetalOverlay() {}

public static void registerGUI(final RegisterGuiLayersEvent evt) {
evt.registerAboveAll(ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, "metal_display"),
new MetalOverlay());
evt.registerAboveAll(Allomancy.rl("metal_display"), new MetalOverlay());
}

private static void blit(GuiGraphics graphics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MetalSelectScreen extends Screen {
Arrays.stream(METAL_NAMES).map(s -> "metals." + s).toArray(String[]::new);
private static final ResourceLocation[] METAL_ICONS = Arrays
.stream(METAL_NAMES)
.map(s -> ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, String.format(GUI_METAL, s)))
.map(s -> Allomancy.rl(String.format(GUI_METAL, s)))
.toArray(ResourceLocation[]::new);
private final Minecraft mc;
private int timeIn = PowersConfig.animate_selection.get() ? 0 : 16;
Expand Down
Loading

0 comments on commit 392e321

Please sign in to comment.