Change models loading (WIP)
This commit is contained in:
parent
de8baa4b83
commit
2910df3078
8 changed files with 129 additions and 41 deletions
|
@ -2,6 +2,7 @@ package ru.betterend.blocks.basis;
|
|||
|
||||
import java.io.Reader;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -26,8 +27,12 @@ public class BarkBlock extends EndPillarBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(BlockState blockState) {
|
||||
public BlockModel getBlockModel(BlockState blockState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@ import java.io.Reader;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -34,12 +36,12 @@ public class BlockBase extends Block implements BlockModelProvider {
|
|||
@Override
|
||||
public String getModelString(String block) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), blockId.getPath());
|
||||
return Patterns.createBlockSimple(blockId.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getModel() {
|
||||
return getModelVariant(defaultBlockState());
|
||||
return getBlockModel(defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,7 +50,15 @@ public class BlockBase extends Block implements BlockModelProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(BlockState blockState) {
|
||||
return BlockModel.fromString(getModelString(""));
|
||||
public BlockModel getBlockModel(BlockState blockState) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
String pattern = Patterns.createBlockSimple(blockId.getPath());
|
||||
return BlockModelProvider.createBlockModel(blockId, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
Variant variant = new Variant(resourceLocation, Transformation.identity(), false, 1);
|
||||
return new MultiVariant(Collections.singletonList(variant));
|
||||
}
|
||||
}
|
|
@ -24,8 +24,6 @@ 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.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.patterns.BlockModelProvider;
|
||||
import ru.betterend.patterns.Patterns;
|
||||
|
@ -91,38 +89,22 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
|||
|
||||
@Override
|
||||
public BlockModel getModel() {
|
||||
return null;
|
||||
return getBlockModel(defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<ResourceLocation, BlockModel> getBlockModel(BlockState blockState) {
|
||||
Direction facing = blockState.getValue(FACING);
|
||||
public BlockModel getBlockModel(BlockState blockState) {
|
||||
int destruction = blockState.getValue(DESTRUCTION);
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
ResourceLocation modelId = createModelId(blockId, facing, destruction);
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("%anvil%", blockId.getPath());
|
||||
map.put("%top%", "_top_" + destruction);
|
||||
String jsonString = Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
||||
BlockModel blockModel = BlockModel.fromString(jsonString);
|
||||
|
||||
return Pair.of(modelId, blockModel);
|
||||
String pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
||||
return BlockModelProvider.createBlockModel(blockId, pattern);
|
||||
}
|
||||
|
||||
@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);
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
return BlockModelProvider.createFacingModel(resourceLocation, blockState.getValue(FACING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,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.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -102,9 +104,35 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
|||
}
|
||||
return Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockModel getModel() {
|
||||
return getBlockModel(defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_BARREL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getBlockModel(BlockState blockState) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
String texture = blockId.getPath();
|
||||
String pattern;
|
||||
if (blockState.getValue(OPEN)) {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
||||
} else {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
||||
}
|
||||
if (pattern != null) {
|
||||
return BlockModelProvider.createBlockModel(blockId, pattern);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
return BlockModelProvider.createFacingModel(resourceLocation, blockState.getValue(FACING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,13 @@ import java.io.Reader;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
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.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -16,7 +21,7 @@ import net.minecraft.world.level.storage.loot.LootContext;
|
|||
import ru.betterend.patterns.BlockModelProvider;
|
||||
import ru.betterend.patterns.Patterns;
|
||||
|
||||
public abstract class EndPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
|
||||
public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
|
||||
public EndPillarBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
@ -43,12 +48,43 @@ public abstract class EndPillarBlock extends RotatedPillarBlock implements Block
|
|||
|
||||
@Override
|
||||
public String getModelString(String block) {
|
||||
String texture = Registry.BLOCK.getKey(this).getPath();
|
||||
return Patterns.createJson(Patterns.BLOCK_PILLAR, texture, texture);
|
||||
return createBlockPattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_PILLAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getBlockModel(BlockState blockState) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
BlockModel model = BlockModel.fromString(createBlockPattern());
|
||||
ResourceLocation modelLoc = new ResourceLocation(blockId.getNamespace(), "blocks/" + blockId.getPath());
|
||||
model.name = modelLoc.toString();
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
Direction.Axis axis = blockState.getValue(AXIS);
|
||||
Transformation transform = Transformation.identity();
|
||||
switch (axis) {
|
||||
case X: {
|
||||
transform = new Transformation(null, Vector3f.ZP.rotationDegrees(90), null, null);
|
||||
break;
|
||||
}
|
||||
case Z: {
|
||||
transform = new Transformation(null, Vector3f.XP.rotationDegrees(90), null, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Variant variant = new Variant(resourceLocation, transform, false, 1);
|
||||
return new MultiVariant(Collections.singletonList(variant));
|
||||
}
|
||||
|
||||
private String createBlockPattern() {
|
||||
String texture = Registry.BLOCK.getKey(this).getPath();
|
||||
return Patterns.createBlockPillar(texture);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue