Skip to content

Commit

Permalink
Upgrade mod to Minecraft 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Sep 12, 2024
1 parent aa9de1b commit d3b5ac2
Show file tree
Hide file tree
Showing 41 changed files with 50 additions and 57 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ archives_base_name=genshinstrument
# Dependencies
fabric_version=0.104.0+1.21.1
modmenu_version=11.0.2
forge_config_api_port_version=21.0.8
forge_config_api_port_version=21.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -44,7 +43,7 @@ public static void load() {}
private static ResourceKey<CreativeModeTab> register(final String name, final CreativeModeTab tab) {
final ResourceKey<CreativeModeTab> tabKey = ResourceKey.create(
Registries.CREATIVE_MODE_TAB,
new ResourceLocation(GInstrumentMod.MODID, name)
GInstrumentMod.loc(name)
);

Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, tabKey, tab);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cstav/genshinstrument/GInstrumentMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier;
import com.cstav.genshinstrument.sound.GISounds;
import net.fabricmc.api.ModInitializer;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -23,6 +24,11 @@ public class GInstrumentMod implements ModInitializer {
public static final String MODID = "genshinstrument";
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

public static ResourceLocation loc(final String name) {
return ResourceLocation.fromNamespaceAndPath(MODID, name);
}


@Override
public void onInitialize() {
GIPacketHandler.registerCodecs();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cstav/genshinstrument/ModModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void onRegisterModels(final RegisterAdditionalModelsEventArgs arg


private static ModelResourceLocation mrl(String path) {
return new ModelResourceLocation(GInstrumentMod.MODID, path, "inventory");
return new ModelResourceLocation(GInstrumentMod.loc(path), "inventory");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public abstract class ModBlockEntities {
// );

// private static <T extends BlockEntity> BlockEntityType<T> regsiter(final String name, final BlockEntityType<T> bet) {
// Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, new ResourceLocation(GInstrumentMod.MODID, name), bet);
// Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, GInstrumentMod.loc(name), bet);
// return bet;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public abstract class ModBlocks {


// private static Block register(final String name, final Block block) {
// Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(GInstrumentMod.MODID, name), block);
// Registry.register(BuiltInRegistries.BLOCK, GInstrumentMod.loc(name), block);
// return block;
// }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.cstav.genshinstrument.client.gui.screen.instrument.drum;

import java.util.HashMap;
import java.util.Map;

import com.cstav.genshinstrument.GInstrumentMod;
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.InstrumentScreen;
Expand All @@ -12,17 +9,19 @@
import com.cstav.genshinstrument.client.gui.screen.options.instrument.partial.InstrumentOptionsScreen;
import com.cstav.genshinstrument.client.midi.InstrumentMidiReceiver;
import com.mojang.blaze3d.platform.InputConstants.Key;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.layouts.LinearLayout;
import net.minecraft.client.gui.layouts.LinearLayout.Orientation;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

@Environment(EnvType.CLIENT)
public class AratakisGreatAndGloriousDrumScreen extends InstrumentScreen {
public static final ResourceLocation INSTRUMENT_ID = new ResourceLocation(GInstrumentMod.MODID, "glorious_drum");
public static final ResourceLocation INSTRUMENT_ID = GInstrumentMod.loc("glorious_drum");
public static final String[] NOTE_LAYOUT = {"D", "G"};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import com.cstav.genshinstrument.client.gui.screen.options.instrument.FloralZitherOptionsScreen;
import com.cstav.genshinstrument.client.gui.screen.options.instrument.partial.InstrumentOptionsScreen;
import com.cstav.genshinstrument.sound.NoteSound;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;

@Environment(EnvType.CLIENT)
public class FloralZitherScreen extends GridInstrumentScreen {
public static final ResourceLocation INSTRUMENT_ID = new ResourceLocation(GInstrumentMod.MODID, "floral_zither");
public static final ResourceLocation INSTRUMENT_ID = GInstrumentMod.loc("floral_zither");

@Override
public ResourceLocation getInstrumentId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Environment(EnvType.CLIENT)
public class NightwindHornScreen extends HeldGridInstrumentScreen {
public static final ResourceLocation INSTRUMENT_ID = new ResourceLocation(GInstrumentMod.MODID, "nightwind_horn");
public static final ResourceLocation INSTRUMENT_ID = GInstrumentMod.loc("nightwind_horn");

@Override
public ResourceLocation getInstrumentId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public ResourceLocation getResourceFromGlob(final String path) {
return getSourcePath().withPath(getGlobalRootPath() + "instrument/" + path);
}
public static ResourceLocation getInternalResourceFromGlob(final String path) {
return new ResourceLocation(GInstrumentMod.MODID, getGlobalRootPath() + path);
return GInstrumentMod.loc(getGlobalRootPath() + path);
}

public static ResourceLocation getInstrumentRootPath(final ResourceLocation instrumentId) {
Expand Down Expand Up @@ -377,8 +377,8 @@ protected Button initOptionsButton(final int vertOffset) {
protected IconToggleButton initVisibilityButton() {
return new IconToggleButton(
VISIBILITY_BUTTON_MARGIN, VISIBILITY_BUTTON_MARGIN,
new ResourceLocation(GInstrumentMod.MODID, VISIBILITY_SPRITE_LOC + "enabled.png"),
new ResourceLocation(GInstrumentMod.MODID, VISIBILITY_SPRITE_LOC + "disabled.png"),
GInstrumentMod.loc(VISIBILITY_SPRITE_LOC + "enabled.png"),
GInstrumentMod.loc(VISIBILITY_SPRITE_LOC + "disabled.png"),
(btn) -> onInstrumentRenderStateChanged(instrumentRenders())
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package com.cstav.genshinstrument.client.gui.screen.instrument.partial;

import java.awt.Color;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

import com.cstav.genshinstrument.GInstrumentMod;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.Resource;
import org.slf4j.Logger;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import org.slf4j.Logger;

import java.awt.*;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

/**
* <p>
Expand Down Expand Up @@ -229,7 +227,7 @@ private static void subscribeResourcesReloadEvent() {
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public ResourceLocation getFabricId() {
return new ResourceLocation(GInstrumentMod.MODID, "instrument_theme_loaders");
return GInstrumentMod.loc("instrument_theme_loaders");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import com.cstav.genshinstrument.client.midi.PressedMIDINote;
import com.cstav.genshinstrument.sound.GISounds;
import com.cstav.genshinstrument.sound.NoteSound;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

@Environment(EnvType.CLIENT)
public class VintageLyreScreen extends GridInstrumentScreen {
public static final ResourceLocation INSTRUMENT_ID = new ResourceLocation(GInstrumentMod.MODID, "vintage_lyre");
public static final ResourceLocation INSTRUMENT_ID = GInstrumentMod.loc("vintage_lyre");
public static final String[] NOTE_LAYOUT = new String[] {
"C", "Db", "Eb", "F", "G", "Ab", "Bb",
"C", "D", "Eb", "F", "G", "A", "Bb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.GridInstrumentScreen;
import com.cstav.genshinstrument.sound.GISounds;
import com.cstav.genshinstrument.sound.NoteSound;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;

@Environment(EnvType.CLIENT)
public class WindsongLyreScreen extends GridInstrumentScreen {
public static final ResourceLocation INSTRUMENT_ID = new ResourceLocation(GInstrumentMod.MODID, "windsong_lyre");
public static final ResourceLocation INSTRUMENT_ID = GInstrumentMod.loc("windsong_lyre");

@Override
public ResourceLocation getInstrumentId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

import com.cstav.genshinstrument.GInstrumentMod;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent;

import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.advancements.CriterionTrigger;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -21,7 +18,7 @@ public class ModCriteria {
private static <T extends CriterionTrigger<?>> T register(String name, T criterionTrigger) {
return Registry.register(
BuiltInRegistries.TRIGGER_TYPES,
new ResourceLocation(GInstrumentMod.MODID, name),
GInstrumentMod.loc(name),
criterionTrigger
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cstav/genshinstrument/item/GIItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GIItems {


private static Item register(final String id, final Item item) {
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(GInstrumentMod.MODID, id), item);
Registry.register(BuiltInRegistries.ITEM, GInstrumentMod.loc(id), item);
addToItemGroups(item);

return item;
Expand All @@ -48,7 +48,7 @@ private static void addToItemGroups(final Item item) {


private static ResourceLocation loc(final String path) {
return new ResourceLocation(GInstrumentMod.MODID, path);
return GInstrumentMod.loc(path);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -15,7 +14,7 @@
public class ModItemPredicates {

public static void register() {
ItemProperties.registerGeneric(new ResourceLocation(GInstrumentMod.MODID, "instrument_open"),
ItemProperties.registerGeneric(GInstrumentMod.loc("instrument_open"),
ModItemPredicates::instrumentOpenPredicate
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.cstav.genshinstrument.event.RegisterAdditionalModelsEvent.RegisterAdditionalModelsEventArgs;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockStateModelLoader;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelBakery.LoadedJson;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.profiling.ProfilerFiller;
Expand All @@ -23,19 +23,19 @@
public abstract class ModelBakeryMixin {

@Invoker
public abstract void invokeLoadTopLevel(ModelResourceLocation location);
public abstract void invokeLoadSpecialItemModelAndDependencies(ModelResourceLocation location);

@Inject(method = "<init>", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/resources/model/ModelBakery;loadTopLevel(Lnet/minecraft/client/resources/model/ModelResourceLocation;)V",
ordinal = 3,
target = "Lnet/minecraft/client/resources/model/ModelBakery;loadSpecialItemModelAndDependencies(Lnet/minecraft/client/resources/model/ModelResourceLocation;)V",
ordinal = 1,
shift = Shift.AFTER
))
private void initInjector(BlockColors blockColors, ProfilerFiller profilerFiller, Map<ResourceLocation, BlockModel> modelResources, Map<ResourceLocation, List<LoadedJson>> blockStateResources, CallbackInfo ci) {
private void initInjector(BlockColors blockColors, ProfilerFiller profilerFiller, Map<ResourceLocation, BlockModel> map, Map<ResourceLocation, List<BlockStateModelLoader.LoadedJson>> map2, CallbackInfo ci) {
final RegisterAdditionalModelsEventArgs args = new RegisterAdditionalModelsEventArgs();
RegisterAdditionalModelsEvent.EVENT.invoker().triggered(args);

args.getModels().forEach(this::invokeLoadTopLevel);
args.getModels().forEach(this::invokeLoadSpecialItemModelAndDependencies);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static <T extends IModPacket> StreamCodec<RegistryFriendlyByteBuf, T> cod
}

public static <T extends IModPacket> CustomPacketPayload.Type<T> type(final Class<T> packetType) {
return new Type<>(new ResourceLocation(
return new Type<>(ResourceLocation.fromNamespaceAndPath(
CommonUtil.getStaticFinalField(packetType, "MOD_ID", String.class),
path(packetType)
));
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/cstav/genshinstrument/sound/GISounds.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.cstav.genshinstrument.sound;

import com.cstav.genshinstrument.GInstrumentMod;

import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.GridInstrumentScreen;
import com.cstav.genshinstrument.sound.held.HeldNoteSound;
import com.cstav.genshinstrument.sound.registrar.HeldNoteSoundRegistrar;
import com.cstav.genshinstrument.sound.registrar.NoteSoundRegistrar;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;

public class GISounds {

Expand Down Expand Up @@ -62,10 +60,10 @@ private static NoteSound[] nightwindSoundBuilder(final NoteSoundRegistrar builde


/**
* Shorthand for {@code new ResourceLocation(GInstrumentMod.MODID, name)}
* Shorthand for {@code GInstrumentMod.loc(name)}
*/
private static ResourceLocation loc(final String name) {
return new ResourceLocation(GInstrumentMod.MODID, name);
return GInstrumentMod.loc(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static List<Player> getPlayersInArea(final Level level, final AABB area)
* @return The resource contained in the specified directory
*/
public static ResourceLocation getResourceFrom(final ResourceLocation dir, final String path) {
return new ResourceLocation(
return ResourceLocation.fromNamespaceAndPath(
dir.getNamespace(),
dir.getPath() + "/" + path
);
Expand Down

0 comments on commit d3b5ac2

Please sign in to comment.