Skip to content

Commit

Permalink
add client versions between 1.0.0 and 1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Nov 9, 2023
1 parent 8c119a9 commit d255a43
Show file tree
Hide file tree
Showing 87 changed files with 3,346 additions and 0 deletions.
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
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,18 @@
package net.lostluma.server_stats.mixin.server;

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,36 @@
package net.lostluma.server_stats.mixin.server;

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 = "main", at = @At("HEAD"))
private static void onMain(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));
}

// 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.lostluma.server_stats.mixin.server;

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;

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

@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.lostluma.server_stats.mixin.server;

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,22 @@
package net.lostluma.server_stats.mixin.server.stats;

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.CallbackInfoReturnable;

import net.lostluma.server_stats.stats.Stats;
import net.minecraft.entity.FishingBobberEntity;
import net.minecraft.entity.living.player.PlayerEntity;

@Mixin(FishingBobberEntity.class)
public class FishingBobberEntityMixin {
@Shadow
public PlayerEntity player;

@Inject(method = "retract", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void onRetract(CallbackInfoReturnable<?> callbackInfo) {
this.player.server_stats$incrementStat(Stats.FISH_CAUGHT, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.lostluma.server_stats.mixin.server.stats;

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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.lostluma.server_stats.stats.Stats;
import net.minecraft.entity.living.LivingEntity;
import net.minecraft.entity.living.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

@Mixin(ItemStack.class)
public class ItemStackMixin {
@Shadow
public int size;

@Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void use(PlayerEntity player, World world, int x, int y, int z, int face, CallbackInfoReturnable<?> callbackInfo) {
var stack = (ItemStack)(Object)this;
player.server_stats$incrementStat(Stats.ITEMS_USED[stack.itemId], 1);
}

@Inject(method = "damageAndBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void damageAndBreak(int amount, LivingEntity entity, CallbackInfo callbackInfo) {
var stack = (ItemStack)(Object)this;
var player = (PlayerEntity)(Object)entity;

player.server_stats$incrementStat(Stats.ITEMS_BROKEN[stack.itemId], 1);
}

@Inject(method = "attackEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void attackEntity(LivingEntity entity, PlayerEntity player, CallbackInfo callbackInfo) {
var stack = (ItemStack)(Object)this;
player.server_stats$incrementStat(Stats.ITEMS_USED[stack.itemId], 1);
}

@Inject(method = "mineBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void mineBlock(int blockId, int x, int y, int z, PlayerEntity player, CallbackInfo callbackInfo) {
var stack = (ItemStack)(Object)this;
player.server_stats$incrementStat(Stats.ITEMS_USED[stack.itemId], 1);
}

@Inject(method = "onResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/living/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;I)V"))
private void onResult(World world, PlayerEntity player, CallbackInfo callbackInfo) {
var stack = (ItemStack)(Object)this;
player.server_stats$incrementStat(Stats.ITEMS_CRAFTED[stack.itemId], this.size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.lostluma.server_stats.mixin.server.stats;

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;
import net.minecraft.entity.living.player.PlayerEntity;
import net.minecraft.world.World;

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

@Inject(method = "setWorld(Lnet/minecraft/world/World;Ljava/lang/String;Lnet/minecraft/entity/living/player/PlayerEntity;)V", at = @At("HEAD"))
private void detectWorldLeaving(World world, String string, PlayerEntity playerEntity, CallbackInfo callbackInfo) {
if (world == null && this.player != null) {
this.player.server_stats$incrementStat(Stats.GAMES_LEFT, 1);
}
}
}
Loading

0 comments on commit d255a43

Please sign in to comment.