BlockStates pattern loading optimization
This commit is contained in:
parent
1847b25aa9
commit
3b96ee6307
7 changed files with 27 additions and 94 deletions
|
@ -1,12 +0,0 @@
|
||||||
package ru.betterend.interfaces;
|
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public interface IdentifiedContext {
|
|
||||||
public Identifier getContextId();
|
|
||||||
public void setContextId(Identifier id);
|
|
||||||
|
|
||||||
default void removeId() {
|
|
||||||
this.setContextId(null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package ru.betterend.mixin.client;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import net.minecraft.client.render.model.json.ModelVariantMap;
|
||||||
|
|
||||||
|
@Mixin(ModelVariantMap.DeserializationContext.class)
|
||||||
|
public interface ContextGsonAccessor {
|
||||||
|
@Accessor
|
||||||
|
public Gson getGson();
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
package ru.betterend.mixin.client;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.render.model.json.ModelVariantMap.DeserializationContext;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import ru.betterend.interfaces.IdentifiedContext;
|
|
||||||
|
|
||||||
@Mixin(DeserializationContext.class)
|
|
||||||
public class DeserializationContextMixin implements IdentifiedContext {
|
|
||||||
|
|
||||||
private Identifier contextId;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier getContextId() {
|
|
||||||
return this.contextId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContextId(Identifier id) {
|
|
||||||
this.contextId = id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,32 +9,24 @@ import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.render.model.ModelLoader;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.render.model.json.JsonUnbakedModel;
|
import net.minecraft.client.render.model.json.JsonUnbakedModel;
|
||||||
import net.minecraft.client.render.model.json.ModelVariantMap.DeserializationContext;
|
|
||||||
import net.minecraft.client.util.ModelIdentifier;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.resource.Resource;
|
import net.minecraft.resource.Resource;
|
||||||
import net.minecraft.resource.ResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.interfaces.IdentifiedContext;
|
|
||||||
import ru.betterend.patterns.Patterned;
|
import ru.betterend.patterns.Patterned;
|
||||||
|
|
||||||
@Mixin(ModelLoader.class)
|
@Mixin(ModelLoader.class)
|
||||||
public class ModelLoaderMixin {
|
public class ModelLoaderMixin {
|
||||||
|
|
||||||
@Final
|
|
||||||
@Shadow
|
|
||||||
private DeserializationContext variantMapDeserializationContext;
|
|
||||||
|
|
||||||
@Final
|
@Final
|
||||||
@Shadow
|
@Shadow
|
||||||
private ResourceManager resourceManager;
|
private ResourceManager resourceManager;
|
||||||
|
@ -92,24 +84,4 @@ public class ModelLoaderMixin {
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "loadModel", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/client/render/model/json/ModelVariantMap$DeserializationContext;setStateFactory(Lnet/minecraft/state/StateManager;)V",
|
|
||||||
shift = Shift.AFTER))
|
|
||||||
private void appendContextID(Identifier id, CallbackInfo info) {
|
|
||||||
IdentifiedContext context = IdentifiedContext.class.cast(variantMapDeserializationContext);
|
|
||||||
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
|
||||||
context.setContextId(BetterEnd.makeID("pattern/" + id.getPath()));
|
|
||||||
} else {
|
|
||||||
context.setContextId(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "loadModel", at = @At("HEAD"))
|
|
||||||
private void loadModel(Identifier id, CallbackInfo info) throws Exception {
|
|
||||||
// if (!(id instanceof ModelIdentifier)) {
|
|
||||||
// System.out.println(id);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,40 +4,29 @@ import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.render.model.json.ModelVariantMap;
|
import net.minecraft.client.render.model.json.ModelVariantMap;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.JsonHelper;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import ru.betterend.interfaces.IdentifiedContext;
|
|
||||||
import ru.betterend.patterns.BlockPatterned;
|
import ru.betterend.patterns.BlockPatterned;
|
||||||
|
|
||||||
@Mixin(ModelVariantMap.class)
|
@Mixin(ModelVariantMap.class)
|
||||||
public abstract class ModelVariantMapMixin {
|
public abstract class ModelVariantMapMixin {
|
||||||
|
|
||||||
@Shadow
|
|
||||||
static ModelVariantMap deserialize(ModelVariantMap.DeserializationContext context, Reader reader) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "deserialize", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "deserialize", at = @At("HEAD"), cancellable = true)
|
||||||
private static void deserializeBlockState(ModelVariantMap.DeserializationContext context, Reader reader, CallbackInfoReturnable<ModelVariantMap> info) {
|
private static void deserializeBlockState(ModelVariantMap.DeserializationContext context, Reader reader, CallbackInfoReturnable<ModelVariantMap> info) {
|
||||||
IdentifiedContext idContext = IdentifiedContext.class.cast(context);
|
Block block = context.getStateFactory().getDefaultState().getBlock();
|
||||||
Identifier id = idContext.getContextId();
|
|
||||||
if (id != null && id.getPath().contains("pattern")) {
|
|
||||||
String[] data = id.getPath().split("/");
|
|
||||||
Identifier blockId = new Identifier(id.getNamespace(), data[1]);
|
|
||||||
Block block = Registry.BLOCK.get(blockId);
|
|
||||||
idContext.removeId();
|
|
||||||
if (block instanceof BlockPatterned) {
|
if (block instanceof BlockPatterned) {
|
||||||
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
|
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
|
||||||
info.setReturnValue(deserialize(context, new StringReader(pattern)));
|
Gson gson = ContextGsonAccessor.class.cast(context).getGson();
|
||||||
info.cancel();
|
ModelVariantMap map = JsonHelper.deserialize(gson, new StringReader(pattern), ModelVariantMap.class);
|
||||||
}
|
info.setReturnValue(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ru.betterend.mixin.client;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -15,23 +14,17 @@ import com.google.common.collect.Lists;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.resource.NamespaceResourceManager;
|
import net.minecraft.resource.NamespaceResourceManager;
|
||||||
import net.minecraft.resource.Resource;
|
import net.minecraft.resource.Resource;
|
||||||
import net.minecraft.resource.ResourcePack;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.patterns.BlockPatterned;
|
import ru.betterend.patterns.BlockPatterned;
|
||||||
|
|
||||||
@Mixin(NamespaceResourceManager.class)
|
@Mixin(NamespaceResourceManager.class)
|
||||||
public abstract class NamespaceResourceManagerMixin {
|
public abstract class NamespaceResourceManagerMixin {
|
||||||
|
|
||||||
@Final
|
|
||||||
@Shadow
|
|
||||||
protected List<ResourcePack> packList;
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public abstract Resource getResource(Identifier id);
|
public abstract Resource getResource(Identifier id);
|
||||||
@Shadow
|
|
||||||
public abstract List<Resource> getAllResources(Identifier id);
|
|
||||||
|
|
||||||
@Inject(method = "getAllResources", cancellable = true, at = @At(
|
@Inject(method = "getAllResources", cancellable = true, at = @At(
|
||||||
value = "NEW",
|
value = "NEW",
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
"AbstractSoundInstanceAccessor",
|
"AbstractSoundInstanceAccessor",
|
||||||
"ClientPlayNetworkHandlerMixin",
|
"ClientPlayNetworkHandlerMixin",
|
||||||
"NamespaceResourceManagerMixin",
|
"NamespaceResourceManagerMixin",
|
||||||
"DeserializationContextMixin",
|
|
||||||
"EnchantingTableBlockMixin",
|
"EnchantingTableBlockMixin",
|
||||||
"BackgroundRendererMixin",
|
"BackgroundRendererMixin",
|
||||||
"ClientRecipeBookMixin",
|
"ClientRecipeBookMixin",
|
||||||
"ModelVariantMapMixin",
|
"ModelVariantMapMixin",
|
||||||
"MinecraftClientMixin",
|
"MinecraftClientMixin",
|
||||||
|
"ContextGsonAccessor",
|
||||||
"WorldRendererMixin",
|
"WorldRendererMixin",
|
||||||
"MusicTrackerMixin",
|
"MusicTrackerMixin",
|
||||||
"AnvilScreenMixin",
|
"AnvilScreenMixin",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue