Skip to content

Commit

Permalink
Jvmfield (#90)
Browse files Browse the repository at this point in the history
* Annotate with @jvm field
Bump versions
Fix translations
Removed unneeded callback
Add null check to initial stack - #85

* Ternary brr
  • Loading branch information
PotatoPresident authored Sep 17, 2021
1 parent 787a1f9 commit aa923d1
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 126 deletions.
6 changes: 3 additions & 3 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
minecraft = "1.17.1"
yarn-mappings = "1.17.1+build.37"
fabric-loader = "0.11.6"
yarn-mappings = "1.17.1+build.61"
fabric-loader = "0.11.7"

fabric-api = "0.37.2+1.17"
fabric-api = "0.40.1+1.17"

# Kotlin
kotlin = "1.5.21"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.quiltservertools.ledger.mixin.callbacks;

import com.github.quiltservertools.ledger.callbacks.PlayerBlockPlaceCallback;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
Expand All @@ -9,7 +10,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.github.quiltservertools.ledger.callbacks.PlayerBlockPlaceCallback;

@Mixin(BlockItem.class)
public abstract class BlockItemMixin extends Item {
Expand All @@ -28,7 +28,7 @@ public void ledgerPlayerPlaceBlockCallback(ItemPlacementContext context, Callbac

BlockState blockState = context.getWorld().getBlockState(context.getBlockPos());

PlayerBlockPlaceCallback.Companion.getEVENT().invoker().place(
PlayerBlockPlaceCallback.EVENT.invoker().place(
context.getWorld(),
context.getPlayer(),
context.getBlockPos(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import com.github.quiltservertools.ledger.callbacks.BlockExplodeCallback;

@Mixin(Explosion.class)
public abstract class ExplosionMixin {
Expand Down Expand Up @@ -47,7 +46,7 @@ private void ledgerBlockExplodeCallback(

if (blockState.isAir()) return;

BlockExplodeCallback.Companion.getEVENT().invoker().explode(
BlockExplodeCallback.EVENT.invoker().explode(
world,
entity,
blockPos,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.quiltservertools.ledger.mixin.callbacks;

import com.github.quiltservertools.ledger.callbacks.BlockFallCallback;
import com.github.quiltservertools.ledger.callbacks.BlockLandCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.FallingBlockEntity;
Expand All @@ -10,8 +12,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import com.github.quiltservertools.ledger.callbacks.BlockFallCallback;
import com.github.quiltservertools.ledger.callbacks.BlockLandCallback;

@Mixin(FallingBlockEntity.class)
public abstract class FallingBlockEntityMixin {
Expand All @@ -29,7 +29,7 @@ public abstract class FallingBlockEntityMixin {
private void ledgerBlockFallInvoker(CallbackInfo ci, Block block, BlockPos blockPos) {
FallingBlockEntity entity = (FallingBlockEntity) (Object) this;

BlockFallCallback.Companion.getEVENT().invoker().fall(entity.world, blockPos, this.block);
BlockFallCallback.EVENT.invoker().fall(entity.world, blockPos, this.block);
}

@Inject(
Expand All @@ -43,6 +43,6 @@ private void ledgerBlockFallInvoker(CallbackInfo ci, Block block, BlockPos block
private void ledgerBlockLandInvoker(CallbackInfo ci, Block block, BlockPos blockPos2, boolean bl, boolean bl2, BlockState blockState) {
FallingBlockEntity entity = (FallingBlockEntity) (Object) this;

BlockLandCallback.Companion.getEVENT().invoker().land(entity.world, blockPos2, this.block);
BlockLandCallback.EVENT.invoker().land(entity.world, blockPos2, this.block);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.quiltservertools.ledger.mixin.callbacks;

import com.github.quiltservertools.ledger.callbacks.BlockBurnCallback;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -11,7 +12,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import com.github.quiltservertools.ledger.callbacks.BlockBurnCallback;

@Mixin(FireBlock.class)
public abstract class FireBlockMixin {
Expand All @@ -25,7 +25,7 @@ public abstract class FireBlockMixin {
)
private void ledgerBlockBurnBreakInvoker(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo ci, int i, BlockState blockState) {
if (blockState.getBlock() != Blocks.FIRE) {
BlockBurnCallback.Companion.getEVENT().invoker().burn(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null);
BlockBurnCallback.EVENT.invoker().burn(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null);
}
}

Expand All @@ -39,7 +39,7 @@ private void ledgerBlockBurnBreakInvoker(World world, BlockPos pos, int spreadFa
)
private void ledgerBlockBurnReplaceInvoker(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo ci, int i, BlockState blockState) {
if (blockState.getBlock() != Blocks.FIRE) {
BlockBurnCallback.Companion.getEVENT().invoker().burn(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null);
BlockBurnCallback.EVENT.invoker().burn(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.quiltservertools.ledger.mixin;
package com.github.quiltservertools.ledger.mixin.callbacks;

import com.github.quiltservertools.ledger.callbacks.PlayerBlockPlaceCallback;
import net.minecraft.item.FlintAndSteelItem;
Expand All @@ -17,7 +17,7 @@ public abstract class FlintAndSteelItemMixin {
public void logFlintAndSteelUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
BlockPos pos = context.getBlockPos().offset(context.getSide());
if (context.getPlayer() != null) {
PlayerBlockPlaceCallback.Companion.getEVENT().invoker().place(context.getWorld(), context.getPlayer(), pos, context.getWorld().getBlockState(pos), new ItemPlacementContext(context), null);
PlayerBlockPlaceCallback.EVENT.invoker().place(context.getWorld(), context.getPlayer(), pos, context.getWorld().getBlockState(pos), new ItemPlacementContext(context), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static void ledgerTrackContainerBreakRemove(World world, double x, doubl
ItemStack stack = inventory.getStack(i);

if (!stack.isEmpty() && inventory instanceof LocationalInventory locationalInventory) {
ItemRemoveCallback.Companion.getEVENT().invoker().remove(stack, locationalInventory.getLocation(), (ServerWorld) world, Sources.BROKE, null);
ItemRemoveCallback.EVENT.invoker().remove(stack, locationalInventory.getLocation(), (ServerWorld) world, Sources.BROKE, null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.quiltservertools.ledger.mixin.callbacks;

import com.github.quiltservertools.ledger.callbacks.EntityKillCallback;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
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.callback.CallbackInfo;
import com.github.quiltservertools.ledger.callbacks.EntityKillCallback;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {
Expand All @@ -17,7 +17,7 @@ public abstract class LivingEntityMixin {
private void ledgerEntityKillInvoker(DamageSource source, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;

EntityKillCallback.Companion.getEVENT().invoker().kill(
EntityKillCallback.EVENT.invoker().kill(
entity.world, entity.getBlockPos(), entity, source
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setHandler(@NotNull ScreenHandler handler) {

@Inject(method = "<init>", at = @At(value = "RETURN"))
private void ledgerGetInitialStack(Inventory inventory, int index, int x, int y, CallbackInfo ci) {
oldStack = this.getStack().copy();
oldStack = this.getStack() == null ? ItemStack.EMPTY : this.getStack().copy();
}

@Inject(method = "markDirty", at = @At(value = "HEAD"))
Expand Down Expand Up @@ -106,9 +106,9 @@ private void logChange(PlayerEntity player, ItemStack stack, ItemStack newStack,
ItemStack changedStack = oldEmpty ? newStack : stack;

if (oldEmpty) {
ItemInsertCallback.Companion.getEVENT().invoker().insert(changedStack, pos, (ServerWorld) player.world, Sources.PLAYER, (ServerPlayerEntity) player);
ItemInsertCallback.EVENT.invoker().insert(changedStack, pos, (ServerWorld) player.world, Sources.PLAYER, (ServerPlayerEntity) player);
} else {
ItemRemoveCallback.Companion.getEVENT().invoker().remove(changedStack, pos, (ServerWorld) player.world, Sources.PLAYER, (ServerPlayerEntity) player);
ItemRemoveCallback.EVENT.invoker().remove(changedStack, pos, (ServerWorld) player.world, Sources.PLAYER, (ServerPlayerEntity) player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun interface BlockBurnCallback {
fun burn(world: World, pos: BlockPos, state: BlockState, entity: BlockEntity?)

companion object {
@JvmField
val EVENT: Event<BlockBurnCallback> =
EventFactory.createArrayBacked(BlockBurnCallback::class.java) { listeners ->
BlockBurnCallback { world, pos, state, entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun interface BlockExplodeCallback {
fun explode(world: World, source: Entity?, pos: BlockPos, state: BlockState, entity: BlockEntity?)

companion object {
@JvmField
val EVENT: Event<BlockExplodeCallback> =
EventFactory.createArrayBacked(BlockExplodeCallback::class.java) { listeners ->
BlockExplodeCallback { world, source, pos, state, entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun interface BlockFallCallback {
fun fall(world: World, pos: BlockPos, state: BlockState)

companion object {
@JvmField
val EVENT: Event<BlockFallCallback> =
EventFactory.createArrayBacked(BlockFallCallback::class.java) { listeners ->
BlockFallCallback { world, pos, state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun interface BlockLandCallback {
fun land(world: World, pos: BlockPos, state: BlockState)

companion object {
@JvmField
val EVENT: Event<BlockLandCallback> =
EventFactory.createArrayBacked(BlockLandCallback::class.java) { listeners ->
BlockLandCallback { world, pos, state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun interface EntityKillCallback {
fun kill(world: World, pos: BlockPos, entity: LivingEntity, source: DamageSource)

companion object {
@JvmField
val EVENT: Event<EntityKillCallback> =
EventFactory.createArrayBacked(EntityKillCallback::class.java) { listeners ->
EntityKillCallback { world, pos, entity, source ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun interface ItemInsertCallback {
fun insert(stack: ItemStack, pos: BlockPos, world: ServerWorld, source: String, player: ServerPlayerEntity?)

companion object {
@JvmField
val EVENT: Event<ItemInsertCallback> =
EventFactory.createArrayBacked(ItemInsertCallback::class.java) { listeners ->
ItemInsertCallback { stack, pos, world, source, player ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun interface ItemRemoveCallback {
fun remove(stack: ItemStack, pos: BlockPos, world: ServerWorld, source: String, player: ServerPlayerEntity?)

companion object {
@JvmField
val EVENT: Event<ItemRemoveCallback> =
EventFactory.createArrayBacked(ItemRemoveCallback::class.java) { listeners ->
ItemRemoveCallback { stack, pos, world, source, player ->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fun interface PlayerBlockPlaceCallback {
)

companion object {
@JvmField
val EVENT: Event<PlayerBlockPlaceCallback> =
EventFactory.createArrayBacked(PlayerBlockPlaceCallback::class.java) { listeners ->
PlayerBlockPlaceCallback { world, player, pos, state, context, entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.time.Instant

private const val MAX_PLAYER_NAME_LENGTH = 16
private const val MAX_ACTION_NAME_LENGTH = 16
private const val MAX_IDENTIFIER_LENGTH = 200
private const val MAX_IDENTIFIER_LENGTH = 191
private const val MAX_SOURCE_NAME_LENGTH = 30

object Tables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.github.quiltservertools.ledger.listeners

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.actionutils.ActionFactory
import com.github.quiltservertools.ledger.callbacks.PlayerBlockAttackCallback
import com.github.quiltservertools.ledger.callbacks.PlayerBlockPlaceCallback
import com.github.quiltservertools.ledger.database.DatabaseManager
import com.github.quiltservertools.ledger.network.Networking.disableNetworking
import com.github.quiltservertools.ledger.utility.inspectBlock
import com.github.quiltservertools.ledger.utility.isInspecting
import kotlinx.coroutines.launch
import net.fabricmc.fabric.api.event.player.AttackBlockCallback
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents
import net.fabricmc.fabric.api.event.player.UseBlockCallback
import net.fabricmc.fabric.api.networking.v1.PacketSender
Expand All @@ -31,7 +31,7 @@ fun registerPlayerListeners() {
PlayerBlockPlaceCallback.EVENT.register(::onBlockPlace)
ServerPlayConnectionEvents.JOIN.register(::onJoin)
ServerPlayConnectionEvents.DISCONNECT.register(::onLeave)
PlayerBlockAttackCallback.EVENT.register(::onBlockAttack)
AttackBlockCallback.EVENT.register(::onBlockAttack)
UseBlockCallback.EVENT.register(::onUseBlock)
}

Expand All @@ -56,9 +56,9 @@ private fun onUseBlock(
private fun onBlockAttack(
player: PlayerEntity,
world: World,
hand: Hand,
pos: BlockPos,
direction: Direction,
hand: Hand
direction: Direction
): ActionResult {
if (world.isClient) return ActionResult.PASS

Expand Down
Loading

0 comments on commit aa923d1

Please sign in to comment.