Change models loading (yes, still WIP)

This commit is contained in:
Aleksey 2021-05-19 17:58:06 +03:00
parent 52fc329a0a
commit 2ece809541
21 changed files with 122 additions and 51 deletions

View file

@ -8,6 +8,7 @@ import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -70,7 +71,7 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Map<String, String> textures = Maps.newHashMap();
textures.put("%glow%", getGlowTexture());
textures.put("%metal%", getMetalTexture(resourceLocation));

View file

@ -32,7 +32,6 @@ public class BlockBase extends Block implements BlockModelProvider {
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
return (BlockModel) getBlockModel(blockId, defaultBlockState());
}
}

View file

@ -9,7 +9,6 @@ import com.google.common.collect.Maps;
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.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -22,6 +21,7 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
@ -77,11 +77,11 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
return (BlockModel) getBlockModel(blockId, defaultBlockState());
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
IntegerProperty destructionProperty = getDestructionProperty();
int destruction = blockState.getValue(destructionProperty);
String name = blockId.getPath();
@ -93,7 +93,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
IntegerProperty destructionProperty = getDestructionProperty();
int destruction = blockState.getValue(destructionProperty);
String modId = resourceLocation.getNamespace();

View file

@ -7,7 +7,6 @@ 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.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
@ -29,6 +28,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.entities.EBarrelBlockEntity;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
@ -104,11 +104,11 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
return (BlockModel) getBlockModel(blockId, defaultBlockState());
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String texture = blockId.getPath();
Optional<String> pattern;
if (blockState.getValue(OPEN)) {
@ -120,7 +120,7 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String open = blockState.getValue(OPEN) ? "_open" : "";
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + open);

View file

@ -6,6 +6,7 @@ import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
@ -16,6 +17,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.Patterns;
public class EndBookshelfBlock extends BlockBase {
@ -42,7 +44,7 @@ public class EndBookshelfBlock extends BlockBase {
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_BOOKSHELF,
getName(blockId), blockId.getPath());
return pattern.map(BlockModel::fromString).orElse(null);

View file

@ -7,7 +7,6 @@ import java.util.Optional;
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.client.resources.model.UnbakedModel;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
@ -18,6 +17,7 @@ import net.minecraft.world.level.block.ChainBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
@ -50,14 +50,14 @@ public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRe
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String name = blockId.getPath();
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
return pattern.map(BlockModel::fromString).orElse(null);
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
Direction.Axis axis = blockState.getValue(AXIS);
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath());

View file

@ -5,6 +5,7 @@ import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
@ -14,6 +15,7 @@ import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
@ -58,7 +60,7 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
}
@Override
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return ModelsHelper.createBlockEmpty(parentId);
}

View file

@ -7,7 +7,6 @@ import java.util.Optional;
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.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -16,6 +15,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.Patterns;
@ -38,16 +38,16 @@ public class EndComposterBlock extends ComposterBlock implements BlockModelProvi
@Override
public BlockModel getModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
return null;
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return null;
}
}

View file

@ -7,6 +7,7 @@ import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
@ -14,6 +15,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CraftingTableBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.Patterns;
@ -47,11 +49,11 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
@Override
public BlockModel getModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String blockName = blockId.getPath();
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
private static final long serialVersionUID = 1L;

View file

@ -23,6 +23,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoorHingeSide;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.client.models.BlockModelProvider;
@ -65,7 +66,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
}
@Override
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String blockName = resourceLocation.getPath();
DoorType doorType = getDoorType(blockState);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockName, blockName);
@ -87,7 +88,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
Direction facing = blockState.getValue(FACING);
DoorType doorType = getDoorType(blockState);
boolean open = blockState.getValue(OPEN);

View file

