Change models loading (WIP)
This commit is contained in:
parent
f5c91c3aad
commit
8b94c91ea5
6 changed files with 78 additions and 15 deletions
|
@ -48,15 +48,4 @@ public class BlockBase extends Block implements BlockModelProvider {
|
|||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_SIMPLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
String pattern = Patterns.createBlockSimple(blockId.getPath());
|
||||
return BlockModelProvider.createBlockModel(blockId, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
return BlockModelProvider.createBlockSimple(resourceLocation);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -126,4 +128,15 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
|
|||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_SAPLING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||
return BlockModelProvider.createBlockItem(resourceLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
String pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
|
||||
return BlockModel.fromString(pattern);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -42,6 +43,7 @@ import ru.betterend.blocks.BlockProperties;
|
|||
import ru.betterend.blocks.BlockProperties.PedestalState;
|
||||
import ru.betterend.blocks.InfusionPedestal;
|
||||
import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||
import ru.betterend.patterns.BlockModelProvider;
|
||||
import ru.betterend.patterns.Patterns;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
@ -367,7 +369,53 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
|||
}
|
||||
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockModel getModel(ResourceLocation blockId) {
|
||||
return getBlockModel(blockId, defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(parent);
|
||||
String name = blockId.getPath();
|
||||
Map<String, String> textures = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put("%mod%", blockId.getNamespace() );
|
||||
put("%top%", name + "_top");
|
||||
put("%base%", name + "_base");
|
||||
put("%pillar%", name + "_pillar");
|
||||
put("%bottom%", name + "_bottom");
|
||||
}
|
||||
};
|
||||
PedestalState state = blockState.getValue(STATE);
|
||||
String pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
||||
switch (state) {
|
||||
case COLUMN_TOP: {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
|
||||
break;
|
||||
}
|
||||
case COLUMN: {
|
||||
pattern = Patterns.createJson(Patterns.BLOKC_PEDESTAL_COLUMN, textures);
|
||||
break;
|
||||
}
|
||||
case PEDESTAL_TOP: {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_TOP, textures);
|
||||
break;
|
||||
}
|
||||
case BOTTOM: {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_BOTTOM, textures);
|
||||
break;
|
||||
}
|
||||
case PILLAR: {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_PILLAR, textures);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return BlockModelProvider.createBlockModel(resourceLocation, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_PEDESTAL;
|
||||
|
|
|
@ -51,7 +51,7 @@ public abstract class ModelLoaderMixin {
|
|||
|
||||
@Inject(method = "loadModel", at = @At("HEAD"), cancellable = true)
|
||||
private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
if (BetterEnd.isModId(resourceLocation) && resourceLocation instanceof ModelResourceLocation) {
|
||||
if (resourceLocation instanceof ModelResourceLocation) {
|
||||
String modId = resourceLocation.getNamespace();
|
||||
String path = resourceLocation.getPath();
|
||||
ResourceLocation clearLoc = new ResourceLocation(modId, path);
|
||||
|
|
|
@ -15,8 +15,20 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
public interface BlockModelProvider extends ModelProvider {
|
||||
String getStatesPattern(Reader data);
|
||||
ResourceLocation statePatternId();
|
||||
BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState);
|
||||
MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState);
|
||||
|
||||
default BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
String pattern = Patterns.createBlockSimple(resourceLocation.getPath());
|
||||
return createBlockModel(resourceLocation, pattern);
|
||||
}
|
||||
|
||||
default MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
return createBlockSimple(resourceLocation);
|
||||
}
|
||||
|
||||
static BlockModel createBlockItem(ResourceLocation resourceLocation) {
|
||||
String pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
||||
return BlockModel.fromString(pattern);
|
||||
}
|
||||
|
||||
static BlockModel createBlockModel(ResourceLocation blockId, String pattern) {
|
||||
BlockModel model = BlockModel.fromString(pattern);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue