Skip to content

Commit

Permalink
Fix *interface injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Feb 1, 2022
1 parent 2f0a0e6 commit 0e6b548
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time.Year

plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower-mini' version "1.2.1" apply false // TODO restore when loom-quiltflower is updated for loom 0.11
id 'io.github.juuxel.loom-quiltflower' version "1.6.0"
id 'org.cadixdev.licenser' version '0.6.1'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'com.jfrog.artifactory' version '4.21.0'
Expand All @@ -25,6 +25,7 @@ sourceSets {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
dummy
}

loom {
Expand Down Expand Up @@ -137,6 +138,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core:3.+'

testmodImplementation sourceSets.main.output
annotationProcessor(sourceSets.dummy.output)
}

test {
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 0.7.0
------------------------------------------------------
**Additions**
Now uses interface injection to expose methods in PlayerInventory

------------------------------------------------------
Version 0.6.2
------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/use
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.12
loader_version=0.12.5
loader_version=0.12.12

# Mod Properties
mod_version = 0.6.2
mod_version = 0.7.0
maven_group = io.github.ladysnake
archives_base_name = locki

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.43.0+1.18
fabric_version=0.46.3+1.18
cca_version = 4.1.0
fpa_version=0.1-SNAPSHOT
backslot_version=3543530
cloth_config_version=6.0.42
modmenu_version=3.0.0
elmendorf_version=0.3.0
elmendorf_version=0.4.0
# Publishing
owners = Ladysnake
display_name = Locki
Expand Down
22 changes: 22 additions & 0 deletions src/dummy/java/io/github/ladysnake/locki/InventoryKeeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Locki
* Copyright (C) 2021 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package io.github.ladysnake.locki;

// Just a dummy version so that the mixin annotation processor does not choke
public interface InventoryKeeper {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,52 @@
*/
package io.github.ladysnake.lockii.tests;

import io.github.ladysnake.elmendorf.GameTestUtil;
import io.github.ladysnake.locki.DefaultInventoryNodes;
import io.github.ladysnake.locki.InventoryLock;
import io.github.ladysnake.locki.Locki;
import io.github.ladysnake.locki.impl.LockiComponents;
import io.github.ladysnake.lockii.Lockii;
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.test.GameTest;
import net.minecraft.test.TestContext;

import static io.github.ladysnake.elmendorf.ByteBufChecker.any;

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

@GameTest(structureName = EMPTY_STRUCTURE)
public void lockingPreventsItemPickup(TestContext ctx) {
PlayerEntity mockPlayer = GameTestUtil.spawnPlayer(ctx, 1, 0, 1);
mockPlayer.getInventory().addLock(lock, DefaultInventoryNodes.INVENTORY);
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
player.getInventory().addLock(lock, DefaultInventoryNodes.INVENTORY);
ctx.spawnItem(Items.DIAMOND, 1, 0, 2);
ctx.expectEntity(EntityType.ITEM);
ctx.waitAndRun(20, () -> {
ctx.expectEntity(EntityType.ITEM);
ctx.complete();
});
player.playerTick();
ctx.expectEntity(EntityType.ITEM);
ctx.complete();
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void itemPickupWorks(TestContext ctx) {
GameTestUtil.spawnPlayer(ctx, 1, 0, 1);
ctx.spawnItem(Items.REDSTONE, 1, 0, 2);
ctx.waitAndRun(20, () -> {
ctx.dontExpectEntity(EntityType.ITEM);
ctx.complete();
});
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
ctx.spawnItem(Items.REDSTONE, 1, 0, 1);
ctx.expectEntity(EntityType.ITEM);
player.playerTick();
ctx.dontExpectEntity(EntityType.ITEM);
ctx.complete();
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void componentGetsSynced(TestContext ctx) {
ServerPlayerEntity player = ctx.spawnServerPlayer(1, 0, 1);
player.getInventory().addLock(lock, DefaultInventoryNodes.INVENTORY);
ctx.verifyConnection(player, conn -> conn.sentEntityComponentUpdate(player, LockiComponents.INVENTORY_KEEPER, c -> c.checkVarInt(any())
.checkString(any())
.checkVarInt(1)
.checkByte((byte)(1 << lock.getRawId()))));
ctx.complete();
}
}

0 comments on commit 0e6b548

Please sign in to comment.