Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client versions between 1.0.0 and 1.2.5 #2

Merged
merged 3 commits into from
Nov 10, 2023
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ dependencies {
shadow libs.gson
implementation libs.gson

include project(":versions:1.0.0-client")
include project(":versions:1.0.1-server")
include project(":versions:1.1.0-client")
include project(":versions:1.1.0-server")
include project(":versions:1.2.5-client")
include project(":versions:1.2.5-server")
include project(":versions:1.3.2")
include project(":versions:1.4.7")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod_version = 1.1.0
maven_group = net.lostluma
archives_base_name = server-stats

minecraft_version_min = 1.0.1
minecraft_version_min = 1.0.0
minecraft_version_max = 1.12.2

# Minecraft Properties
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ pluginManagement {
}
}

include(":versions:1.0.0-client")
include(":versions:1.0.1-server")
include(":versions:1.1.0-client")
include(":versions:1.1.0-server")
include(":versions:1.2.5-client")
include(":versions:1.2.5-server")
include(":versions:1.3.2")
include(":versions:1.4.7")
Expand Down
49 changes: 49 additions & 0 deletions versions/1.0.0-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'maven-publish'
alias libs.plugins.shadow
alias libs.plugins.quilt.loom
alias libs.plugins.ploceus
}

apply from: "${rootProject.projectDir}/gradle/common.gradle"

group = project.maven_group
version = generateVersionWithMetadata()

base {
archivesName = project.archives_base_name
}

loom {
clientOnlyMinecraftJar()

accessWidenerPath = file("src/main/resources/server_stats.accesswidener")
}

ploceus {
clientOnlyMappings()
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"

mappings loom.layered {
mappings "net.ornithemc:feather:${project.feather_version}:v2"
addLayer ploceus.nestedMappings() // Required for nests
}

nests "net.ornithemc:nests:${project.nests_version}"
modImplementation libs.quilt.loader

implementation libs.gson
}

shadowJar {
configurations = [project.configurations.shadow]
relocate "com.google", "net.lostluma.server_stats.external"
}

remapJar {
inputFile.set shadowJar.archiveFile
dependsOn shadowJar
}
8 changes: 8 additions & 0 deletions versions/1.0.0-client/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mod Properties
archives_base_name = server-stats-mixins-client

# Minecraft Properties
minecraft_version = 1.0.0

nests_version = 1.0.0-client+build.1
feather_version = 1.0.0-client+build.11
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
@@ -0,0 +1,34 @@
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;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.lostluma.server_stats.stats.Stats;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.living.player.InputPlayerEntity;

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

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

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

@Inject(method = "m_4977780", at = @At("TAIL"))
private void changeDimension(int dimension, CallbackInfo callbackInfo) {
this.player.server_stats$saveStats();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.lostluma.server_stats.mixin.common;

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 net.lostluma.server_stats.stats.Stats;
import net.minecraft.entity.Entities;

@Mixin(Entities.class)
public class EntitiesMixin {
@Inject(method = "register", at = @At("TAIL"))
private static void registerWithSpawnEgg(Class<?> type, String key, int id, CallbackInfo callbackInfo) {
Stats.createEntityKillStat(key);
Stats.createKilledByEntityStat(key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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;

import net.lostluma.server_stats.stats.ServerPlayerStats;
import net.lostluma.server_stats.stats.Stat;
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();
var player = (PlayerEntity)(Object)this;

if (stats != null) {
stats.increment(player, stat, amount);
}
}

@Override
public void server_stats$saveStats() {
var stats = this.server_stats$getStats();

if (stats != null) {
stats.save();
}
}

@Override
public @Nullable ServerPlayerStats server_stats$getStats() {
var player = (PlayerEntity)(Object)this;

// Unmapped method returns true when the server is multiplayer
if (Minecraft.INSTANCE.m_2812472()) {
return null;
}

if (this.server_stats$serverPlayerStats == null) {
this.server_stats$serverPlayerStats = new ServerPlayerStats(player);
}

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
@@ -0,0 +1,25 @@
package net.lostluma.server_stats.mixin.common;

import java.util.List;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.entity.living.player.PlayerEntity;
import net.minecraft.world.World;

@Mixin(World.class)
public class WorldMixin {
@Shadow
public List<PlayerEntity> players;

@Inject(method = "saveData", at = @At("TAIL"))
public void onSave(CallbackInfo callbackInfo) {
for (PlayerEntity player : this.players) {
player.server_stats$saveStats();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.lostluma.server_stats.stats;

import org.jetbrains.annotations.Nullable;

public class GeneralStat extends Stat {
public GeneralStat(String key, @Nullable Integer vanillaId) {
super(key, vanillaId);
}

@Override
public Stat register() {
super.register();
Stats.GENERAL.add(this);
return this;
}
}
Loading