Changing model loading (WIP)
This commit is contained in:
parent
d9c5f8e89c
commit
4d2e3d7be6
8 changed files with 120 additions and 98 deletions
|
@ -100,6 +100,6 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
|||
String modelId = "block/" + resourceLocation.getPath() + "_top_" + destruction;
|
||||
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
||||
registerBlockModel(resourceLocation, modelLocation, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING).getOpposite());
|
||||
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ 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.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
@ -125,6 +127,15 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
|||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + open);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
||||
Direction facing = blockState.getValue(FACING);
|
||||
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
||||
switch (facing) {
|
||||
case NORTH: rotation = BlockModelRotation.X90_Y0; break;
|
||||
case EAST: rotation = BlockModelRotation.X90_Y90; break;
|
||||
case SOUTH: rotation = BlockModelRotation.X90_Y180; break;
|
||||
case WEST: rotation = BlockModelRotation.X90_Y270; break;
|
||||
case DOWN: rotation = BlockModelRotation.X180_Y0; break;
|
||||
}
|
||||
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ 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.models.ModelsHelper;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
|
@ -133,8 +134,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
|||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + "_" + doorType);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
Variant variant = new Variant(modelId, rotation.getRotation(), false, 1);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
|
||||
}
|
||||
|
||||
protected DoorType getDoorType(BlockState blockState) {
|
||||
|
|
|
@ -1,19 +1,7 @@
|
|||
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;
|
||||
|
@ -22,14 +10,16 @@ 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.BetterEnd;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
||||
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||
private final Block parent;
|
||||
|
@ -92,23 +82,16 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
|||
registerBlockModel(postId, postId, blockState, modelCache);
|
||||
registerBlockModel(sideId, sideId, blockState, modelCache);
|
||||
|
||||
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)));
|
||||
StateDefinition<Block, BlockState> blockStateDefinition = getStateDefinition();
|
||||
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)
|
||||
));
|
||||
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
|
||||
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).save();
|
||||
builder.part(sideId).setCondition(state -> state.getValue(EAST))
|
||||
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).save();
|
||||
builder.part(sideId).setCondition(state -> state.getValue(SOUTH))
|
||||
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).save();
|
||||
builder.part(sideId).setCondition(state -> state.getValue(WEST))
|
||||
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).save();
|
||||
builder.part(postId).save();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
|||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + lit);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,9 +2,12 @@ package ru.betterend.blocks.basis;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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;
|
||||
|
@ -12,7 +15,9 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.FenceGateBlock;
|
||||
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;
|
||||
|
||||
public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
|
||||
|
@ -45,4 +50,30 @@ public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
|
|||
return Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
boolean inWall = blockState.getValue(IN_WALL);
|
||||
boolean isOpen = blockState.getValue(OPEN);
|
||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||
Optional<String> pattern;
|
||||
if (inWall) {
|
||||
pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN_WALL, parentId.getPath(), blockId.getPath()) :
|
||||
Patterns.createJson(Patterns.BLOCK_GATE_CLOSED_WALL, parentId.getPath(), blockId.getPath());
|
||||
} else {
|
||||
pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN, parentId.getPath(), blockId.getPath()) :
|
||||
Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
|
||||
}
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
boolean inWall = blockState.getValue(IN_WALL);
|
||||
boolean isOpen = blockState.getValue(OPEN);
|
||||
String state = "" + (inWall ? "_wall" : "") + (isOpen ? "_open" : "_closed");
|
||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + state);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), true, false);
|
||||
}
|
||||
}
|
|
@ -59,9 +59,7 @@ public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
|
|||
"block/" + resourceLocation.getPath() + "_" + type);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
if (type == SlabType.TOP) {
|
||||
BlockModelRotation rotation = BlockModelRotation.by(180, 0);
|
||||
Variant variant = new Variant(modelId, rotation.getRotation(), true, 1);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true);
|
||||
}
|
||||
return ModelsHelper.createBlockSimple(modelId);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue