Skip to content

Commit adf169c

Browse files
committed
Merge 1.20.2 into 1.20.3
2 parents 45b734d + 8d5e662 commit adf169c

File tree

3 files changed

+75
-59
lines changed

3 files changed

+75
-59
lines changed

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakerImplMixin.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.embeddedt.modernfix.fabric.mixin.perf.dynamic_resources;
22

3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
35
import net.fabricmc.loader.api.FabricLoader;
46
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
57
import net.minecraft.client.resources.model.*;
@@ -18,7 +20,6 @@
1820
import org.spongepowered.asm.mixin.Shadow;
1921
import org.spongepowered.asm.mixin.injection.At;
2022
import org.spongepowered.asm.mixin.injection.Inject;
21-
import org.spongepowered.asm.mixin.injection.ModifyVariable;
2223
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2324

2425
import java.lang.invoke.MethodHandle;
@@ -53,22 +54,13 @@ public abstract class ModelBakerImplMixin implements IExtendedModelBaker {
5354
}
5455
}
5556

56-
private ResourceLocation capturedLocation;
57-
private UnbakedModel capturedModel;
58-
private ModelState capturedState;
59-
6057
private boolean throwIfMissing;
6158

6259
@Override
6360
public void throwOnMissingModel() {
6461
throwIfMissing = true;
6562
}
6663

67-
@Inject(method = "bake", at = @At("HEAD"))
68-
private void captureState(ResourceLocation rl, ModelState state, CallbackInfoReturnable<BakedModel> cir) {
69-
capturedState = state;
70-
}
71-
7264
@Inject(method = "getModel", at = @At("HEAD"), cancellable = true)
7365
private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedModel> cir) {
7466
if(debugDynamicModelLoading)
@@ -109,10 +101,6 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
109101
}
110102
cir.setReturnValue(toReplace);
111103
cir.getReturnValue().resolveParents(this.field_40571::getModel);
112-
if(capturedLocation == null) {
113-
capturedLocation = arg;
114-
capturedModel = cir.getReturnValue();
115-
}
116104
if(cir.getReturnValue() == extendedBakery.mfix$getUnbakedMissingModel()) {
117105
if(arg != ModelBakery.MISSING_MODEL_LOCATION) {
118106
if(debugDynamicModelLoading)
@@ -123,31 +111,17 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
123111
}
124112
}
125113

126-
@ModifyVariable(method = "bake", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;"))
127-
private BakedModel unifyMissingBakedModel(BakedModel model) {
128-
// Save these variables in case the nested model calls getModel somehow
129-
ResourceLocation location = this.capturedLocation;
130-
UnbakedModel unbakedModel = this.capturedModel;
131-
ModelState state = this.capturedState;
132-
133-
// Safety check
134-
if(location == null) {
135-
return model;
136-
}
114+
@WrapOperation(method = "bake", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;"))
115+
private BakedModel callBakedModelIntegration(UnbakedModel unbakedModel, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState state, ResourceLocation location, Operation<BakedModel> operation) {
116+
BakedModel model = operation.call(unbakedModel, baker, spriteGetter, state, location);
137117

138118
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
139119
model = integration.onBakedModelLoad(location, unbakedModel, model, state, this.field_40571);
140120
}
141121

142-
// Allow more capturing
143-
this.capturedLocation = null;
144-
this.capturedModel = null;
145-
146122
return model;
147123
}
148124

149-
150-
151125
/**
152126
* @author embeddedt
153127
* @reason emulate old function, to allow injectors to work
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.embeddedt.modernfix.forge.mixin.perf.forge_registry_alloc;
2+
3+
import net.minecraft.core.Holder;
4+
import net.minecraft.resources.ResourceKey;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraftforge.registries.ForgeRegistry;
7+
import org.spongepowered.asm.mixin.Final;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Overwrite;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
12+
import java.util.Locale;
13+
import java.util.Map;
14+
15+
@Mixin(value = ForgeRegistry.class, remap = false)
16+
public abstract class ForgeRegistryMixin<V> {
17+
@Shadow @Final private Map<ResourceLocation, Holder.Reference<V>> delegatesByName;
18+
19+
@Shadow @Final private Map<V, Holder.Reference<V>> delegatesByValue;
20+
21+
/**
22+
* @author embeddedt
23+
* @reason stop allocating so many unneeded objects. stop.
24+
*/
25+
@Overwrite
26+
public Holder.Reference<V> getDelegateOrThrow(ResourceLocation location) {
27+
Holder.Reference<V> holder = delegatesByName.get(location);
28+
29+
if (holder == null) {
30+
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for location %s", location));
31+
}
32+
33+
return holder;
34+
}
35+
36+
/**
37+
* @author embeddedt
38+
* @reason see above
39+
*/
40+
@Overwrite
41+
public Holder.Reference<V> getDelegateOrThrow(ResourceKey<V> rkey) {
42+
Holder.Reference<V> holder = delegatesByName.get(rkey.location());
43+
44+
if (holder == null) {
45+
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for key %s", rkey));
46+
}
47+
48+
return holder;
49+
}
50+
51+
/**
52+
* @author embeddedt
53+
* @reason see above
54+
*/
55+
@Overwrite
56+
public Holder.Reference<V> getDelegateOrThrow(V value) {
57+
Holder.Reference<V> holder = delegatesByValue.get(value);
58+
59+
if (holder == null) {
60+
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for value %s", value));
61+
}
62+
63+
return holder;
64+
}
65+
}

neoforge/src/main/java/org/embeddedt/modernfix/neoforge/mixin/perf/dynamic_resources/ModelBakerImplMixin.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.embeddedt.modernfix.neoforge.mixin.perf.dynamic_resources;
22

33
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
5+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
46
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
57
import net.minecraft.client.resources.model.*;
68
import net.minecraft.resources.ResourceLocation;
@@ -34,22 +36,13 @@ public abstract class ModelBakerImplMixin implements IModelBakerImpl, IExtendedM
3436
mfix$ignoreCache = true;
3537
}
3638

