33 lines
1.3 KiB
Java
33 lines
1.3 KiB
Java
package xyz.nodrop.farmingtools.mixin.client;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
|
import net.minecraft.util.math.BlockPos;
|
|
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.CallbackInfoReturnable;
|
|
import xyz.nodrop.farmingtools.client.hud.FarmingTrackerModule;
|
|
|
|
@Mixin(ClientPlayerInteractionManager.class)
|
|
public class MixinPlayerInteractionManager {
|
|
|
|
private Block pendingBrokenBlock = null; // tymczasowe przechowanie
|
|
|
|
@Inject(method = "breakBlock", at = @At("HEAD"))
|
|
private void beforeBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
|
|
MinecraftClient client = MinecraftClient.getInstance();
|
|
if (client.world != null) {
|
|
pendingBrokenBlock = client.world.getBlockState(pos).getBlock();
|
|
}
|
|
}
|
|
|
|
@Inject(method = "breakBlock", at = @At("RETURN"))
|
|
private void onBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
|
|
if (Boolean.TRUE.equals(cir.getReturnValue()) && pendingBrokenBlock != null) {
|
|
FarmingTrackerModule.INSTANCE.onBlockBroken(pendingBrokenBlock);
|
|
}
|
|
pendingBrokenBlock = null;
|
|
}
|
|
} |