Skip to content

Commit

Permalink
Merge pull request #5108 from Partonetrain/VazkiiMods-1.21.0/dev
Browse files Browse the repository at this point in the history
1.21.1 porting chore: ResourceLocation/Key
  • Loading branch information
BrokenK3yboard authored Jan 5, 2025
2 parents d64d8e9 + 827cbac commit a9afa33
Show file tree
Hide file tree
Showing 115 changed files with 282 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {

private static final ModelResourceLocation LOCATION_MODEL = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath(Quark.MOD_ID, "extra/pipe_flare"), "inventory");
private static final ModelResourceLocation LOCATION_MODEL = new ModelResourceLocation(Quark.asResource("extra/pipe_flare"), "inventory");

private final Random random = new Random();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.violetmoon.quark.addons.oddities.block.be.TinyPotatoBlockEntity;
import org.violetmoon.quark.addons.oddities.module.TinyPotatoModule;
import org.violetmoon.quark.addons.oddities.util.TinyPotatoInfo;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.content.tools.base.RuneColor;
import org.violetmoon.quark.content.tools.module.ColorRunesModule;
import org.violetmoon.quark.mixin.mixins.client.accessor.AccessorModelManager;
Expand Down Expand Up @@ -76,7 +77,7 @@ private static BakedModel getModel(String name, boolean angry) {
}

private static ResourceLocation taterLocation(String name) {
return new ResourceLocation("quark", "tiny_potato/" + normalizeName(name));
return Quark.asResource( "tiny_potato/" + normalizeName(name));
}