37-
private ResourceLocation capturedLocation;
38-
private UnbakedModel capturedModel;
39-
private ModelState capturedState;
40-
4139
private boolean throwIfMissing;
4240

4341
@Override
4442
public void throwOnMissingModel() {
4543
throwIfMissing = true;
4644
}
4745

48-
@Inject(method = "bake(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/resources/model/ModelState;Ljava/util/function/Function;)Lnet/minecraft/client/resources/model/BakedModel;", at = @At("HEAD"), remap = false)
49-
private void captureState(ResourceLocation arg, ModelState state, Function<Material, TextureAtlasSprite> sprites, CallbackInfoReturnable<BakedModel> cir) {
50-
capturedState = state;
51-
}
52-
5346
@Inject(method = "getModel", at = @At("HEAD"), cancellable = true)
5447
private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedModel> cir) {
5548
if(debugDynamicModelLoading)
@@ -77,10 +70,6 @@ private void obtainModel(ResourceLocation arg, CallbackInfoReturnable<UnbakedMod
7770
}
7871
cir.setReturnValue(toReplace);
7972
cir.getReturnValue().resolveParents(this.field_40571::getModel);
80-
if(capturedLocation == null) {
81-
capturedLocation = arg;
82-
capturedModel = cir.getReturnValue();
83-
}
8473
if(cir.getReturnValue() == extendedBakery.mfix$getUnbakedMissingModel()) {
8574
if(arg != ModelBakery.MISSING_MODEL_LOCATION) {
8675
if(debugDynamicModelLoading)
@@ -96,26 +85,14 @@ private Object ignoreCacheIfRequested(Object o) {
9685
return mfix$ignoreCache ? null : o;
9786
}
9887

99-
@ModifyExpressionValue(method = "bake(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/resources/model/ModelState;Ljava/util/function/Function;)Lnet/minecraft/client/resources/model/BakedModel;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;"))
100-
private BakedModel unifyMissingBakedModel(BakedModel model) {
101-
// Save these variables in case the nested model calls getModel somehow
102-
ResourceLocation location = this.capturedLocation;
103-
UnbakedModel unbakedModel = this.capturedModel;
104-
ModelState state = this.capturedState;
105-
106-
// Safety check
107-
if(location == null) {
108-
return model;
109-
}
88+
@WrapOperation(method = "bake(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/resources/model/ModelState;Ljava/util/function/Function;)Lnet/minecraft/client/resources/model/BakedModel;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/UnbakedModel;bake(Lnet/minecraft/client/resources/model/ModelBaker;Ljava/util/function/Function;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/BakedModel;"))
89+
private BakedModel callBakedModelIntegration(UnbakedModel unbakedModel, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState state, ResourceLocation location, Operation<BakedModel> operation) {
90+
BakedModel model = operation.call(unbakedModel, baker, spriteGetter, state, location);
11091

11192
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
11293
model = integration.onBakedModelLoad(location, unbakedModel, model, state, this.field_40571);
11394
}
11495

115-
// Allow more capturing
116-
this.capturedLocation = null;
117-
this.capturedModel = null;
118-
11996
return model;
12097
}
12198
}

0 commit comments

Comments
 (0)