Skip to content

Commit

Permalink
Remove dependency on QSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 16, 2024
1 parent 25fc288 commit 2a9eaf3
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies {
mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:intermediary-v2"
modImplementation "org.quiltmc:quilt-loader:${project.loader_version}"

modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${quilted_fabric_api_version}"
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 }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx3G
archives_base_name = locki

# Dependencies
quilted_fabric_api_version = 9.0.0-alpha.8+0.97.0-1.20.4
fabric_api_version = 0.97.1+1.20.4
cca_version = 5.4.0
fpa_version=0.2-SNAPSHOT
# V1.2.12
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/ladysnake/locki/Locki.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
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;
Expand All @@ -35,10 +38,6 @@
import org.ladysnake.locki.impl.InventoryLockArgumentType;
import org.ladysnake.locki.impl.InventoryNodeArgumentType;
import org.ladysnake.locki.impl.LockiCommand;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.command.api.CommandRegistrationCallback;
import org.quiltmc.qsl.command.api.ServerArgumentType;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -153,15 +152,16 @@ public static Stream<String> streamNodeNames() {
}

@Override
public void onInitialize(ModContainer mod) {
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));
}

void baseInit() {
DefaultInventoryNodes.init();
ModdedInventoryNodes.init();

if (mod != null) { // Unit testing
ServerArgumentType.register(new Identifier("locki", "inventory_lock"), InventoryLockArgumentType.class, SingletonArgumentInfo.contextFree(InventoryLockArgumentType::inventoryLock), t -> IdentifierArgumentType.identifier());
ServerArgumentType.register(new Identifier("locki", "inventory_node"), InventoryNodeArgumentType.class, SingletonArgumentInfo.contextFree(InventoryNodeArgumentType::inventoryNode), t -> StringArgumentType.string());
}

CommandRegistrationCallback.EVENT.register((dispatcher, ctx, dedicated) -> LockiCommand.register(dispatcher));
PermissionCheckEvent.EVENT.register((source, permission) -> {
if (source instanceof ServerCommandSource && permission.startsWith("locki.access.")) {
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 @@ -17,6 +17,7 @@
*/
package org.ladysnake.locki.impl;

import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.recipe_book.RecipeBookProvider;
Expand All @@ -27,7 +28,6 @@
import org.ladysnake.locki.InventoryLockingChangeCallback;
import org.ladysnake.locki.InventoryNode;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer;

public class LockiClient implements ClientModInitializer {
public static final Identifier LOCKED_SLOT_SPRITE = new Identifier("locki", "gui/locked_slot");
Expand All @@ -52,7 +52,7 @@ private static void updateCraftingBookVisibility(PlayerEntity player, InventoryN
}

@Override
public void onInitializeClient(ModContainer mod) {
public void onInitializeClient() {
InventoryLockingChangeCallback.EVENT.register(LockiClient::updateCraftingBookVisibility);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
},
"intermediate_mappings": "net.fabricmc:intermediary",
"entrypoints": {
"init": [
"main": [
"org.ladysnake.locki.Locki"
],
"client_init": [
"client": [
"org.ladysnake.locki.impl.LockiClient"
],
"cardinal-components": [
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/ladysnake/locki/LockiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LockiTest {

@BeforeAll
public static void setUpGlobal() {
instance.onInitialize(null);
instance.baseInit();
}

@BeforeEach
Expand Down
5 changes: 2 additions & 3 deletions src/testmod/java/org/ladysnake/lockii/Lockii.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
*/
package org.ladysnake.lockii;

import net.fabricmc.api.ModInitializer;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;

public final class Lockii implements ModInitializer {
public static Identifier id(String path) {
return new Identifier("lockii", path);
}

@Override
public void onInitialize(ModContainer mod) {
public void onInitialize() {
Registry.register(Registries.ITEM, id("inventory_lock"), new InventoryLockItem(new Item.Settings()));
}
}
12 changes: 5 additions & 7 deletions src/testmod/java/org/ladysnake/lockii/tests/LockiTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.ladysnake.lockii.tests;

import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
Expand All @@ -33,12 +34,9 @@
import org.ladysnake.locki.Locki;
import org.ladysnake.locki.impl.LockiComponents;
import org.ladysnake.lockii.Lockii;
import org.quiltmc.qsl.testing.api.game.QuiltGameTest;
import org.quiltmc.qsl.testing.api.game.QuiltTestContext;

import static org.ladysnake.elmendorf.ByteBufChecker.any;

public class LockiTestSuite implements QuiltGameTest {
public class LockiTestSuite implements FabricGameTest {
public static final InventoryLock lock = Locki.registerLock(Lockii.id("test_suite"));

@GameTest(structureName = EMPTY_STRUCTURE)
Expand Down Expand Up @@ -71,7 +69,7 @@ public void checkPermission(TestContext ctx) {
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void lockingPreventsItemPickup(QuiltTestContext ctx) {
public void lockingPreventsItemPickup(TestContext ctx) {
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
player.getInventory().addLock(lock, DefaultInventoryNodes.INVENTORY);
ctx.spawnItemEntity(Items.DIAMOND, 1, 1, 2);
Expand All @@ -82,7 +80,7 @@ public void lockingPreventsItemPickup(QuiltTestContext ctx) {
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void lockingPreventsDropFromMainHand(QuiltTestContext ctx) {
public void lockingPreventsDropFromMainHand(TestContext ctx) {
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
player.equipStack(EquipmentSlot.MAINHAND, new ItemStack(Items.ENCHANTED_GOLDEN_APPLE));
player.getInventory().addLock(lock, DefaultInventoryNodes.MAIN_HAND);
Expand All @@ -101,7 +99,7 @@ public void lockingPreventsDropFromMainHand(QuiltTestContext ctx) {
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void itemPickupWorks(QuiltTestContext ctx) {
public void itemPickupWorks(TestContext ctx) {
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
ctx.spawnItemEntity(Items.REDSTONE, 1, 1, 1);
ctx.expectEntity(EntityType.ITEM);
Expand Down
4 changes: 2 additions & 2 deletions src/testmod/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
}
},
"entrypoints": {
"init": [
"main": [
"org.ladysnake.lockii.Lockii"
],
"quilt:game_test": [
"fabric-gametest": [
"org.ladysnake.lockii.tests.LockiTestSuite"
]
},
Expand Down

0 comments on commit 2a9eaf3

Please sign in to comment.