Skip to content

Commit

Permalink
Manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 authored May 3, 2024
1 parent 2db1de1 commit 8a74576
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 148 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public abstract class BucketDispenserBehaviorMixin extends ItemDispenserBehavior
method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;",
target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;",
shift = At.Shift.AFTER
)
)
private void logFluidPickup(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir, @Local ItemStack itemStack, @Local BlockPos pos, @Local BlockState blockState) {
var world = pointer.world();
var world = pointer.getWorld();
if (!itemStack.isEmpty()) {
if (blockState.isLiquid() || blockState.isOf(Blocks.POWDER_SNOW)) {
BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, blockState, world.getBlockEntity(pos), Sources.REDSTONE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.github.quiltservertools.ledger.mixin;

import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback;
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
import com.github.quiltservertools.ledger.utility.PlayerCausable;
import com.github.quiltservertools.ledger.utility.Sources;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -21,6 +23,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(Explosion.class)
public abstract class ExplosionMixin {
Expand All @@ -37,15 +40,22 @@ public abstract class ExplosionMixin {
private Entity entity;

@Inject(
method = "affectWorld",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"
)
method = "affectWorld",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"),
locals = LocalCapture.CAPTURE_FAILEXCEPTION
)
private void ledgerExplosionFireCallback(boolean particles, CallbackInfo ci,
@Local ObjectListIterator<BlockPos> affectedBlocks, @Local BlockPos blockPos) {
BlockState blockState = AbstractFireBlock.getState(world, blockPos);
private void ledgerBlockExplodeCallback(
boolean bl,
CallbackInfo ci,
boolean bl2,
ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList,
boolean bl3,
ObjectListIterator<BlockPos> blocks,
BlockPos blockPos,
BlockState blockState,
Block block) {

if (blockState.isAir()) return;

LivingEntity entity;
if (this.entity instanceof PlayerCausable playerCausable && playerCausable.getCausingPlayer() != null) {
Expand All @@ -60,14 +70,35 @@ private void ledgerExplosionFireCallback(boolean particles, CallbackInfo ci,
} else {
source = Sources.EXPLOSION;
}

// if (entity != null && !(entity instanceof PlayerEntity)) {
// source = Registries.ENTITY_TYPE.getId(entity.getType()).getPath();
// } else {
// if (this.entity instanceof PlayerCausable hasCausingPlayer) {
// // If the source is an end portal, we obtain the source player
// var playerSource = hasCausingPlayer.getCausingPlayer();
//
// if (playerSource != null) {
// entity = playerSource;
// }
// }
// source = Sources.EXPLOSION;
// }

// if (this.entity instanceof CreeperEntity creeper) {
// var target = creeper.getTarget();
// if (target instanceof PlayerEntity player) {
// entity = player;
// }
// }

BlockPlaceCallback.EVENT.invoker().place(
world,
blockPos,
blockState,
world.getBlockEntity(blockPos) != null ? world.getBlockEntity(blockPos) : null,
source,
entity instanceof PlayerEntity player ? player : null
BlockBreakCallback.EVENT.invoker().breakBlock(
world,
blockPos,
blockState,
world.getBlockEntity(blockPos) != null ? world.getBlockEntity(blockPos) : null,
source,
entity instanceof PlayerEntity player ? player : null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -20,7 +18,9 @@
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;

@Mixin(FillCommand.class)
Expand All @@ -30,16 +30,10 @@ public abstract class FillCommandMixin {
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/command/argument/BlockStateArgument;setBlockState(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;I)Z"
)
),
locals = LocalCapture.CAPTURE_FAILHARD
)
private static void logFillChanges(
ServerCommandSource source,
BlockBox range,
BlockStateArgument block,
@Coerce Object mode,
Predicate<CachedBlockPosition> filter,
CallbackInfoReturnable<Integer> cir,
@Local BlockPos pos) {
private static void logFillChanges(ServerCommandSource source, BlockBox range, BlockStateArgument block, @Coerce Object mode, Predicate filter, CallbackInfoReturnable<Integer> cir, List list, ServerWorld serverWorld, int j, Iterator var9, BlockPos pos) {
ServerWorld world = source.getWorld();
BlockState oldState = world.getBlockState(pos);
BlockEntity oldBlockEntity = world.getBlockEntity(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

Expand All @@ -25,12 +26,12 @@ public abstract class BedBlockMixin {
private BlockEntity oldBlockEntity = null;

@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void storeBlockEntity(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
public void storeBlockEntity(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
oldBlockEntity = world.getBlockEntity(blockPos);
}

@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void logBedBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
public void logBedBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
BlockBreakCallback.EVENT.invoker().breakBlock(world, blockPos, blockState, oldBlockEntity, player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static void logWaterDrainNonSource(BlockPos actorBlockPos, World world,
}

@Inject(method = "method_49829", at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;"))
target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;"))
private static void logWaterDrainSource(BlockPos actorBlockPos, World world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), null, Sources.SPONGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import net.minecraft.block.TrapdoorBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -15,15 +18,16 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(TrapdoorBlock.class)
public abstract class TrapdoorBlockMixin {
@Shadow
@Final
public static BooleanProperty OPEN;

@Inject(method = "flip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void logTrapdoorInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, CallbackInfo ci) {
@Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void logTrapdoorInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(OPEN), state, null, null, Sources.INTERACT, player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ object Ledger : CoroutineScope {

override val coroutineContext: CoroutineContext = Dispatchers.IO

@JvmStatic
fun onInitializeServer() {
val version = LedgerExpectPlatform.getModVersionFriendlyString()
logInfo("Initializing Ledger $version")
Expand All @@ -77,11 +78,20 @@ object Ledger : CoroutineScope {
CommandRegistrationEvent.EVENT.register { dispatcher, _, _ -> registerCommands(dispatcher) }
}

private fun registerWorlds() {
for (world in server.worlds) {
Ledger.launch {
DatabaseManager.registerWorld(world.registryKey.value)
}
}
}

private fun serverStarting(server: MinecraftServer) {
this.server = server
ExtensionManager.serverStarting(server)
DatabaseManager.setup(ExtensionManager.getDataSource())
DatabaseManager.ensureTables()
registerWorlds()

ActionRegistry.registerDefaultTypes()
initListeners()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.github.quiltservertools.ledger.utility.literal
import com.github.quiltservertools.ledger.utility.translate
import kotlinx.coroutines.launch
import org.sasha0552.ledger.LedgerExpectPlatform
import org.sasha0552.ledger.LedgerExpectPlatform
import net.minecraft.server.command.CommandManager
import net.minecraft.text.ClickEvent
import net.minecraft.text.Text
Expand Down Expand Up @@ -102,8 +101,4 @@ object StatusCommand : BuildableCommand {

return 1
}

private fun getVersion() = SemanticVersion.parse(
FabricLoader.getInstance().getModContainer(Ledger.MOD_ID).get().metadata.version.friendlyString
)
}
Loading

0 comments on commit 8a74576

Please sign in to comment.