Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies {

// Fabric
minecraft(libs.minecraft)
mappings(variantOf(libs.yarn.mappings) { classifier("v2") })
mappings(loom.officialMojangMappings())
modImplementation(libs.fabric.loader)

// Fabric API
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx2G

# Mod Properties
modVersion = 1.3.17
modVersion = 1.3.18
mavenGroup = com.github.quiltservertools
modId = ledger
modName = Ledger
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
12 changes: 5 additions & 7 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[versions]
minecraft = "1.21.10"
yarn-mappings = "1.21.10+build.2"
fabric-loader = "0.17.2"
minecraft = "1.21.11-rc2"
fabric-loader = "0.18.1"

fabric-api = "0.135.0+1.21.10"
fabric-api = "0.139.4+1.21.11"

# Kotlin
kotlin = "2.2.0"
# Also modrinth version in gradle.properties
fabric-kotlin = "1.13.4+kotlin.2.2.0"

fabric-permissions = "0.5.0"
fabric-permissions = "0.6.0-patbox"
translations = "2.5.2+1.21.9-pre3"

exposed = "1.0.0-rc-2"
Expand All @@ -22,7 +21,6 @@ detekt = "1.23.8"

[libraries]
minecraft = { module = "net.minecraft:minecraft", version.ref = "minecraft" }
yarn-mappings = { module = "net.fabricmc:yarn", version.ref = "yarn-mappings" }
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }

fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
Expand All @@ -45,5 +43,5 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting",
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
loom = { id = "fabric-loom", version = "1.11.+" }
loom = { id = "fabric-loom", version = "1.14.+" }
git_hooks = { id = "com.github.jakemarsden.git-hooks", version = "0.0.2" }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -29,64 +29,64 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ScreenHandler.class)
public abstract class ScreenHandlerMixin implements HandlerWithContext {
@Mixin(AbstractContainerMenu.class)
public abstract class AbstractContainerMenuMixin implements HandlerWithContext {
@Unique
Map<ItemData, Integer> changedStacks = new HashMap<>();
@Unique
private ServerPlayerEntity player = null;
private ServerPlayer player = null;

@Unique
private BlockPos pos = null;

@Inject(method = "addSlot", at = @At(value = "HEAD"))
private void ledgerGiveSlotHandlerReference(Slot slot, CallbackInfoReturnable<Slot> cir) {
((HandledSlot) slot).setHandler((ScreenHandler) (Object) this);
((HandledSlot) slot).setHandler((AbstractContainerMenu) (Object) this);
}

@Inject(method = "onButtonClick", at = @At(value = "HEAD"))
private void ledgerButtonClickGetPlayer(PlayerEntity player, int id, CallbackInfoReturnable<Boolean> cir) {
this.player = (ServerPlayerEntity) player;
@Inject(method = "clickMenuButton", at = @At(value = "HEAD"))
private void ledgerButtonClickGetPlayer(Player player, int id, CallbackInfoReturnable<Boolean> cir) {
this.player = (ServerPlayer) player;
}

@Inject(method = "internalOnSlotClick", at = @At(value = "HEAD"))
private void internalOnSlotClickGetPlayer(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
this.player = (ServerPlayerEntity) player;
@Inject(method = "doClick", at = @At(value = "HEAD"))
private void internalOnSlotClickGetPlayer(int slotIndex, int button, ClickType actionType, Player player, CallbackInfo ci) {
this.player = (ServerPlayer) player;
}

@Inject(method = "onSlotClick", at = @At(value = "HEAD"))
private void ledgerSlotClickGetPlayer(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
this.player = (ServerPlayerEntity) player;
@Inject(method = "clicked", at = @At(value = "HEAD"))
private void ledgerSlotClickGetPlayer(int slotIndex, int button, ClickType actionType, Player player, CallbackInfo ci) {
this.player = (ServerPlayer) player;
}

@Inject(method = "dropInventory", at = @At(value = "HEAD"))
private void ledgerDropInventoryGetPlayer(PlayerEntity player, Inventory inventory, CallbackInfo ci) {
this.player = (ServerPlayerEntity) player;
@Inject(method = "clearContainer", at = @At(value = "HEAD"))
private void ledgerDropInventoryGetPlayer(Player player, Container inventory, CallbackInfo ci) {
this.player = (ServerPlayer) player;
}

@Inject(method = "onClosed", at = @At(value = "RETURN"))
private void ledgerCloseScreenLogChanges(PlayerEntity player, CallbackInfo ci) {
if (!player.getEntityWorld().isClient() && pos != null) {
@Inject(method = "removed", at = @At(value = "RETURN"))
private void ledgerCloseScreenLogChanges(Player player, CallbackInfo ci) {
if (!player.level().isClientSide() && pos != null) {
for (var pair : changedStacks.keySet()) {
ItemStack stack = new ItemStack(Registries.ITEM.getEntry(pair.getItem()), 1, pair.getChanges());
ItemStack stack = new ItemStack(BuiltInRegistries.ITEM.wrapAsHolder(pair.getItem()), 1, pair.getChanges());
if (stack.isEmpty()) {
continue;
}
int count = changedStacks.get(pair);
int countAbs = Math.abs(count);
List<ItemStack> splitStacks = new ArrayList<>();
while (countAbs > 0) {
ItemStack addStack = stack.copyWithCount(Math.min(countAbs, stack.getMaxCount()));
ItemStack addStack = stack.copyWithCount(Math.min(countAbs, stack.getMaxStackSize()));
splitStacks.add(addStack);
countAbs -= addStack.getCount();
}
if (count > 0) {
for (ItemStack splitStack : splitStacks) {
ItemInsertCallback.EVENT.invoker().insert(splitStack, pos, (ServerWorld) player.getEntityWorld(), Sources.PLAYER, (ServerPlayerEntity) player);
ItemInsertCallback.EVENT.invoker().insert(splitStack, pos, (ServerLevel) player.level(), Sources.PLAYER, (ServerPlayer) player);
}
} else {
for (ItemStack splitStack : splitStacks) {
ItemRemoveCallback.EVENT.invoker().remove(splitStack, pos, (ServerWorld) player.getEntityWorld(), Sources.PLAYER, (ServerPlayerEntity) player);
ItemRemoveCallback.EVENT.invoker().remove(splitStack, pos, (ServerLevel) player.level(), Sources.PLAYER, (ServerPlayer) player);
}
}
}
Expand All @@ -95,7 +95,7 @@ private void ledgerCloseScreenLogChanges(PlayerEntity player, CallbackInfo ci) {

@Nullable
@Override
public ServerPlayerEntity getPlayer() {
public ServerPlayer getPlayer() {
return player;
}

Expand All @@ -114,15 +114,15 @@ public void setPos(@NotNull BlockPos pos) {
public void onStackChanged(@NotNull ItemStack old, @NotNull ItemStack itemStack, @NotNull BlockPos pos) {
if (old.isEmpty() && !itemStack.isEmpty()) {
// Add item
var key = new ItemData(itemStack.getItem(), itemStack.getComponentChanges());
var key = new ItemData(itemStack.getItem(), itemStack.getComponentsPatch());
if (changedStacks.containsKey(key)) {
changedStacks.put(key, changedStacks.get(key) + itemStack.getCount());
} else {
changedStacks.put(key, itemStack.getCount());
}
} else if (!old.isEmpty() && itemStack.isEmpty()) {
// Remove item
var key = new ItemData(old.getItem(), old.getComponentChanges());
var key = new ItemData(old.getItem(), old.getComponentsPatch());
if (changedStacks.containsKey(key)) {
changedStacks.put(key, changedStacks.get(key) - old.getCount());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(AnvilScreenHandler.class)
public abstract class AnvilScreenHandlerMixin {
@Mixin(AnvilMenu.class)
public abstract class AnvilMenuMixin {

@Inject(method = "method_24922",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
private static void ledgerLogAnvilBreak(PlayerEntity player, World world, BlockPos pos, CallbackInfo ci) {
target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z"))
private static void ledgerLogAnvilBreak(Player player, Level world, BlockPos pos, CallbackInfo ci) {
BlockBreakCallback.EVENT.invoker().breakBlock(
world,
pos,
Expand All @@ -33,8 +33,8 @@ private static void ledgerLogAnvilBreak(PlayerEntity player, World world, BlockP

@ModifyArgs(method = "method_24922",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private static void ledgerLogAnvilChange(Args args, PlayerEntity player, World world, BlockPos pos) {
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"))
private static void ledgerLogAnvilChange(Args args, Player player, Level world, BlockPos pos) {
BlockState newBlockState = args.get(1);
BlockChangeCallback.EVENT.invoker().changeBlock(
world,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(AxeItem.class)
public abstract class AxeItemMixin {
@ModifyArgs(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void logAxeUsage(Args args, ItemUsageContext context) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
@ModifyArgs(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"))
public void logAxeUsage(Args args, UseOnContext context) {
Level world = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockState oldState = world.getBlockState(pos);
BlockState newState = args.get(1);
PlayerEntity player = context.getPlayer();
Player player = context.getPlayer();
if (player != null) {
BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, player);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.quiltservertools.ledger.mixin;

import com.github.quiltservertools.ledger.actionutils.LocationalInventory;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(BaseContainerBlockEntity.class)
public abstract class BaseContainerBlockEntityMixin extends BlockEntity implements LocationalInventory {
public BaseContainerBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

@NotNull
@Override
public BlockPos getLocation() {
return this.worldPosition;
}
}
Loading