Change loading models (WIP)
This commit is contained in:
parent
6447ec6026
commit
de8baa4b83
5 changed files with 34 additions and 20 deletions
|
@ -2,13 +2,10 @@ package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
|
||||||
import ru.betterend.patterns.Patterns;
|
import ru.betterend.patterns.Patterns;
|
||||||
|
|
||||||
public class BarkBlock extends EndPillarBlock {
|
public class BarkBlock extends EndPillarBlock {
|
||||||
|
@ -29,7 +26,7 @@ public class BarkBlock extends EndPillarBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Triple<ResourceLocation, MultiVariant, BlockModel> getBlockModels(BlockState blockState) {
|
public MultiVariant getModelVariant(BlockState blockState) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
|
||||||
import ru.betterend.patterns.BlockModelProvider;
|
import ru.betterend.patterns.BlockModelProvider;
|
||||||
import ru.betterend.patterns.Patterns;
|
import ru.betterend.patterns.Patterns;
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ public class BlockBase extends Block implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel() {
|
public BlockModel getModel() {
|
||||||
return getBlockModels(defaultBlockState());
|
return getModelVariant(defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,7 +48,7 @@ public class BlockBase extends Block implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Triple<ResourceLocation, MultiVariant, BlockModel> getBlockModels(BlockState blockState) {
|
public MultiVariant getModelVariant(BlockState blockState) {
|
||||||
return BlockModel.fromString(getModelString(""));
|
return BlockModel.fromString(getModelString(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@ import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||||
import net.minecraft.world.level.material.MaterialColor;
|
import net.minecraft.world.level.material.MaterialColor;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import ru.betterend.blocks.BlockProperties;
|
import ru.betterend.blocks.BlockProperties;
|
||||||
import ru.betterend.patterns.BlockModelProvider;
|
import ru.betterend.patterns.BlockModelProvider;
|
||||||
|
@ -94,20 +95,34 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Triple<ResourceLocation, MultiVariant, BlockModel> getBlockModels(BlockState blockState) {
|
public Pair<ResourceLocation, BlockModel> getBlockModel(BlockState blockState) {
|
||||||
Direction facing = blockState.getValue(FACING);
|
Direction facing = blockState.getValue(FACING);
|
||||||
int destruction = blockState.getValue(DESTRUCTION);
|
int destruction = blockState.getValue(DESTRUCTION);
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation modelId = new ResourceLocation(blockId.getNamespace(),
|
ResourceLocation modelId = createModelId(blockId, facing, destruction);
|
||||||
blockId.getPath() + "/" + facing + "/destruction_" + destruction);
|
|
||||||
Transformation transform = new Transformation(null, facing.getRotation(), null, null);
|
|
||||||
Variant variant = new Variant(modelId, transform, false, 1);
|
|
||||||
MultiVariant weightedModel = new MultiVariant(Collections.singletonList(variant));
|
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%anvil%", blockId.getPath());
|
map.put("%anvil%", blockId.getPath());
|
||||||
map.put("%top%", "_top_" + destruction);
|
map.put("%top%", "_top_" + destruction);
|
||||||
String jsonString = Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
String jsonString = Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
||||||
BlockModel blockModel = BlockModel.fromString(jsonString);
|
BlockModel blockModel = BlockModel.fromString(jsonString);
|
||||||
return Triple.of(modelId, weightedModel, blockModel);
|
|
||||||
|
return Pair.of(modelId, blockModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultiVariant getModelVariant(BlockState blockState) {
|
||||||
|
Direction facing = blockState.getValue(FACING);
|
||||||
|
int destruction = blockState.getValue(DESTRUCTION);
|
||||||
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
|
ResourceLocation modelId = createModelId(blockId, facing, destruction);
|
||||||
|
Transformation transform = new Transformation(null, facing.getRotation(), null, null);
|
||||||
|
Variant variant = new Variant(modelId, transform, false, 1);
|
||||||
|
|
||||||
|
return new MultiVariant(Collections.singletonList(variant));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ResourceLocation createModelId(ResourceLocation blockId, Direction facing, int destruction) {
|
||||||
|
return new ResourceLocation(blockId.getNamespace(),
|
||||||
|
blockId.getPath() + "/" + facing + "/destruction_" + destruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.server.packs.resources.Resource;
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
@ -78,11 +79,12 @@ public abstract class ModelLoaderMixin {
|
||||||
Block block = Registry.BLOCK.get(clearLoc);
|
Block block = Registry.BLOCK.get(clearLoc);
|
||||||
if (block instanceof BlockModelProvider) {
|
if (block instanceof BlockModelProvider) {
|
||||||
block.getStateDefinition().getPossibleStates().forEach(blockState -> {
|
block.getStateDefinition().getPossibleStates().forEach(blockState -> {
|
||||||
Triple<ResourceLocation, MultiVariant, BlockModel> models = ((BlockModelProvider) block).getBlockModels(blockState);
|
MultiVariant modelVariant = ((BlockModelProvider) block).getModelVariant(blockState);
|
||||||
if (models != null) {
|
Pair<ResourceLocation, BlockModel> modelData = ((BlockModelProvider) block).getBlockModel(blockState);
|
||||||
|
if (modelVariant != null) {
|
||||||
ModelResourceLocation stateLoc = BlockModelShaper.stateToModelLocation(clearLoc, blockState);
|
ModelResourceLocation stateLoc = BlockModelShaper.stateToModelLocation(clearLoc, blockState);
|
||||||
cacheAndQueueDependencies(stateLoc, models.getMiddle());
|
cacheAndQueueDependencies(stateLoc, modelVariant);
|
||||||
unbakedCache.put(models.getLeft(), models.getRight());
|
unbakedCache.put(modelData.getLeft(), modelData.getRight());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
info.cancel();
|
info.cancel();
|
||||||
|
|
|
@ -6,10 +6,11 @@ import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
public interface BlockModelProvider extends ModelProvider {
|
public interface BlockModelProvider extends ModelProvider {
|
||||||
String getStatesPattern(Reader data);
|
String getStatesPattern(Reader data);
|
||||||
ResourceLocation statePatternId();
|
ResourceLocation statePatternId();
|
||||||
Triple<ResourceLocation, MultiVariant, BlockModel> getBlockModels(BlockState blockState);
|
Pair<ResourceLocation, BlockModel> getBlockModel(BlockState blockState);
|
||||||
|
MultiVariant getModelVariant(BlockState blockState);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue