Changing model loading (WIP)
This commit is contained in:
parent
d9c5f8e89c
commit
4d2e3d7be6
8 changed files with 120 additions and 98 deletions
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue