Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 16, 2024
1 parent 2a9eaf3 commit 15fcd02
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17 # Minimum supported by Minecraft
21 # Minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-latest]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (Permissions.check(player, "locki.access.inventory.armor.head", true)) {
// nothing is locking the head slot
}
```
For a list of default inventory nodes, see [DefaultInventoryNodes.java](src/main/java/io/github/ladysnake/locki/DefaultInventoryNodes.java).
For a list of default inventory nodes, see [DefaultInventoryNodes.java](src/main/java/org/ladysnake/locki/DefaultInventoryNodes.java).
Simply prepend the desired node's full path with `locki.access.` before checking.

## Adding Locki to your project
Expand Down Expand Up @@ -69,8 +69,8 @@ dependencies {
include "org.ladysnake:locki:${locki_version}"
// locki dependencies
include "me.lucko:fabric-permissions-api:${fpa_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}"
include "org.ladysnake.cardinal-components-api:cardinal-components-base:${cca_version}"
include "org.ladysnake.cardinal-components-api:cardinal-components-entity:${cca_version}"
}
```

Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ chenille {
}

license = 'LGPL'
javaVersion = 17
javaVersion = 21
}

repositories {
mavenCentral()
mavenLocal()
chenille.repositories {
cursemaven()
modrinth()
ladysnake()
lucko()
jitpack()
Expand All @@ -54,13 +54,13 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

modIncludeImplementation ("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}") { transitive = false }
modIncludeImplementation ("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}") { transitive = false }
modIncludeImplementation ("org.ladysnake.cardinal-components-api:cardinal-components-base:${cca_version}") { transitive = false }
modIncludeImplementation ("org.ladysnake.cardinal-components-api:cardinal-components-entity:${cca_version}") { transitive = false }
modIncludeImplementation "me.lucko:fabric-permissions-api:${fpa_version}"

compileOnly "com.demonwav.mcdev:annotations:1.0"

modCompileOnly "curse.maven:backslot-402739:${backslot_version}" // not updated yet
modCompileOnly "maven.modrinth:backslot:${backslot_version}" // not updated yet
modLocalRuntime ("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { transitive = false }

modLocalRuntime ("com.terraformersmc:modmenu:${modmenu_version}") { transitive = false }
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
------------------------------------------------------
Version 0.13.0
------------------------------------------------------
Updated to 1.21

------------------------------------------------------
Version 0.12.0
------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ org.gradle.jvmargs=-Xmx3G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version = 1.20.4
quilt_mappings = 3
minecraft_version = 1.21
quilt_mappings = 1
loader_version=0.26.0

# Mod Properties
mod_version = 0.12.0
mod_version = 0.13.0
maven_group = org.ladysnake
archives_base_name = locki

# Dependencies
fabric_api_version = 0.97.1+1.20.4
cca_version = 5.4.0
fabric_api_version = 0.100.1+1.21
cca_version = 6.1.0
fpa_version=0.2-SNAPSHOT
# V1.2.12
backslot_version=4178145
cloth_config_version=11.1.118
modmenu_version=9.2.0-beta.2
elmendorf_version=0.12.0
backslot_version=1.2.15+1.20.6
cloth_config_version=15.0.127
modmenu_version=11.0.0-rc.2
elmendorf_version=0.13.0
# Publishing
owners = Ladysnake
display_name = Locki
license_header = LGPL
gpl_version = 3
curseforge_id = 483059
modrinth_id = qS8U15sj
curseforge_versions = 1.20.4
curseforge_versions = 1.21
cf_requirements = qsl
cf_embeddeds = cardinal-components-api
release_type = beta
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static InventoryNode get(EquipmentSlot equipmentSlot) {
case LEGS -> LEGS;
case CHEST -> CHEST;
case HEAD -> HEAD;
case BODY -> MAIN_INVENTORY;
};
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/ladysnake/locki/Locki.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.PermissionCheckEvent;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.command.argument.SingletonArgumentInfo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -52,9 +50,14 @@
* @see #registerNode(InventoryNode, String)
*/
public final class Locki implements ModInitializer {
public static final String MOD_ID = "locki";
public static final Logger LOGGER = LogManager.getLogger("Locki");
public static final Pattern NODE_NAME_PART = Pattern.compile("[a-z0-9_-]+");

public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}

private static final Map<Identifier, InventoryLock> locks = new HashMap<>();
private static final Map<String, InventoryNode> nodes = new HashMap<>();
private static int nextId;
Expand Down Expand Up @@ -154,8 +157,8 @@ public static Stream<String> streamNodeNames() {
@Override
public void onInitialize() {
this.baseInit();
ArgumentTypeRegistry.registerArgumentType(new Identifier("locki", "inventory_lock"), InventoryLockArgumentType.class, SingletonArgumentInfo.contextFree(InventoryLockArgumentType::inventoryLock));
ArgumentTypeRegistry.registerArgumentType(new Identifier("locki", "inventory_node"), InventoryNodeArgumentType.class, SingletonArgumentInfo.contextFree(InventoryNodeArgumentType::inventoryNode));
ArgumentTypeRegistry.registerArgumentType(id("inventory_lock"), InventoryLockArgumentType.class, SingletonArgumentInfo.contextFree(InventoryLockArgumentType::inventoryLock));
ArgumentTypeRegistry.registerArgumentType(id("inventory_node"), InventoryNodeArgumentType.class, SingletonArgumentInfo.contextFree(InventoryNodeArgumentType::inventoryNode));
}

void baseInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
*/
package org.ladysnake.locki.impl;

import dev.onyxstudios.cca.api.v3.component.Component;
import it.unimi.dsi.fastutil.objects.Reference2BooleanMap;
import it.unimi.dsi.fastutil.objects.Reference2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.registry.HolderLookup;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.component.Component;
import org.ladysnake.locki.InventoryKeeper;
import org.ladysnake.locki.InventoryLock;
import org.ladysnake.locki.InventoryNode;
Expand Down Expand Up @@ -142,7 +143,7 @@ protected BitSet lookup(InventoryNode inventoryNode) {
}

@Override
public void readFromNbt(NbtCompound tag) {
public void readFromNbt(NbtCompound tag, HolderLookup.Provider registryLookup) {
if (tag.contains("locks", NbtElement.COMPOUND_TYPE)) {
this.clearCache();
this.getLocks().clear();
Expand All @@ -169,7 +170,7 @@ public void readFromNbt(NbtCompound tag) {
}

@Override
public void writeToNbt(NbtCompound tag) {
public void writeToNbt(NbtCompound tag, HolderLookup.Provider registryLookup) {
NbtCompound dict = new NbtCompound();
for (Map.Entry<InventoryNode, Reference2BooleanMap<InventoryLock>> nodeEntry : this.getLocks().entrySet()) {
NbtList list = new NbtList();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ladysnake/locki/impl/LockiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.ladysnake.locki.DefaultInventoryNodes;
import org.ladysnake.locki.InventoryLockingChangeCallback;
import org.ladysnake.locki.InventoryNode;
import org.quiltmc.loader.api.ModContainer;
import org.ladysnake.locki.Locki;

public class LockiClient implements ClientModInitializer {
public static final Identifier LOCKED_SLOT_SPRITE = new Identifier("locki", "gui/locked_slot");
public static final Identifier LOCKED_SLOT_SPRITE = Locki.id("gui/locked_slot");

private static void updateCraftingBookVisibility(PlayerEntity player, InventoryNode invNode, boolean locked) {
MinecraftClient mc = MinecraftClient.getInstance();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/ladysnake/locki/impl/LockiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.ladysnake.locki.InventoryLock;
import org.ladysnake.locki.InventoryNode;
import org.ladysnake.locki.Locki;
Expand All @@ -38,7 +37,7 @@
import static org.ladysnake.locki.impl.InventoryLockArgumentType.inventoryLock;

public final class LockiCommand {
public static final InventoryLock COMMAND_LOCK = Locki.registerLock(new Identifier("locki", "commands"), true);
public static final InventoryLock COMMAND_LOCK = Locki.registerLock(Locki.id("commands"), true);

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("locki")
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/ladysnake/locki/impl/LockiComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
package org.ladysnake.locki.impl;

import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer;
import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.component.ComponentKey;
import org.ladysnake.cca.api.v3.component.ComponentRegistry;
import org.ladysnake.cca.api.v3.entity.EntityComponentFactoryRegistry;
import org.ladysnake.cca.api.v3.entity.EntityComponentInitializer;
import org.ladysnake.cca.api.v3.entity.RespawnCopyStrategy;
import org.ladysnake.locki.Locki;

public final class LockiComponents implements EntityComponentInitializer {
public static final ComponentKey<InventoryKeeperBase> INVENTORY_KEEPER = ComponentRegistry.getOrCreate(new Identifier("locki", "inventory_keeper"), InventoryKeeperBase.class);
public static final ComponentKey<InventoryKeeperBase> INVENTORY_KEEPER = ComponentRegistry.getOrCreate(Locki.id("inventory_keeper"), InventoryKeeperBase.class);

@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import it.unimi.dsi.fastutil.objects.Reference2BooleanMap;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent;
import org.ladysnake.locki.DefaultInventoryNodes;
import org.ladysnake.locki.InventoryKeeper;
import org.ladysnake.locki.InventoryLock;
Expand Down Expand Up @@ -74,7 +74,7 @@ public boolean shouldSyncWith(ServerPlayerEntity player) {
}

@Override
public void writeSyncPacket(PacketByteBuf buf, ServerPlayerEntity recipient) {
public void writeSyncPacket(RegistryByteBuf buf, ServerPlayerEntity recipient) {
buf.writeVarInt(this.cache.size());
for (Map.Entry<InventoryNode, BitSet> entry : this.getCache().entrySet()) {
// Could compress this by not repeating ancestors?
Expand All @@ -84,7 +84,7 @@ public void writeSyncPacket(PacketByteBuf buf, ServerPlayerEntity recipient) {
}

@Override
public void applySyncPacket(PacketByteBuf buf) {
public void applySyncPacket(RegistryByteBuf buf) {
int size = buf.readVarInt();
this.clearCache();
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@Mixin(InputSlotFiller.class)
public abstract class InputSlotFillerMixin {
@Shadow protected AbstractRecipeScreenHandler<?> handler;
@Shadow protected AbstractRecipeScreenHandler<?, ?> handler;

@WrapOperation(method = "fillInputSlots(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/recipe/RecipeHolder;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/RecipeMatcher;match(Lnet/minecraft/recipe/Recipe;Lit/unimi/dsi/fastutil/ints/IntList;)Z"))
private boolean blockInventoryCrafting(RecipeMatcher instance, Recipe<?> recipe, IntList output, Operation<Boolean> original, ServerPlayerEntity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.class_9779;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.hud.in_game.InGameHud;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -54,12 +55,12 @@ public abstract class InGameHudMixin {
protected abstract PlayerEntity getCameraPlayer();

@Inject(
method = "renderHotbar",
method = "renderSurvivalHotbar",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V"),
allow = 1,
cancellable = true
)
private void checkInventoryLimit(float tickDelta, GuiGraphics graphics, CallbackInfo ci) {
private void checkInventoryLimit(GuiGraphics graphics, class_9779 arg, CallbackInfo ci) {
this.renderMainHandOnly = false;
InventoryKeeper inventoryKeeper = InventoryKeeper.get(this.getCameraPlayer());
if (inventoryKeeper.isLocked(DefaultInventoryNodes.MAIN_HAND)) {
Expand All @@ -69,7 +70,7 @@ private void checkInventoryLimit(float tickDelta, GuiGraphics graphics, Callback
}
}

@ModifyVariable(method = "renderHotbar", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/player/PlayerEntity;getOffHandStack()Lnet/minecraft/item/ItemStack;"))
@ModifyVariable(method = "renderSurvivalHotbar", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/player/PlayerEntity;getOffHandStack()Lnet/minecraft/item/ItemStack;"))
private ItemStack lockOffHand(ItemStack base) {
if (InventoryKeeper.get(this.getCameraPlayer()).isLocked(DefaultInventoryNodes.OFF_HAND)) {
return ItemStack.EMPTY;
Expand All @@ -78,7 +79,7 @@ private ItemStack lockOffHand(ItemStack base) {
}

@WrapOperation(
method = "renderHotbar",
method = "renderSurvivalHotbar",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 0)
)
private void centerCroppedHotbar(GuiGraphics instance, Identifier texture, int x, int y, int width, int height, Operation<Void> original) {
Expand All @@ -93,7 +94,7 @@ private void centerCroppedHotbar(GuiGraphics instance, Identifier texture, int x
}

@ModifyArg(
method = "renderHotbar",
method = "renderSurvivalHotbar",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 1),
index = 1
)
Expand All @@ -105,7 +106,7 @@ private int centerSelectedSlot(int x) {
}

@ModifyArg(
method = "renderHotbar",
method = "renderSurvivalHotbar",
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 1)
Expand All @@ -118,12 +119,12 @@ private int cancelLockedItemRender(int index) {
}

@ModifyArg(
method = "renderHotbar",
method = "renderSurvivalHotbar",
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 1)
),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/in_game/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/GuiGraphics;IIFLnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V")
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/in_game/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/GuiGraphics;IILnet/minecraft/class_9779;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V")
)
private ItemStack cancelLockedItemRender(ItemStack stack) {
if (this.cancelNextItem) {
Expand All @@ -133,12 +134,12 @@ private ItemStack cancelLockedItemRender(ItemStack stack) {
}

@ModifyArg(
method = "renderHotbar",
method = "renderSurvivalHotbar",
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 1)
),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/in_game/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/GuiGraphics;IIFLnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V"),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/in_game/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/GuiGraphics;IILnet/minecraft/class_9779;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V"),
index = 1
)
private int shiftMainHandItem(int x) {
Expand Down
Loading

0 comments on commit 15fcd02

Please sign in to comment.