Improve usability of -Dmodernfix.debugReloaders
This commit is contained in:
parent
f6e658fee6
commit
10b65219bc
|
|
@ -8,16 +8,38 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(ProfiledReloadInstance.class)
|
||||
public class ProfiledReloadInstanceMixin {
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason Decorate reload listeners with their class name as well as the simple name
|
||||
*/
|
||||
@ModifyVariable(method = "<init>", at = @At("HEAD"), argsOnly = true, ordinal = 0)
|
||||
private static List<PreparableReloadListener> getWrappedListeners(List<PreparableReloadListener> listeners) {
|
||||
List<PreparableReloadListener> newList = new ArrayList<>(listeners.size());
|
||||
for(PreparableReloadListener listener : listeners) {
|
||||
newList.add(new NamedPreparableResourceListener(listener));
|
||||
// No need to wrap listeners that are already wrapped/provided by a mod loader
|
||||
String className = listener.getClass().getName();
|
||||
if (className.startsWith("net.minecraftforge.") || className.startsWith("net.neoforged.") || className.startsWith("net.fabricmc.")) {
|
||||
newList.add(listener);
|
||||
} else {
|
||||
newList.add(new NamedPreparableResourceListener(listener));
|
||||
}
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason Place most expensive reload listeners first
|
||||
*/
|
||||
@ModifyVariable(method = "finish", ordinal = 0, argsOnly = true, at = @At("HEAD"))
|
||||
private List<ProfiledReloadInstance.State> sortStates(List<ProfiledReloadInstance.State> datapoints) {
|
||||
datapoints = new ArrayList<>(datapoints);
|
||||
datapoints.sort(Comparator.<ProfiledReloadInstance.State>comparingLong(s -> s.preparationNanos.get() + s.reloadNanos.get()).reversed());
|
||||
return datapoints;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,5 +56,8 @@ accessible field net/minecraft/client/renderer/entity/EnderDragonRenderer$Dragon
|
|||
accessible method net/minecraft/world/level/block/state/StateDefinition appendPropertyCodec (Lcom/mojang/serialization/MapCodec;Ljava/util/function/Supplier;Ljava/lang/String;Lnet/minecraft/world/level/block/state/properties/Property;)Lcom/mojang/serialization/MapCodec;
|
||||
accessible class net/minecraft/client/multiplayer/SessionSearchTrees$Key
|
||||
|
||||
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State preparationNanos Ljava/util/concurrent/atomic/AtomicLong;
|
||||
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State reloadNanos Ljava/util/concurrent/atomic/AtomicLong;
|
||||
|
||||
accessible class net/minecraft/world/item/crafting/Ingredient$Value
|
||||
accessible class net/minecraft/world/item/crafting/Ingredient$ItemValue
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package org.embeddedt.modernfix.forge.mixin.feature.measure_time;
|
||||
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(targets = "net/minecraftforge/event/AddReloadListenerEvent$WrappedStateAwareListener")
|
||||
public abstract class AddReloadListenerEventWrapperMixin implements PreparableReloadListener {
|
||||
@Shadow @Final private PreparableReloadListener wrapped;
|
||||
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason make a proper name show up in ProfiledReloadInstance
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.wrapped.getClass().getName();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user