private static String normalizeName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class BackpackInventoryScreen extends InventoryScreen implements IQuarkButtonAllowed {

private static final ResourceLocation BACKPACK_INVENTORY_BACKGROUND = new ResourceLocation(Quark.MOD_ID, "textures/misc/backpack_gui.png");
private static final ResourceLocation BACKPACK_INVENTORY_BACKGROUND = Quark.asResource("textures/misc/backpack_gui.png");

private final Player player;
private final Map<Button, Integer> buttonYs = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.minecraft.world.entity.player.Inventory;

public class CrateScreen extends AbstractContainerScreen<CrateMenu> implements IQuarkButtonAllowed {
private static final ResourceLocation TEXTURE = new ResourceLocation(Quark.MOD_ID, "textures/gui/crate.png");
private static final ResourceLocation TEXTURE = Quark.asResource("textures/gui/crate.png");

private int lastScroll;
private int scrollOffs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class MatrixEnchantingScreen extends AbstractContainerScreen<MatrixEnchantingMenu> {

public static final ResourceLocation BACKGROUND = new ResourceLocation(Quark.MOD_ID, "textures/misc/matrix_enchanting.png");
public static final ResourceLocation BACKGROUND = Quark.asResource("textures/misc/matrix_enchanting.png");

protected final Inventory playerInv;
protected final MatrixEnchantingTableBlockEntity enchanter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public void writeToNBT(CompoundTag cmp) {
public void readFromNBT(CompoundTag cmp) {
color = cmp.getInt(TAG_COLOR);
type = cmp.getInt(TAG_TYPE);
enchant = BuiltInRegistries.ENCHANTMENT.get(new ResourceLocation(cmp.getString(TAG_ENCHANTMENT)));
enchant = BuiltInRegistries.ENCHANTMENT.get(ResourceLocation.parse(cmp.getString(TAG_ENCHANTMENT)));
level = cmp.getInt(TAG_LEVEL);
x = cmp.getInt(TAG_X);
y = cmp.getInt(TAG_Y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public final void register(ZRegister event) {

@LoadEvent
public final void setup(ZCommonSetup event) {
backpackBlockedTag = ItemTags.create(new ResourceLocation(Quark.MOD_ID, "backpack_blocked"));
backpackBlockedTag = ItemTags.create(Quark.asResource("backpack_blocked"));
}

@PlayEvent
Expand Down Expand Up @@ -193,7 +193,7 @@ public void clientSetup(ZClientSetup e) {
e.enqueueWork(() -> {
MenuScreens.register(menyType, BackpackInventoryScreen::new);

ItemProperties.register(backpack, new ResourceLocation("has_items"),
ItemProperties.register(backpack, Quark.asResource("has_items"),
(stack, world, entity, i) -> (!BackpackModule.superOpMode && BackpackItem.doesBackpackHaveItems(stack)) ? 1 : 0);

QuarkClient.ZETA_CLIENT.setHumanoidArmorModel(backpack.asItem(), (living, stack, slot, original) -> ModelHandler.armorModel(ModelHandler.backpack, slot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class MagnetsModule extends ZetaModule {
@Config(description = "The maximum hardness of a block that a stonecutter pushed by magnets can cut through.")
public static double stoneCutterMaxHardness = 3;

public static final TagKey<EntityType<?>> magneticEntities = TagKey.create(Registries.ENTITY_TYPE, Quark.asResource("affected_by_magnets"));
public static final TagKey<EntityType<?>> magneticEntities = Quark.asTagKey(Registries.ENTITY_TYPE,"affected_by_magnets");

@Hint
public static Block magnet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private Influence parseEnchantmentList(String enchantmentList) {
if(damp)
enchStr = enchStr.substring(1);

Enchantment ench = BuiltInRegistries.ENCHANTMENT.get(new ResourceLocation(enchStr));
Enchantment ench = BuiltInRegistries.ENCHANTMENT.get(ResourceLocation.parse(enchStr));
if(ench != null) {
if(damp)
dampen.add(ench);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public final void register(ZRegister event) {

@LoadEvent
public final void setup(ZCommonSetup event) {
pipesTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "pipes"));
pipesTag = BlockTags.create(Quark.asResource("pipes"));
}

@LoadEvent
Expand All @@ -84,7 +84,7 @@ public final void clientSetup(ZClientSetup event) {

@LoadEvent
public void registerAdditionalModels(ZAddModels event) {
event.register(new ModelResourceLocation(Quark.MOD_ID, "extra/pipe_flare", "inventory"));
event.register(new ModelResourceLocation(Quark.asResource("extra/pipe_flare"), "inventory"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public final void register(ZRegister event) {
public static class Client extends TinyPotatoModule {
@LoadEvent
public void modelBake(ZModel.ModifyBakingResult event) {
ResourceLocation tinyPotato = new ModelResourceLocation(new ResourceLocation("quark", "tiny_potato"), "inventory");
Map<ResourceLocation, BakedModel> map = event.getModels();
ModelResourceLocation tinyPotato = ModelResourceLocation.inventory(Quark.asResource("tiny_potato"));
Map<ModelResourceLocation, BakedModel> map = event.getModels();
BakedModel originalPotato = map.get(tinyPotato);
map.put(tinyPotato, new TinyPotatoModel(originalPotato));
}
Expand All @@ -84,7 +84,7 @@ private void registerTaters(ZAddModels event, String mod, Set<String> usedNames,
usedNames.add(path);

path = path.substring("models/".length(), path.length() - ".json".length());
event.register(new ResourceLocation("quark", path));
event.register(Quark.asResource(path));
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/violetmoon/quark/base/Quark.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.neoforged.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -56,12 +57,15 @@ public Quark() {
if (!ZETA.isProduction) // force all mixins to load in dev
MixinEnvironment.getCurrentEnvironment().audit();
}

public static ResourceLocation asResource(String name) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, name);
public static ResourceLocation asResource(String path) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
}

public static <T> ResourceKey<T> asResourceKey(ResourceKey<? extends Registry<T>> base, String name) {
return ResourceKey.create(base, asResource(name));
}

public static <T> TagKey<T> asTagKey(ResourceKey<? extends Registry<T>> base, String name) {
return TagKey.create(base, asResource(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// TODO: push these event handlers into their respective modules
public class CapabilityHandler {
private static final ResourceLocation DROPOFF_MANAGER = new ResourceLocation(Quark.MOD_ID, "dropoff");
private static final ResourceLocation SORTING_HANDLER = new ResourceLocation(Quark.MOD_ID, "sort");
private static final ResourceLocation MAGNET_TRACKER = new ResourceLocation(Quark.MOD_ID, "magnet_tracker");
private static final ResourceLocation RUNE_COLOR_HANDLER = new ResourceLocation(Quark.MOD_ID, "rune_color");
private static final ResourceLocation DROPOFF_MANAGER = Quark.asResource("dropoff");
private static final ResourceLocation SORTING_HANDLER = Quark.asResource("sort");
private static final ResourceLocation MAGNET_TRACKER = Quark.asResource("magnet_tracker");
private static final ResourceLocation RUNE_COLOR_HANDLER = Quark.asResource("rune_color");

@PlayEvent
public static void attachItemCapabilities(ZAttachCapabilities.ItemStackCaps event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class QuarkConfigHomeScreen extends ZetaConfigHomeScreen {

private static final CubeMap CUBE_MAP = new CubeMap(new ResourceLocation(Quark.MOD_ID, "textures/misc/panorama/panorama"));
private static final CubeMap CUBE_MAP = new CubeMap(Quark.asResource("textures/misc/panorama/panorama"));
private static final PanoramaRenderer PANORAMA = new PanoramaRenderer(CUBE_MAP);
private float time;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class SocialButton extends Button {

public static final ResourceLocation SOCIAL_ICONS = ResourceLocation.fromNamespaceAndPath(Quark.MOD_ID, "textures/gui/social_icons.png");
public static final ResourceLocation SOCIAL_ICONS = Quark.asResource("textures/gui/social_icons.png");

private final int textColor;
private final int socialId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class ClientUtil {

public static final ResourceLocation GENERAL_ICONS = new ResourceLocation(Quark.MOD_ID, "textures/gui/general_icons.png");
public static final ResourceLocation GENERAL_ICONS = Quark.asResource("textures/gui/general_icons.png");

private static int progress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static ModelLayerLocation addArmorModel(String name, Supplier<LayerDefin
}

private static ModelLayerLocation addLayer(String name, Layer layer) {
ModelLayerLocation loc = new ModelLayerLocation(new ResourceLocation(Quark.MOD_ID, name), "main");
ModelLayerLocation loc = new ModelLayerLocation(Quark.asResource(name), "main");
layers.put(loc, layer);
return loc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public QuarkBoatRenderer(EntityRendererProvider.Context context, boolean chest)
private static Map<String, BoatModelTuple> computeBoatResources(boolean chest, EntityRendererProvider.Context context) {
return WoodSetHandler.boatTypes().collect(ImmutableMap.toImmutableMap(Functions.identity(), name -> {
String folder = chest ? "chest_boat" : "boat";
ResourceLocation texture = new ResourceLocation(Quark.MOD_ID, "textures/model/entity/" + folder + "/" + name + ".png");
ResourceLocation texture = Quark.asResource("textures/model/entity/" + folder + "/" + name + ".png");
BoatModel model = (chest) ? new ChestBoatModel(context.bakeLayer(ModelHandler.quark_boat_chest)) : new BoatModel(context.bakeLayer(ModelHandler.quark_boat));

return new BoatModelTuple(texture, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static void onRenderPlayer(ZRenderPlayer.Post event) {
if(clientPlayer.isCapeLoaded()) {
PlayerInfo info = clientPlayer.playerInfo;
Map<MinecraftProfileTexture.Type, ResourceLocation> textures = info.textureLocations;
ResourceLocation loc = new ResourceLocation("quark", "textures/misc/dev_cape.png");
ResourceLocation loc = Quark.asResource("textures/misc/dev_cape.png");
textures.put(MinecraftProfileTexture.Type.CAPE, loc);
textures.put(MinecraftProfileTexture.Type.ELYTRA, loc);
done.add(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static <T> void remapAll(MissingMappingsEvent event, DefaultedRegistry<T
for (var v : event.getMappings(block.key(), Quark.MOD_ID)) {
String rem = REMAP.get(v.getKey().toString());
if (rem != null) {
var b = block.getOptional(new ResourceLocation(rem));
var b = block.getOptional(ResourceLocation.parse(rem));
b.ifPresent(v::remap);
} else v.ignore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void start(ZRegister e) {
}

public static SoundEvent register(String name) {
SoundEvent event = SoundEvent.createVariableRangeEvent(new ResourceLocation(Quark.MOD_ID, name));
SoundEvent event = SoundEvent.createVariableRangeEvent(Quark.asResource(name));
REGISTRY_DEFERENCE.add(event);
return event;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ else if(o instanceof Block block)
else if(o instanceof ItemStack stack)
itemList.add(stack.getItem());
else if(o instanceof String s) {
Item item = BuiltInRegistries.ITEM.get(new ResourceLocation(s));
Item item = BuiltInRegistries.ITEM.get(ResourceLocation.parse(s));
if(item != Items.AIR)
itemList.add(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ public ExclusionRecipe fromJson(@NotNull ResourceLocation recipeId, @NotNull Jso
JsonArray excluded = GsonHelper.getAsJsonArray(json, "exclusions");
List<ResourceLocation> excludedRecipes = new ArrayList<>();
for(JsonElement el : excluded) {
ResourceLocation loc = new ResourceLocation(el.getAsString());
ResourceLocation loc = ResourceLocation.parse(el.getAsString());
if(!loc.equals(recipeId))
excludedRecipes.add(loc);
}

RecipeSerializer<?> serializer = BuiltInRegistries.RECIPE_SERIALIZER.get(new ResourceLocation(trueType));
RecipeSerializer<?> serializer = BuiltInRegistries.RECIPE_SERIALIZER.get(ResourceLocation.parse(trueType));
if(serializer == null)
throw new JsonSyntaxException("Invalid or unsupported recipe type '" + trueType + "'");
Recipe<?> parent = serializer.fromJson(recipeId, json);
Expand All @@ -179,13 +179,13 @@ public ExclusionRecipe fromNetwork(@NotNull ResourceLocation recipeId, @NotNull
int exclusions = buffer.readVarInt();
List<ResourceLocation> excludedRecipes = new ArrayList<>();
for(int i = 0; i < exclusions; i++) {
ResourceLocation loc = new ResourceLocation(buffer.readUtf(32767));
ResourceLocation loc = ResourceLocation.parse(buffer.readUtf(32767));
if(!loc.equals(recipeId))
excludedRecipes.add(loc);
}
String trueType = buffer.readUtf(32767);

RecipeSerializer<?> serializer = BuiltInRegistries.RECIPE_SERIALIZER.get(new ResourceLocation(trueType));
RecipeSerializer<?> serializer = BuiltInRegistries.RECIPE_SERIALIZER.get(ResourceLocation.parse(trueType));
if(serializer == null)
throw new IllegalArgumentException("Invalid or unsupported recipe type '" + trueType + "'");
Recipe<?> parent = serializer.fromNetwork(recipeId, buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static boolean renderPistonBlock(PistonMovingBlockEntity piston, float pa
if(tile == null)
return false;
CompoundTag tileTag = PistonsMoveTileEntitiesModule.getMovingBlockEntityData(piston.getLevel(), truePos);
if(tileTag != null && tile.getType() == BuiltInRegistries.BLOCK_ENTITY_TYPE.get(new ResourceLocation(tileTag.getString("id"))))
if(tileTag != null && tile.getType() == BuiltInRegistries.BLOCK_ENTITY_TYPE.get(ResourceLocation.parse(tileTag.getString("id"))))
tile.load(tileTag);
Vec3 offset = new Vec3(piston.getXOff(partialTicks), piston.getYOff(partialTicks), piston.getZOff(partialTicks));
return renderTESafely(piston.getLevel(), truePos, state, tile, piston, partialTicks, offset, matrix, bufferIn, combinedLightIn, combinedOverlayIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
public class FeedingTroughModule extends ZetaModule {

//using a ResourceKey because they're interned, and Holder.Reference#is leverages this for a very efficient implementation
private static final ResourceKey<PoiType> FEEDING_TROUGH_POI_KEY = ResourceKey.create(Registries.POINT_OF_INTEREST_TYPE, Quark.asResource("feeding_trough"));
private static final ResourceKey<PoiType> FEEDING_TROUGH_POI_KEY = Quark.asResourceKey(Registries.POINT_OF_INTEREST_TYPE, "feeding_trough");
private static final Set<FakePlayer> FREE_FAKE_PLAYERS = new HashSet<>();
//fake players created are either stored here above or in the cache below.
//this way each animal has its own player which is needed as they are moved in diff pos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.violetmoon.quark.content.automation.module;

import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -33,6 +34,6 @@ public final void register(ZRegister event) {

@LoadEvent
public final void setup(ZCommonSetup event) {
ironRodImmuneTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "iron_rod_immune"));
ironRodImmuneTag = Quark.asTagKey(Registries.BLOCK,"iron_rod_immune"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static BlockEntity loadBlockEntitySafe(Level level, BlockPos pos, Compou
if(inWorldEntity == null) {
Quark.LOG.warn("No block entity found at {} (expected {})", pos.toShortString(), expectedTypeStr);
return null;
} else if(inWorldEntity.getType() != BuiltInRegistries.BLOCK_ENTITY_TYPE.get(new ResourceLocation(expectedTypeStr))) {
} else if(inWorldEntity.getType() != BuiltInRegistries.BLOCK_ENTITY_TYPE.get(ResourceLocation.parse(expectedTypeStr))) {
Quark.LOG.warn("Wrong block entity found at {} (expected {}, got {})", pos.toShortString(), expectedTypeStr, BlockEntityType.getKey(inWorldEntity.getType()));
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Material getMaterial(ChestBlockEntity tile, ChestType type) {
else
tex.append(choose(type, "normal", "left", "right"));

return new Material(Sheets.CHEST_SHEET, new ResourceLocation(Quark.MOD_ID, tex.toString()));
return new Material(Sheets.CHEST_SHEET, Quark.asResource(tex.toString()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

public class GlassItemFrameRenderer extends EntityRenderer<GlassItemFrame> {

private static final ModelResourceLocation LOCATION_MODEL = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath(Quark.MOD_ID, "extra/glass_item_frame"), "inventory");
private static final ModelResourceLocation LOCATION_MODEL = new ModelResourceLocation(Quark.asResource("extra/glass_item_frame"), "inventory");

private static final List<Direction> SIGN_DIRECTIONS = List.of(Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.violetmoon.quark.content.building.module;

import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void postRegister(ZRegister.Post e) {

@LoadEvent
public final void setup(ZCommonSetup event) {
hedgesTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "hedges"));
hedgesTag = Quark.asTagKey(Registries.BLOCK,"hedges");
}

@ZetaLoadModule(clientReplacement = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import net.minecraft.core.registries.Registries;
import org.violetmoon.quark.api.ICrawlSpaceBlock;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.content.building.block.HollowLogBlock;
Expand Down Expand Up @@ -64,7 +65,7 @@ public final void register(ZRegister event) {

@LoadEvent
public final void setup(ZCommonSetup event) {
hollowLogsTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "hollow_logs"));
hollowLogsTag = Quark.asTagKey(Registries.BLOCK, "hollow_logs");
}

@PlayEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.violetmoon.quark.content.building.module;

import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -35,7 +36,7 @@ public static boolean isCorundum() {

@LoadEvent
public final void setup(ZCommonSetup event) {
lampTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "crystal_lamp"));
lampTag = Quark.asTagKey(Registries.BLOCK, "crystal_lamp");
}

@LoadEvent
Expand Down
Loading

0 comments on commit a9afa33

Please sign in to comment.