Changed models loading (Done)
This commit is contained in:
parent
831faeb306
commit
5da634fc73
63 changed files with 490 additions and 729 deletions
|
@ -2,7 +2,6 @@ package ru.betterend.mixin.client;
|
|||
|
||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
|
@ -10,6 +9,7 @@ import net.minecraft.client.resources.model.UnbakedModel;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -20,17 +20,13 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelProvider;
|
||||
import ru.betterend.client.models.ItemModelProvider;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(ModelBakery.class)
|
||||
|
@ -45,11 +41,8 @@ public abstract class ModelLoaderMixin {
|
|||
@Shadow
|
||||
protected abstract void cacheAndQueueDependencies(ResourceLocation resourceLocation, UnbakedModel unbakedModel);
|
||||
|
||||
@Shadow
|
||||
protected abstract BlockModel loadBlockModel(ResourceLocation resourceLocation);
|
||||
|
||||
@Inject(method = "loadModel", at = @At("HEAD"), cancellable = true)
|
||||
private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) throws IOException {
|
||||
private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
if (resourceLocation instanceof ModelResourceLocation) {
|
||||
String modId = resourceLocation.getNamespace();
|
||||
String path = resourceLocation.getPath();
|
||||
|
@ -60,8 +53,17 @@ public abstract class ModelLoaderMixin {
|
|||
ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
|
||||
if (!resourceManager.hasResource(itemModelLoc)) {
|
||||
Item item = Registry.ITEM.get(clearLoc);
|
||||
if (item instanceof ModelProvider) {
|
||||
BlockModel model = ((ModelProvider) item).getModel(clearLoc);
|
||||
ItemModelProvider modelProvider = null;
|
||||
if (item instanceof ItemModelProvider) {
|
||||
modelProvider = (ItemModelProvider) item;
|
||||
} else if (item instanceof BlockItem) {
|
||||
Block block = Registry.BLOCK.get(clearLoc);
|
||||
if (block instanceof ItemModelProvider) {
|
||||
modelProvider = (ItemModelProvider) block;
|
||||
}
|
||||
}
|
||||
if (modelProvider != null) {
|
||||
BlockModel model = modelProvider.getItemModel(clearLoc);
|
||||
if (model != null) {
|
||||
model.name = itemLoc.toString();
|
||||
cacheAndQueueDependencies(modelId, model);
|
||||
|
@ -102,59 +104,6 @@ public abstract class ModelLoaderMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "loadBlockModel", at = @At("HEAD"), cancellable = true)
|
||||
private void be_loadModelPattern(ResourceLocation modelId, CallbackInfoReturnable<BlockModel> info) throws IOException {
|
||||
ResourceLocation modelLocation = new ResourceLocation(modelId.getNamespace(), "models/" + modelId.getPath() + ".json");
|
||||
if (!resourceManager.hasResource(modelLocation)) {
|
||||
String[] data = modelId.getPath().split("/");
|
||||
if (data.length > 1) {
|
||||
ResourceLocation itemId = new ResourceLocation(modelId.getNamespace(), data[1]);
|
||||
Optional<Block> block = Registry.BLOCK.getOptional(itemId);
|
||||
if (block.isPresent()) {
|
||||
if (block.get() instanceof ModelProvider) {
|
||||
ModelProvider modelProvider = (ModelProvider) block.get();
|
||||
Optional<BlockModel> model = be_getModel(data, modelId, modelProvider);
|
||||
if (model.isPresent()) {
|
||||
info.setReturnValue(model.get());
|
||||
} else {
|
||||
throw new FileNotFoundException("Error loading model: " + modelId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Optional<Item> item = Registry.ITEM.getOptional(itemId);
|
||||
if (item.isPresent() && item.get() instanceof ModelProvider) {
|
||||
ModelProvider modelProvider = (ModelProvider) item.get();
|
||||
Optional<BlockModel> model = be_getModel(data, modelId, modelProvider);
|
||||
if (model.isPresent()) {
|
||||
info.setReturnValue(model.get());
|
||||
} else {
|
||||
throw new FileNotFoundException("Error loading model: " + modelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<BlockModel> be_getModel(String[] data, ResourceLocation id, ModelProvider modelProvider) {
|
||||
Optional<String> pattern;
|
||||
if (id.getPath().contains("item")) {
|
||||
pattern = modelProvider.getModelString(id.getPath());
|
||||
} else {
|
||||
if (data.length > 2) {
|
||||
pattern = modelProvider.getModelString(data[2]);
|
||||
} else {
|
||||
pattern = modelProvider.getModelString(data[1]);
|
||||
}
|
||||
}
|
||||
if (pattern.isPresent()) {
|
||||
BlockModel model = BlockModel.fromString(pattern.get());
|
||||
model.name = id.toString();
|
||||
return Optional.of(model);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
|
||||
public ResourceLocation be_switchModel(ResourceLocation id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue