Patterns refactor
This commit is contained in:
parent
ce8ae2e7fe
commit
14434e4028
33 changed files with 397 additions and 356 deletions
|
@ -3,6 +3,7 @@ package ru.betterend.mixin.client;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -17,13 +18,15 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.json.JsonUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelVariantMap.DeserializationContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.interfaces.IdentifiedContext;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
import ru.betterend.patterns.Patterned;
|
||||
|
||||
@Mixin(ModelLoader.class)
|
||||
public class ModelLoaderMixin {
|
||||
|
@ -50,29 +53,46 @@ public class ModelLoaderMixin {
|
|||
} catch (Exception ex) {
|
||||
String data[] = id.getPath().split("/");
|
||||
if (data.length > 1) {
|
||||
Identifier blockId = new Identifier(id.getNamespace(), data[1]);
|
||||
Block block = Registry.BLOCK.get(blockId);
|
||||
if (block instanceof Patterned) {
|
||||
String pattern;
|
||||
if (id.getPath().contains("item")) {
|
||||
pattern = ((Patterned) block).getModelPattern(id.getPath());
|
||||
} else {
|
||||
if (data.length > 2) {
|
||||
pattern = ((Patterned) block).getModelPattern(data[2]);
|
||||
} else {
|
||||
pattern = ((Patterned) block).getModelPattern(data[1]);
|
||||
}
|
||||
Identifier itemId = new Identifier(id.getNamespace(), data[1]);
|
||||
Optional<Block> block = Registry.BLOCK.getOrEmpty(itemId);
|
||||
if (block.isPresent()) {
|
||||
if (block.get() instanceof Patterned) {
|
||||
Patterned patterned = (Patterned) block.get();
|
||||
model = this.be_getModel(data, id, patterned);
|
||||
info.setReturnValue(model);
|
||||
info.cancel();
|
||||
}
|
||||
} else {
|
||||
Optional<Item> item = Registry.ITEM.getOrEmpty(itemId);
|
||||
if (item.isPresent() && item.get() instanceof Patterned) {
|
||||
Patterned patterned = (Patterned) item.get();
|
||||
model = this.be_getModel(data, id, patterned);
|
||||
info.setReturnValue(model);
|
||||
info.cancel();
|
||||
}
|
||||
model = JsonUnbakedModel.deserialize(pattern);
|
||||
model.id = id.toString();
|
||||
info.setReturnValue(model);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JsonUnbakedModel be_getModel(String data[], Identifier id, Patterned patterned) {
|
||||
String pattern;
|
||||
if (id.getPath().contains("item")) {
|
||||
pattern = patterned.getModelPattern(id.getPath());
|
||||
} else {
|
||||
if (data.length > 2) {
|
||||
pattern = patterned.getModelPattern(data[2]);
|
||||
} else {
|
||||
pattern = patterned.getModelPattern(data[1]);
|
||||
}
|
||||
}
|
||||
JsonUnbakedModel model = JsonUnbakedModel.deserialize(pattern);
|
||||
model.id = id.toString();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@Inject(method = "loadModel", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/render/model/json/ModelVariantMap$DeserializationContext;setStateFactory(Lnet/minecraft/state/StateManager;)V",
|
||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraft.client.render.model.json.ModelVariantMap;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.interfaces.IdentifiedContext;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
import ru.betterend.patterns.BlockPatterned;
|
||||
|
||||
@Mixin(ModelVariantMap.class)
|
||||
public abstract class ModelVariantMapMixin {
|
||||
|
@ -33,8 +33,8 @@ public abstract class ModelVariantMapMixin {
|
|||
Identifier blockId = new Identifier(id.getNamespace(), data[1]);
|
||||
Block block = Registry.BLOCK.get(blockId);
|
||||
idContext.removeId();
|
||||
if (block instanceof Patterned) {
|
||||
String pattern = ((Patterned) block).getStatesPattern(reader);
|
||||
if (block instanceof BlockPatterned) {
|
||||
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
|
||||
info.setReturnValue(deserialize(context, new StringReader(pattern)));
|
||||
info.cancel();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.resource.Resource;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
import ru.betterend.patterns.BlockPatterned;
|
||||
|
||||
@Mixin(NamespaceResourceManager.class)
|
||||
public abstract class NamespaceResourceManagerMixin {
|
||||
|
@ -35,9 +35,9 @@ public abstract class NamespaceResourceManagerMixin {
|
|||
if (data.length > 1) {
|
||||
Identifier blockId = BetterEnd.makeID(data[1].replace(".json", ""));
|
||||
Block block = Registry.BLOCK.get(blockId);
|
||||
if (block instanceof Patterned) {
|
||||
if (block instanceof BlockPatterned) {
|
||||
List<Resource> resources = Lists.newArrayList();
|
||||
resources.add(this.getResource(((Patterned) block).statePatternId()));
|
||||
resources.add(this.getResource(((BlockPatterned) block).statePatternId()));
|
||||
info.setReturnValue(resources);
|
||||
info.cancel();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue