Change models loading (WIP)

This commit is contained in:
Aleksey 2021-05-15 22:22:33 +03:00
parent de8baa4b83
commit 2910df3078
8 changed files with 129 additions and 41 deletions

View file

@ -1,16 +1,32 @@
package ru.betterend.patterns;
import java.io.Reader;
import java.util.Collections;
import com.mojang.math.Transformation;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.renderer.block.model.Variant;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.apache.commons.lang3.tuple.Pair;
public interface BlockModelProvider extends ModelProvider {
String getStatesPattern(Reader data);
ResourceLocation statePatternId();
Pair<ResourceLocation, BlockModel> getBlockModel(BlockState blockState);
MultiVariant getModelVariant(BlockState blockState);
BlockModel getBlockModel(BlockState blockState);
MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState);
static BlockModel createBlockModel(ResourceLocation blockId, String pattern) {
BlockModel model = BlockModel.fromString(pattern);
ResourceLocation modelLoc = new ResourceLocation(blockId.getNamespace(), "blocks/" + blockId.getPath());
model.name = modelLoc.toString();
return model;
}
static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing) {
Transformation transform = new Transformation(null, facing.getRotation(), null, null);
Variant variant = new Variant(resourceLocation, transform, false, 1);
return new MultiVariant(Collections.singletonList(variant));
}
}

View file

@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import org.jetbrains.annotations.Nullable;
@ -121,6 +122,13 @@ public class Patterns {
public static String createItemGenerated(String name) {
return createJson(ITEM_GENERATED, name);
}
public static String createBlockSimple(String name) {
return Patterns.createJson(Patterns.BLOCK_BASE, name, name);
}
public static String createBlockPillar(String name) {
return Patterns.createJson(Patterns.BLOCK_PILLAR, name, name);
}
public static String createJson(Reader data, String parent, String block) {
try (BufferedReader buffer = new BufferedReader(data)) {
@ -160,4 +168,5 @@ public class Patterns {
return "";
}
}
}