Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/stats' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Sep 1, 2024
2 parents d2fdce4 + 12382b2 commit 8f0dbf2
Show file tree
Hide file tree
Showing 26 changed files with 551 additions and 31 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/Hodgepodge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

import com.mitchej123.hodgepodge.client.HodgepodgeClient;
import com.mitchej123.hodgepodge.commands.DebugCommand;
import com.mitchej123.hodgepodge.config.TweaksConfig;
import com.mitchej123.hodgepodge.net.NetworkHandler;
import com.mitchej123.hodgepodge.util.AnchorAlarm;
import com.mitchej123.hodgepodge.util.StatHandler;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ICrashCallable;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLModIdMappingEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.versioning.ArtifactVersion;
Expand Down Expand Up @@ -90,6 +94,20 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
EVENT_HANDLER.setAidTriggerDisabled(false);
}

@EventHandler
public void onServerStarted(FMLServerStartedEvent event) {
if (TweaksConfig.addModEntityStats) {
StatHandler.addEntityStats();
}
}

@EventHandler
public void onModIdMapping(FMLModIdMappingEvent event) {
if (TweaksConfig.addModItemStats) {
StatHandler.remap(event.remappedIds);
}
}

/**
* Block any clients older than 2.5.36 from joining servers to ensure the fastBlockPlacingDisableServerSide setting
* is respected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ private void printHelp(ICommandSender sender) {
"\"randomNbt [bytes]\" - adds a random byte array of the given size to the held item"));
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] ss) {
public List<String> addTabCompletionOptions(ICommandSender sender, String[] ss) {
List<String> l = new ArrayList<>();
String test = ss.length == 0 ? "" : ss[0].trim();
if (ss.length == 0 || ss.length == 1
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/config/TweaksConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ public class TweaksConfig {
@Config.RequiresMcRestart
public static boolean unbindKeybindsByDefault;

@Config.Comment("Adds non-vanilla blocks/items to the statistics")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean addModItemStats;

@Config.Comment("Adds non-vanilla entities to the statistics")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean addModEntityStats;

@Config.Comment("No stats will be registered for these enties (e.g. because another mod already adds them)")
@Config.DefaultStringList({ "Mob", "Monster" })
@Config.RequiresMcRestart
public static String[] entityStatsExclusions;

@Config.Comment("Sort Mob stats lexicographically (Requires addModEntityStats)")
@Config.DefaultBoolean(true)
public static boolean sortEntityStats;

// Automagy

@Config.Comment("Implement container for thirsty tank")
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public enum Mixins {
FIX_BOGUS_INTEGRATED_SERVER_NPE(new Builder("Fix bogus FMLProxyPacket NPEs on integrated server crashes")
.setPhase(Phase.EARLY).setSide(Side.BOTH)
.addMixinClasses(
"forge.MixinFMLProxyPacket",
"forge.MixinNetworkDispatcher",
"fml.MixinFMLProxyPacket",
"fml.MixinNetworkDispatcher",
"minecraft.NetworkManagerAccessor")
.setApplyIf(() -> FixesConfig.fixBogusIntegratedServerNPEs).addTargetedMod(TargetedMod.VANILLA)),

Expand Down Expand Up @@ -277,7 +277,7 @@ public enum Mixins {
.setPhase(Phase.EARLY).addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.enhanceNightVision)
.addMixinClasses("minecraft.MixinEntityRenderer_EnhanceNightVision")),
OPTIMIZE_ASMDATATABLE_INDEX(new Builder("Optimize ASM DataTable Index").setPhase(Phase.EARLY).setSide(Side.BOTH)
.addMixinClasses("forge.MixinASMDataTable").setApplyIf(() -> SpeedupsConfig.optimizeASMDataTable)
.addMixinClasses("fml.MixinASMDataTable").setApplyIf(() -> SpeedupsConfig.optimizeASMDataTable)
.addTargetedMod(TargetedMod.VANILLA)),
SQUASH_BED_ERROR_MESSAGE(new Builder("Stop \"You can only sleep at night\" message filling the chat")
.addMixinClasses("minecraft.MixinNetHandlerPlayClient").addTargetedMod(TargetedMod.VANILLA)
Expand All @@ -297,7 +297,7 @@ public enum Mixins {
.addMixinClasses("forge.MixinGuiIngameForge_CrosshairInvertColors").setSide(Side.CLIENT)
.setApplyIf(() -> TweaksConfig.dontInvertCrosshairColor).addTargetedMod(TargetedMod.VANILLA)),
FIX_OPENGUIHANDLER_WINDOWID(new Builder("Fix OpenGuiHandler").setPhase(Phase.EARLY).setSide(Side.BOTH)
.addMixinClasses("forge.MixinOpenGuiHandler").setApplyIf(() -> FixesConfig.fixForgeOpenGuiHandlerWindowId)
.addMixinClasses("fml.MixinOpenGuiHandler").setApplyIf(() -> FixesConfig.fixForgeOpenGuiHandlerWindowId)
.addTargetedMod(TargetedMod.VANILLA)),
FIX_KEYBIND_CONFLICTS(new Builder("Trigger all conflicting keybinds").setPhase(Phase.EARLY).setSide(Side.CLIENT)
.addMixinClasses("minecraft.MixinKeyBinding", "minecraft.MixinMinecraft_UpdateKeys")
Expand Down Expand Up @@ -398,6 +398,19 @@ public enum Mixins {
.addMixinClasses("minecraft.MixinMinecraft_FixDuplicateSounds")
.setApplyIf(() -> FixesConfig.fixDuplicateSounds)),

ADD_MOD_ITEM_STATS(new Builder("Add stats for modded items").addMixinClasses("fml.MixinGameRegistry")
.addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.addModItemStats).setPhase(Phase.EARLY)
.setSide(Side.BOTH)),

ADD_MOD_ENTITY_STATS(new Builder("Add stats for modded entities").addMixinClasses("minecraft.MixinStatList")
.addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.addModEntityStats).setPhase(Phase.EARLY)
.setSide(Side.BOTH)),

ADD_MOD_ENTITY_STATS_CLIENT(new Builder("Add stats for modded entities (client side)")
.addMixinClasses("minecraft.MixinStatsMobsList", "minecraft.MixinStatsBlock", "minecraft.MixinStatsItem")
.addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.addModEntityStats).setPhase(Phase.EARLY)
.setSide(Side.CLIENT)),

FIX_SLASH_COMMAND(
new Builder("Fix forge command handler not checking for a / and also not running commands with any case")
.setPhase(Phase.EARLY).setSide(Side.CLIENT).addTargetedMod(TargetedMod.VANILLA)
Expand Down Expand Up @@ -453,10 +466,10 @@ public enum Mixins {
"ic2.MixinIC2ArmorSolarHelmet",
"ic2.MixinIC2ArmorStaticBoots")
.setApplyIf(() -> FixesConfig.fixIc2ArmorLag).addTargetedMod(TargetedMod.IC2)),
IC2_RESOURCE_PACK_TRANSLATION_FIX(new Builder("IC2 Resource Pack Translation Fix").setPhase(Phase.EARLY)
.setSide(Side.CLIENT)
.addMixinClasses("forge.MixinLanguageRegistry", "forge.MixinFMLClientHandler", "ic2.MixinLocalization")
.setApplyIf(() -> FixesConfig.fixIc2ResourcePackTranslation).addTargetedMod(TargetedMod.IC2)),
IC2_RESOURCE_PACK_TRANSLATION_FIX(
new Builder("IC2 Resource Pack Translation Fix").setPhase(Phase.EARLY).setSide(Side.CLIENT)
.addMixinClasses("fml.MixinLanguageRegistry", "fml.MixinFMLClientHandler", "ic2.MixinLocalization")
.setApplyIf(() -> FixesConfig.fixIc2ResourcePackTranslation).addTargetedMod(TargetedMod.IC2)),

// Disable update checkers
BIBLIOCRAFT_UPDATE_CHECK(new Builder("Yeet Bibliocraft Update Check").setPhase(Phase.LATE).setSide(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

import java.io.File;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

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,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

import net.minecraft.network.Packet;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.mitchej123.hodgepodge.mixins.early.fml;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.stats.StatCrafting;
import net.minecraft.stats.StatList;
import net.minecraft.util.ChatComponentTranslation;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.mitchej123.hodgepodge.Common;

import cpw.mods.fml.common.registry.GameRegistry;

@Mixin(GameRegistry.class)
public class MixinGameRegistry {

@ModifyExpressionValue(
at = @At(
target = "Lcpw/mods/fml/common/registry/GameData;registerItem(Lnet/minecraft/item/Item;Ljava/lang/String;)I",
value = "INVOKE"),
method = "registerBlock(Lnet/minecraft/block/Block;Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/block/Block;",
remap = false)
private static int hodgepodge$registerBlockStats(int itemId, Block block, Class<? extends ItemBlock> itemclass,
String name, Object[] itemCtorArgs, @Local ItemBlock i) {
if (block.getEnableStats()) {
StatCrafting statMine = hodgepodge$createAndRegisterStat("stat.mineBlock", i);
StatList.mineBlockStatArray[itemId] = statMine;
StatList.objectMineStats.add(statMine);
}
StatList.objectUseStats[itemId] = hodgepodge$createAndRegisterStat("stat.useItem", i);
StatList.objectCraftStats[itemId] = hodgepodge$createAndRegisterStat("stat.craftItem", i);
return itemId;
}

@ModifyExpressionValue(
at = @At(
target = "Lcpw/mods/fml/common/registry/GameData;registerItem(Lnet/minecraft/item/Item;Ljava/lang/String;)I",
value = "INVOKE"),
method = "registerItem(Lnet/minecraft/item/Item;Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/item/Item;",
remap = false)
private static int hodgepodge$registerItemStats(int itemId, Item item, String name, String modId) {
if (item.isDamageable()) {
StatList.objectBreakStats[itemId] = hodgepodge$createAndRegisterStat("stat.breakItem", item);
}
StatCrafting statCraft = hodgepodge$createAndRegisterStat("stat.useItem", item);
StatList.objectUseStats[itemId] = statCraft;
if (!(item instanceof ItemBlock)) {
StatList.itemStats.add(statCraft);
}
StatList.objectCraftStats[itemId] = hodgepodge$createAndRegisterStat("stat.craftItem", item);
return itemId;
}

@Unique
private static StatCrafting hodgepodge$createAndRegisterStat(String key, Item item) {
String unlocalizedName;
try {
unlocalizedName = item.getUnlocalizedName();
} catch (Exception e) {
String registryName = item.delegate.name();
unlocalizedName = "item." + registryName + ".name";
Common.log.warn(
"An Exception occured while invoking Item.getUnlocalizedName() after registering the item {} ({})! Using fallback unlocalized name.",
registryName,
item.getClass().getName());
}
StatCrafting stat = new StatCrafting(
key + ".autogen." + item.delegate.name(),
new ChatComponentTranslation(key, new ChatComponentTranslation(unlocalizedName)),
item);
stat.registerStat();
return stat;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

import java.lang.ref.WeakReference;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mitchej123.hodgepodge.mixins.early.forge;
package com.mitchej123.hodgepodge.mixins.early.fml;

import static org.objectweb.asm.Opcodes.PUTFIELD;

Expand All @@ -21,7 +21,7 @@
import cpw.mods.fml.common.network.internal.OpenGuiHandler;
import io.netty.channel.SimpleChannelInboundHandler;

@Mixin(value = { OpenGuiHandler.class })
@Mixin(value = OpenGuiHandler.class)
public abstract class MixinOpenGuiHandler extends SimpleChannelInboundHandler<FMLMessage.OpenGui> {

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;

@Mixin(GuiIngameForge.class)
public class MixinGuiIngameForge_CrosshairInvertColors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import com.mitchej123.hodgepodge.mixins.early.fml.MixinLanguageRegistry;
import com.mitchej123.hodgepodge.mixins.hooks.IC2ResourcePack;

import cpw.mods.fml.common.registry.LanguageRegistry;
import ic2.core.init.Localization;

Expand All @@ -17,8 +20,8 @@ public class MixinLocalization {
/**
* Translations are delegated to vanilla lang system
*
* @see com.mitchej123.hodgepodge.mixins.early.forge.MixinLanguageRegistry
* @see com.mitchej123.hodgepodge.mixins.hooks.IC2ResourcePack
* @see MixinLanguageRegistry
* @see IC2ResourcePack
*/
@Redirect(
method = "postInit",
Expand All @@ -32,8 +35,8 @@ public class MixinLocalization {
/**
* @author miozune
* @reason Translations are delegated to vanilla lang system
* @see com.mitchej123.hodgepodge.mixins.early.forge.MixinLanguageRegistry
* @see com.mitchej123.hodgepodge.mixins.hooks.IC2ResourcePack
* @see MixinLanguageRegistry
* @see IC2ResourcePack
*/
@Overwrite(remap = false)
protected static Map<String, String> getStringTranslateMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.mitchej123.hodgepodge.config.TweaksConfig;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public abstract class MixinEntityPlayerMP extends EntityLivingBase {
ServersideAttributeMap oldAttributeMap = (ServersideAttributeMap) oldPlayer.getAttributeMap();

// Grab the watched attributes
@SuppressWarnings("unchecked")
Collection<IAttributeInstance> watchedAttribs = oldAttributeMap.getWatchedAttributes();

if (!watchedAttribs.isEmpty()) {
Expand Down Expand Up @@ -64,7 +63,6 @@ public abstract class MixinEntityPlayerMP extends EntityLivingBase {
}

// Helper method based on 1.12
@SuppressWarnings("unchecked")
@Unique
private Collection<AttributeModifier> getModifiers(ModifiableAttributeInstance attr) {
Set<AttributeModifier> toReturn = Sets.newHashSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;

@Mixin(GuiContainerCreative.class)
public abstract class MixinGuiContainerCreative extends GuiContainer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;

@Mixin(GuiNewChat.class)
public abstract class MixinGuiNewChat_TransparentChat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class MixinServerConfigurationManager {
private void hodgepodge$sendEntityProperties(EntityPlayerMP player, int dimension, Teleporter teleporter,
CallbackInfo ci) {
ServersideAttributeMap attributeMap = (ServersideAttributeMap) player.getAttributeMap();
@SuppressWarnings("unchecked")
Collection<IAttributeInstance> watchedAttribs = attributeMap.getWatchedAttributes();
if (!watchedAttribs.isEmpty()) {
player.playerNetServerHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.entity.EntityList.EntityEggInfo;
import net.minecraft.stats.StatList;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mitchej123.hodgepodge.util.StatHandler;
import com.mitchej123.hodgepodge.util.StatHandler.EntityInfo;

@Mixin(StatList.class)
public class MixinStatList {

@ModifyExpressionValue(
at = @At(
target = "Lnet/minecraft/entity/EntityList;getStringFromID(I)Ljava/lang/String;",
value = "INVOKE"),
method = { "func_151182_a", "func_151176_b" }) // these methods create and register the stats for
// killing/being killed by the specified entity
private static String hodgepodge$getEntityName(String original, EntityEggInfo info) {
if (info instanceof EntityInfo) {
return StatHandler.currentEntityName;
}
return original;
}

}
Loading

0 comments on commit 8f0dbf2

Please sign in to comment.