@ -2,16 +2,29 @@ package ru.betterend.blocks.basis;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.google.common.collect.Lists;
import com.mojang.math.Transformation;
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.client.renderer.block.model.Variant;
import net.minecraft.client.renderer.block.model.multipart.Condition;
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import net.minecraft.client.renderer.block.model.multipart.Selector;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.Patterns;
@ -41,4 +54,57 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
return Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
}
@Override
public BlockModel getModel(ResourceLocation blockId) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_FENCE, parentId.getPath(), blockId.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
@Override
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation postId = new ResourceLocation(blockId.getNamespace(),
"block/" + blockId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(blockId.getNamespace(),
"block/" + blockId.getPath() + "_side");
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (blockId.equals(postId)) {
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
if (blockId.equals(sideId)) {
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_SIDE, parentId.getPath(), blockId.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
return null;
}
@Override
public UnbakedModel getModelVariant(ResourceLocation blockId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(blockId.getNamespace(),
"block/" + blockId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(blockId.getNamespace(),
"block/" + blockId.getPath() + "_side");
registerBlockModel(blockId, postId, blockState, modelCache);
registerBlockModel(blockId, sideId, blockState, modelCache);
StateDefinition<Block, BlockState> blockStateDefinition = getStateDefinition();
MultiVariant postVariant = new MultiVariant(Lists.newArrayList(
new Variant(postId, Transformation.identity(), false, 1)));
MultiVariant sideNorth = new MultiVariant(Lists.newArrayList(
new Variant(sideId, Transformation.identity(), true, 1)));
MultiVariant sideEast = new MultiVariant(Lists.newArrayList(
new Variant(sideId, BlockModelRotation.X0_Y90.getRotation(), true, 1)));
MultiVariant sideSouth = new MultiVariant(Lists.newArrayList(
new Variant(sideId, BlockModelRotation.X0_Y180.getRotation(), true, 1)));
MultiVariant sideWest = new MultiVariant(Lists.newArrayList(
new Variant(sideId, BlockModelRotation.X0_Y270.getRotation(), true, 1)));
return new MultiPart(blockStateDefinition, Lists.newArrayList(
new Selector(Condition.TRUE, postVariant),
new Selector(stateDefinition -> state -> state.getValue(NORTH), sideNorth),
new Selector(stateDefinition -> state -> state.getValue(EAST), sideEast),
new Selector(stateDefinition -> state -> state.getValue(SOUTH), sideSouth),
new Selector(stateDefinition -> state -> state.getValue(WEST), sideWest)
));
}
}

View file

@ -9,7 +9,6 @@ import com.google.common.collect.Maps;
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.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
@ -26,6 +25,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.entities.EFurnaceBlockEntity;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer;
@ -70,7 +70,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String blockName = blockId.getPath();
Map<String, String> textures = Maps.newHashMap();
textures.put("%top%", blockName + "_top");
@ -89,11 +89,11 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
@Override
public BlockModel getModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String lit = blockState.getValue(LIT) ? "_lit" : "";
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + lit);

View file

@ -1,7 +1,6 @@
package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -124,7 +123,7 @@ public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterlogg
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String floor = blockState.getValue(IS_FLOOR) ? "_floor" : "";
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + floor);

View file

@ -7,7 +7,6 @@ import java.util.Optional;
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.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -16,6 +15,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
@ -36,7 +36,7 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
return (BlockModel) getBlockModel(blockId, defaultBlockState());
}
@Override
@ -46,13 +46,13 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
}
@Override
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
Optional<String> pattern = createBlockPattern(blockId);
return pattern.map(BlockModel::fromString).orElse(null);
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath());
registerBlockModel(resourceLocation, modelId, blockState, modelCache);

View file

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
@ -157,7 +157,7 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return ModelsHelper.createBlockEmpty(parentId);
}

View file

@ -46,14 +46,14 @@ public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
SlabType type = blockState.getValue(TYPE);
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + "_" + type);

View file

@ -7,6 +7,7 @@ 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.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
@ -26,6 +27,7 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
@ -123,7 +125,7 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
}
@Override
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}

View file

@ -7,7 +7,6 @@ import java.util.Map;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable;
@ -357,11 +356,11 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
return (BlockModel) getBlockModel(blockId, defaultBlockState());
}
@Override
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Map<String, String> textures = createTexturesMap();
PedestalState state = blockState.getValue(STATE);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
@ -391,7 +390,7 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
PedestalState state = blockState.getValue(STATE);
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + "_" + state);

View file

@ -6,6 +6,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
@ -74,7 +75,7 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String blockName = resourceLocation.getPath();
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, blockName, blockName) :

View file

@ -1,11 +1,9 @@
package ru.betterend.client.models;
import java.io.Reader;
import java.util.Map;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
@ -15,13 +13,12 @@ import ru.betterend.BetterEnd;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ModelProvider {
@Nullable
default BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
default @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
default MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
default UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath());
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
@ -30,7 +27,7 @@ public interface BlockModelProvider extends ModelProvider {
default void registerBlockModel(ResourceLocation stateId, ResourceLocation modelId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
if (!modelCache.containsKey(modelId)) {
BlockModel model = getBlockModel(stateId, blockState);
UnbakedModel model = getBlockModel(stateId, blockState);
if (model != null) {
modelCache.put(modelId, model);
} else {

View file

@ -79,7 +79,7 @@ public abstract class ModelLoaderMixin {
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
.findFirst();
if (stateOptional.isPresent()) {
MultiVariant modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
if (modelVariant != null) {
cacheAndQueueDependencies(modelId, modelVariant);
} else {