Skip to content

Commit

Permalink
Integrate upstream changes, fix stats involving blocks/items
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Nov 10, 2023
1 parent d255a43 commit 6179fa1
Show file tree
Hide file tree
Showing 62 changed files with 532 additions and 1,344 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.lostluma.server_stats;

public class Constants {
public static final String MOD_ID = "server_stats";
public static final String STATS_PACKET_CHANNEL = MOD_ID + "|s";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.lostluma.server_stats.mixin.client;

import net.lostluma.server_stats.stats.Stats;
import net.minecraft.client.entity.living.player.InputPlayerEntity;
import net.minecraft.client.entity.living.player.LocalPlayerEntity;
import net.minecraft.entity.living.player.PlayerEntity;
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;

@Mixin({ InputPlayerEntity.class, LocalPlayerEntity.class })
public class LocalPlayerEntityMixin {
private PlayerEntity getPlayer() {
return (PlayerEntity) (Object) this;
}

@Inject(method = "incrementStat(Lnet/minecraft/stat/Stat;I)V", at = @At("HEAD"))
private void incrementStat(net.minecraft.stat.Stat vanillaStat, int amount, CallbackInfo callbackInfo) {
if (vanillaStat == null) {
return;
}

var stat = Stats.byVanillaId(vanillaStat.id);

if (stat != null) {
this.getPlayer().server_stats$incrementStat(stat, amount);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package net.lostluma.server_stats.mixin.server;
package net.lostluma.server_stats.mixin.client;

import net.lostluma.server_stats.stats.ServerPlayerStats;
import net.minecraft.world.WorldSettings;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,22 +14,21 @@

@Mixin(Minecraft.class)
public class MinecraftMixin {
@Shadow
public InputPlayerEntity player;
@Shadow
public InputPlayerEntity player;

@Inject(method = "main", at = @At("HEAD"))
private static void onMain(CallbackInfo callbackInfo) {
@Inject(method = "<init>", at = @At("TAIL"))
private void onInit(CallbackInfo callbackInfo) {
Stats.init();
}

@Inject(method = "startGame", at = @At("HEAD"))
private void loadWorld(String worldDir, String worldName, WorldSettings worldSettings, CallbackInfo callbackInfo) {
ServerPlayerStats.setWorldDirectory(String.format("saves/%s", worldDir));
private void startGame(String worldDir, String worldName, WorldSettings worldSettings, CallbackInfo callbackInfo) {
ServerPlayerStats.setWorldDirectory(String.format("saves/%s", worldDir));
}

// This method is called when the player switches between worlds
@Inject(method = "m_4977780", at = @At("TAIL"))
private void onRespawn(int dimension, CallbackInfo callbackInfo) {
this.player.server_stats$saveStats();
private void changeDimension(int dimension, CallbackInfo callbackInfo) {
this.player.server_stats$saveStats();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.lostluma.server_stats.mixin.server;
package net.lostluma.server_stats.mixin.common;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.lostluma.server_stats.mixin.server;
package net.lostluma.server_stats.mixin.common;

import net.lostluma.server_stats.stats.Stats;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.living.LivingEntity;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -9,12 +12,19 @@
import net.lostluma.server_stats.types.StatsPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.living.player.PlayerEntity;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin implements StatsPlayer {
@Unique
private ServerPlayerStats server_stats$serverPlayerStats = null;

private PlayerEntity getPlayer() {
return (PlayerEntity) (Object) this;
}

@Override
public void server_stats$incrementStat(Stat stat, int amount) {
var stats = this.server_stats$getStats();
Expand Down Expand Up @@ -49,4 +59,17 @@ public class PlayerEntityMixin implements StatsPlayer {

return this.server_stats$serverPlayerStats;
}

@Inject(method = "onKill", at = @At("HEAD"))
private void onKill(LivingEntity entity, CallbackInfo callbackInfo) {
this.getPlayer().server_stats$incrementStat(Stats.getEntityKillStat(entity), 1);
}

@Inject(method = "onKilled", at = @At("HEAD"))
private void onKilled(DamageSource source, CallbackInfo callbackInfo) {
if (source.getAttacker() != null) {
var attacker = source.getAttacker();
this.getPlayer().server_stats$incrementStat(Stats.getKilledByEntityStat(attacker), 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.lostluma.server_stats.mixin.server;
package net.lostluma.server_stats.mixin.common;

import java.util.List;

Expand All @@ -15,7 +15,7 @@
public class WorldMixin {
@Shadow
public List<PlayerEntity> players;

@Inject(method = "saveData", at = @At("TAIL"))
public void onSave(CallbackInfo callbackInfo) {
for (PlayerEntity player : this.players) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6179fa1

Please sign in to comment.