Changing model loading (WIP)
This commit is contained in:
parent
4d2e3d7be6
commit
53c9525c2d
33 changed files with 435 additions and 128 deletions
|
@ -1,10 +1,21 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.item.material.EndToolMaterial;
|
import ru.betterend.item.material.EndToolMaterial;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class AeterniumAnvil extends EndAnvilBlock {
|
public class AeterniumAnvil extends EndAnvilBlock {
|
||||||
private static final IntegerProperty DESTRUCTION_LONG = BlockProperties.DESTRUCTION_LONG;
|
private static final IntegerProperty DESTRUCTION_LONG = BlockProperties.DESTRUCTION_LONG;
|
||||||
|
|
||||||
|
@ -17,4 +28,30 @@ public class AeterniumAnvil extends EndAnvilBlock {
|
||||||
return DESTRUCTION_LONG;
|
return DESTRUCTION_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
|
String name = blockId.getPath();
|
||||||
|
int damage = getDamageState(blockState);
|
||||||
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
|
textures.put("%anvil%", name);
|
||||||
|
textures.put("%top%", name + "_top_" + damage);
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
int damage = getDamageState(blockState);
|
||||||
|
String modId = resourceLocation.getNamespace();
|
||||||
|
String modelId = "block/" + resourceLocation.getPath() + "_top_" + damage;
|
||||||
|
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
||||||
|
registerBlockModel(resourceLocation, modelLocation, blockState, modelCache);
|
||||||
|
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDamageState(BlockState blockState) {
|
||||||
|
IntegerProperty destructionProperty = getDestructionProperty();
|
||||||
|
int damage = blockState.getValue(destructionProperty);
|
||||||
|
return damage < 3 ? 0 : damage < 6 ? 1 : 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.google.common.collect.Maps;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -22,6 +21,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.blocks.basis.EndLanternBlock;
|
import ru.betterend.blocks.basis.EndLanternBlock;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.render.ERenderLayer;
|
import ru.betterend.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
@ -71,14 +71,14 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%glow%", getGlowTexture());
|
textures.put("%glow%", getGlowTexture());
|
||||||
textures.put("%metal%", getMetalTexture(resourceLocation));
|
textures.put("%metal%", getMetalTexture(resourceLocation));
|
||||||
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
||||||
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, textures) :
|
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, textures) :
|
||||||
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, textures);
|
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, textures);
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getMetalTexture(ResourceLocation blockId) {
|
protected String getMetalTexture(ResourceLocation blockId) {
|
||||||
|
|
|
@ -32,6 +32,6 @@ public class BlockBase extends Block implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return (BlockModel) getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -77,11 +77,11 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return (BlockModel) getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
IntegerProperty destructionProperty = getDestructionProperty();
|
IntegerProperty destructionProperty = getDestructionProperty();
|
||||||
int destruction = blockState.getValue(destructionProperty);
|
int destruction = blockState.getValue(destructionProperty);
|
||||||
String name = blockId.getPath();
|
String name = blockId.getPath();
|
||||||
|
@ -89,7 +89,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
textures.put("%anvil%", name);
|
textures.put("%anvil%", name);
|
||||||
textures.put("%top%", name + "_top_" + destruction);
|
textures.put("%top%", name + "_top_" + destruction);
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -106,11 +106,11 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return (BlockModel) getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String texture = blockId.getPath();
|
String texture = blockId.getPath();
|
||||||
Optional<String> pattern;
|
Optional<String> pattern;
|
||||||
if (blockState.getValue(OPEN)) {
|
if (blockState.getValue(OPEN)) {
|
||||||
|
@ -118,7 +118,7 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
||||||
} else {
|
} else {
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
||||||
}
|
}
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -18,6 +17,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndBookshelfBlock extends BlockBase {
|
public class EndBookshelfBlock extends BlockBase {
|
||||||
|
@ -44,10 +44,10 @@ public class EndBookshelfBlock extends BlockBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_BOOKSHELF,
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_BOOKSHELF,
|
||||||
getName(blockId), blockId.getPath());
|
getName(blockId), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getName(ResourceLocation blockId) {
|
private String getName(ResourceLocation blockId) {
|
||||||
|
|
90
src/main/java/ru/betterend/blocks/basis/EndButtonBlock.java
Normal file
90
src/main/java/ru/betterend/blocks/basis/EndButtonBlock.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
|
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.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.ButtonBlock;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.AttachFace;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public abstract class EndButtonBlock extends ButtonBlock implements BlockModelProvider {
|
||||||
|
|
||||||
|
private final Block parent;
|
||||||
|
|
||||||
|
protected EndButtonBlock(Block parent, Properties properties, boolean sensitive) {
|
||||||
|
super(sensitive, properties);
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||||
|
return Collections.singletonList(new ItemStack(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getModelString(String block) {
|
||||||
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
if (block.contains("item")) {
|
||||||
|
return Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
if (block.contains("pressed")) {
|
||||||
|
return Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
Optional<String> pattern = blockState.getValue(POWERED) ?
|
||||||
|
Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath()) :
|
||||||
|
Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
String powered = blockState.getValue(POWERED) ? "_powered" : "";
|
||||||
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
|
"block/" + resourceLocation.getPath() + powered);
|
||||||
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
|
AttachFace face = blockState.getValue(FACE);
|
||||||
|
boolean isCeiling = face == AttachFace.CEILING;
|
||||||
|
int x = 0, y = 0;
|
||||||
|
switch (face) {
|
||||||
|
case CEILING: x = 180; break;
|
||||||
|
case WALL: x = 90; break;
|
||||||
|
}
|
||||||
|
switch (blockState.getValue(FACING)) {
|
||||||
|
case NORTH: if (isCeiling) { y = 180; } break;
|
||||||
|
case EAST: y = isCeiling ? 270 : 90; break;
|
||||||
|
case SOUTH: if(!isCeiling) { y = 180; } break;
|
||||||
|
case WEST: y = isCeiling ? 90 : 270; break;
|
||||||
|
}
|
||||||
|
BlockModelRotation rotation = BlockModelRotation.by(x, y);
|
||||||
|
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,6 @@ import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.render.ERenderLayer;
|
import ru.betterend.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRenderTypeable {
|
public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRenderTypeable {
|
||||||
|
@ -46,14 +45,14 @@ public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return ModelProvider.createItemModel(blockId.getPath());
|
return ModelsHelper.createItemModel(blockId.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String name = blockId.getPath();
|
String name = blockId.getPath();
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -56,11 +55,11 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
return ModelsHelper.createBlockEmpty(parentId);
|
return ModelsHelper.createBlockEmpty(parentId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
|
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndComposterBlock extends ComposterBlock implements BlockModelProvider {
|
public class EndComposterBlock extends ComposterBlock implements BlockModelProvider {
|
||||||
|
@ -38,16 +40,40 @@ public class EndComposterBlock extends ComposterBlock implements BlockModelProvi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
|
return getBlockModel(resourceLocation, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
return null;
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockId.getPath());
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
return null;
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(), "block/" + resourceLocation.getPath());
|
||||||
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
|
|
||||||
|
ResourceLocation content_1 = new ResourceLocation("block/composter_contents1");
|
||||||
|
ResourceLocation content_2 = new ResourceLocation("block/composter_contents2");
|
||||||
|
ResourceLocation content_3 = new ResourceLocation("block/composter_contents3");
|
||||||
|
ResourceLocation content_4 = new ResourceLocation("block/composter_contents4");
|
||||||
|
ResourceLocation content_5 = new ResourceLocation("block/composter_contents5");
|
||||||
|
ResourceLocation content_6 = new ResourceLocation("block/composter_contents6");
|
||||||
|
ResourceLocation content_7 = new ResourceLocation("block/composter_contents7");
|
||||||
|
ResourceLocation content_8 = new ResourceLocation("block/composter_contents_ready");
|
||||||
|
|
||||||
|
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
|
||||||
|
builder.part(content_1).setCondition(state -> state.getValue(LEVEL) == 1).add();
|
||||||
|
builder.part(content_2).setCondition(state -> state.getValue(LEVEL) == 2).add();
|
||||||
|
builder.part(content_3).setCondition(state -> state.getValue(LEVEL) == 3).add();
|
||||||
|
builder.part(content_4).setCondition(state -> state.getValue(LEVEL) == 4).add();
|
||||||
|
builder.part(content_5).setCondition(state -> state.getValue(LEVEL) == 5).add();
|
||||||
|
builder.part(content_6).setCondition(state -> state.getValue(LEVEL) == 6).add();
|
||||||
|
builder.part(content_7).setCondition(state -> state.getValue(LEVEL) == 7).add();
|
||||||
|
builder.part(content_8).setCondition(state -> state.getValue(LEVEL) == 8).add();
|
||||||
|
builder.part(modelId).add();
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -17,6 +16,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
|
public class EndCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
|
||||||
|
@ -49,11 +49,11 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
|
return getBlockModel(resourceLocation, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String blockName = blockId.getPath();
|
String blockName = blockId.getPath();
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
@ -67,6 +67,6 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
|
||||||
put("%east%", blockName + "_side");
|
put("%east%", blockName + "_side");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
|
||||||
import net.minecraft.client.renderer.block.model.Variant;
|
|
||||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -67,7 +64,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
String blockName = resourceLocation.getPath();
|
String blockName = resourceLocation.getPath();
|
||||||
DoorType doorType = getDoorType(blockState);
|
DoorType doorType = getDoorType(blockState);
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockName, blockName);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockName, blockName);
|
||||||
|
@ -85,7 +82,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
|
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
@ -51,11 +52,11 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_FENCE, parentId.getPath(), blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_FENCE, parentId.getPath(), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
ResourceLocation thisId = Registry.BLOCK.getKey(this);
|
ResourceLocation thisId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
ResourceLocation postId = new ResourceLocation(thisId.getNamespace(),
|
ResourceLocation postId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
@ -64,11 +65,11 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
"block/" + thisId.getPath() + "_side");
|
"block/" + thisId.getPath() + "_side");
|
||||||
if (blockId.equals(postId)) {
|
if (blockId.equals(postId)) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
if (blockId.equals(sideId)) {
|
if (blockId.equals(sideId)) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_SIDE, parentId.getPath(), blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_SIDE, parentId.getPath(), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -83,14 +84,14 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
registerBlockModel(sideId, sideId, blockState, modelCache);
|
registerBlockModel(sideId, sideId, blockState, modelCache);
|
||||||
|
|
||||||
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
|
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
|
||||||
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).save();
|
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
|
||||||
builder.part(sideId).setCondition(state -> state.getValue(EAST))
|
builder.part(sideId).setCondition(state -> state.getValue(EAST))
|
||||||
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).save();
|
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
|
||||||
builder.part(sideId).setCondition(state -> state.getValue(SOUTH))
|
builder.part(sideId).setCondition(state -> state.getValue(SOUTH))
|
||||||
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).save();
|
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
|
||||||
builder.part(sideId).setCondition(state -> state.getValue(WEST))
|
builder.part(sideId).setCondition(state -> state.getValue(WEST))
|
||||||
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).save();
|
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
|
||||||
builder.part(postId).save();
|
builder.part(postId).add();
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String blockName = blockId.getPath();
|
String blockName = blockId.getPath();
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%top%", blockName + "_top");
|
textures.put("%top%", blockName + "_top");
|
||||||
|
@ -84,12 +84,12 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
textures.put("%front%", blockName + "_front");
|
textures.put("%front%", blockName + "_front");
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
|
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
|
||||||
}
|
}
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return (BlockModel) getBlockModel(resourceLocation, defaultBlockState());
|
return getBlockModel(resourceLocation, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
boolean inWall = blockState.getValue(IN_WALL);
|
boolean inWall = blockState.getValue(IN_WALL);
|
||||||
boolean isOpen = blockState.getValue(OPEN);
|
boolean isOpen = blockState.getValue(OPEN);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
@ -63,7 +63,7 @@ public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
|
||||||
pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN, parentId.getPath(), blockId.getPath()) :
|
pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN, parentId.getPath(), blockId.getPath()) :
|
||||||
Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
|
Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
|
||||||
}
|
}
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -25,6 +28,8 @@ import net.minecraft.world.level.material.FluidState;
|
||||||
import net.minecraft.world.level.material.Fluids;
|
import net.minecraft.world.level.material.Fluids;
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
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.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
@ -146,4 +151,21 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
|
||||||
return Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
|
return Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
|
return ModelsHelper.createBlockItem(blockId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return (BlockModel) getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,9 +46,9 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
Optional<String> pattern = createBlockPattern(blockId);
|
Optional<String> pattern = createBlockPattern(blockId);
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -157,7 +157,7 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
return ModelsHelper.createBlockEmpty(parentId);
|
return ModelsHelper.createBlockEmpty(parentId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
|
||||||
import net.minecraft.client.renderer.block.model.Variant;
|
|
||||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -46,10 +43,10 @@ public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,17 +2,25 @@ package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.StairBlock;
|
import net.minecraft.world.level.block.StairBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.Half;
|
||||||
|
import net.minecraft.world.level.block.state.properties.StairsShape;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndStairsBlock extends StairBlock implements BlockModelProvider {
|
public class EndStairsBlock extends StairBlock implements BlockModelProvider {
|
||||||
|
@ -43,4 +51,84 @@ public class EndStairsBlock extends StairBlock implements BlockModelProvider {
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
|
return getBlockModel(resourceLocation, defaultBlockState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
Optional<String> pattern = Optional.empty();
|
||||||
|
switch (blockState.getValue(SHAPE)) {
|
||||||
|
case STRAIGHT:
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
|
||||||
|
break;
|
||||||
|
case INNER_LEFT:
|
||||||
|
case INNER_RIGHT:
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_INNER, parentId.getPath(), blockId.getPath());
|
||||||
|
break;
|
||||||
|
case OUTER_LEFT:
|
||||||
|
case OUTER_RIGHT:
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_OUTER, parentId.getPath(), blockId.getPath());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
String state = "";
|
||||||
|
switch (blockState.getValue(SHAPE)) {
|
||||||
|
case INNER_LEFT:
|
||||||
|
case INNER_RIGHT:
|
||||||
|
state = "_inner"; break;
|
||||||
|
case OUTER_LEFT:
|
||||||
|
case OUTER_RIGHT:
|
||||||
|
state = "_outer"; break;
|
||||||
|
}
|
||||||
|
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state);
|
||||||
|
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||||
|
|
||||||
|
StairsShape shape = blockState.getValue(SHAPE);
|
||||||
|
boolean isTop = blockState.getValue(HALF) == Half.TOP;
|
||||||
|
boolean isLeft = shape == StairsShape.INNER_LEFT ||
|
||||||
|
shape == StairsShape.OUTER_LEFT;
|
||||||
|
boolean isRight = shape == StairsShape.INNER_RIGHT ||
|
||||||
|
shape == StairsShape.OUTER_RIGHT;
|
||||||
|
int y = 0;
|
||||||
|
int x = isTop ? 180 : 0;
|
||||||
|
switch (blockState.getValue(FACING)) {
|
||||||
|
case NORTH:
|
||||||
|
if (isTop) {
|
||||||
|
if (!isRight) y = 270;
|
||||||
|
} else {
|
||||||
|
y = (isLeft) ? 180 : 270;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
if (isTop) {
|
||||||
|
if (isRight) y = 90;
|
||||||
|
} else {
|
||||||
|
if (isLeft) y = 270;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
if (isTop) {
|
||||||
|
y = (isRight) ? 180 : 90;
|
||||||
|
} else {
|
||||||
|
if (!isLeft) y = 90;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
if (isTop) {
|
||||||
|
y = isRight ? 270 : 180;
|
||||||
|
} else {
|
||||||
|
y = isLeft ? 90 : 180;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BlockModelRotation rotation = BlockModelRotation.by(x, y);
|
||||||
|
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,40 +5,29 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.StoneButtonBlock;
|
import net.minecraft.world.level.block.StoneButtonBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndStoneButtonBlock extends StoneButtonBlock implements BlockModelProvider {
|
public class EndStoneButtonBlock extends EndButtonBlock {
|
||||||
private final Block parent;
|
|
||||||
|
|
||||||
public EndStoneButtonBlock(Block source) {
|
public EndStoneButtonBlock(Block source) {
|
||||||
super(FabricBlockSettings.copyOf(source).noOcclusion());
|
super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false);
|
||||||
this.parent = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
protected SoundEvent getSound(boolean clicked) {
|
||||||
return Collections.singletonList(new ItemStack(this));
|
return clicked ? SoundEvents.STONE_BUTTON_CLICK_ON : SoundEvents.STONE_BUTTON_CLICK_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getModelString(String block) {
|
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
|
||||||
if (block.contains("item")) {
|
|
||||||
return Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
if (block.contains("pressed")) {
|
|
||||||
return Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,24 @@ package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.WallBlock;
|
import net.minecraft.world.level.block.WallBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.WallSide;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndWallBlock extends WallBlock implements BlockModelProvider {
|
public class EndWallBlock extends WallBlock implements BlockModelProvider {
|
||||||
|
@ -45,4 +52,65 @@ public class EndWallBlock extends WallBlock implements BlockModelProvider {
|
||||||
return Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath());
|
return Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_WALL, parentId.getPath(), blockId.getPath());
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
|
ResourceLocation thisId = Registry.BLOCK.getKey(this);
|
||||||
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
ResourceLocation postId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
"block/" + thisId.getPath() + "_post");
|
||||||
|
ResourceLocation sideId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
"block/" + thisId.getPath() + "_side");
|
||||||
|
ResourceLocation sideTallId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
"block/" + thisId.getPath() + "_side_tall");
|
||||||
|
Optional<String> pattern = Optional.empty();
|
||||||
|
if (blockId.equals(postId)) {
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
if (blockId.equals(sideId)) {
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_WALL_SIDE, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
if (blockId.equals(sideTallId)) {
|
||||||
|
pattern = Patterns.createJson(Patterns.BLOCK_WALL_SIDE_TALL, parentId.getPath(), blockId.getPath());
|
||||||
|
}
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
ResourceLocation sideTallId = new ResourceLocation(blockId.getNamespace(),
|
||||||
|
"block/" + blockId.getPath() + "_side_tall");
|
||||||
|
registerBlockModel(postId, postId, blockState, modelCache);
|
||||||
|
registerBlockModel(sideId, sideId, blockState, modelCache);
|
||||||
|
registerBlockModel(sideTallId, sideTallId, blockState, modelCache);
|
||||||
|
|
||||||
|
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
|
||||||
|
builder.part(sideId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.LOW).setUVLock(true).add();
|
||||||
|
builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(sideId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(sideId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(sideTallId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL).setUVLock(true).add();
|
||||||
|
builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(sideTallId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(sideTallId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL)
|
||||||
|
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
|
||||||
|
builder.part(postId).setCondition(state -> state.getValue(UP)).add();
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.util.Optional;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.WoodButtonBlock;
|
import net.minecraft.world.level.block.WoodButtonBlock;
|
||||||
|
@ -15,30 +17,14 @@ import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndWoodenButtonBlock extends WoodButtonBlock implements BlockModelProvider {
|
public class EndWoodenButtonBlock extends EndButtonBlock {
|
||||||
private final Block parent;
|
|
||||||
|
|
||||||
public EndWoodenButtonBlock(Block source) {
|
public EndWoodenButtonBlock(Block source) {
|
||||||
super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion());
|
super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true);
|
||||||
this.parent = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
protected SoundEvent getSound(boolean clicked) {
|
||||||
return Collections.singletonList(new ItemStack(this));
|
return clicked ? SoundEvents.WOODEN_BUTTON_CLICK_ON : SoundEvents.WOODEN_BUTTON_CLICK_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getModelString(String block) {
|
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
|
||||||
if (block.contains("item")) {
|
|
||||||
return Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
if (block.contains("pressed")) {
|
|
||||||
return Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Random;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -125,8 +124,8 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,11 +356,11 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
return (BlockModel) getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
Map<String, String> textures = createTexturesMap();
|
Map<String, String> textures = createTexturesMap();
|
||||||
PedestalState state = blockState.getValue(STATE);
|
PedestalState state = blockState.getValue(STATE);
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
||||||
|
@ -386,7 +386,7 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,7 +6,6 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.minecraft.client.color.block.BlockColor;
|
import net.minecraft.client.color.block.BlockColor;
|
||||||
import net.minecraft.client.color.item.ItemColor;
|
import net.minecraft.client.color.item.ItemColor;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
|
@ -19,6 +18,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.betterend.blocks.AuroraCrystalBlock;
|
import ru.betterend.blocks.AuroraCrystalBlock;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.interfaces.IColorProvider;
|
import ru.betterend.interfaces.IColorProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
|
@ -75,11 +75,11 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
String blockName = resourceLocation.getPath();
|
String blockName = resourceLocation.getPath();
|
||||||
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
||||||
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, blockName, blockName) :
|
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, blockName, blockName) :
|
||||||
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, blockName, blockName);
|
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, blockName, blockName);
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ import ru.betterend.BetterEnd;
|
||||||
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
|
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
|
||||||
|
|
||||||
public interface BlockModelProvider extends ModelProvider {
|
public interface BlockModelProvider extends ModelProvider {
|
||||||
default @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
default UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
|
|
@ -9,11 +9,6 @@ public interface ModelProvider {
|
||||||
Optional<String> getModelString(String name);
|
Optional<String> getModelString(String name);
|
||||||
|
|
||||||
default BlockModel getModel(ResourceLocation resourceLocation) {
|
default BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return createItemModel(resourceLocation.getPath());
|
return ModelsHelper.createItemModel(resourceLocation.getPath());
|
||||||
}
|
|
||||||
|
|
||||||
static BlockModel createItemModel(String name) {
|
|
||||||
Optional<String> pattern = Patterns.createItemGenerated("item/" + name);
|
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,14 +23,24 @@ import java.util.function.Function;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class ModelsHelper {
|
public class ModelsHelper {
|
||||||
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
|
public static BlockModel fromPattern(Optional<String> pattern) {
|
||||||
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockModel createItemModel(String name) {
|
||||||
|
Optional<String> pattern = Patterns.createItemGenerated("item/" + name);
|
||||||
|
return fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
|
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) {
|
public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, resourceLocation.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiVariant createMultiVariant(ResourceLocation resourceLocation, Transformation transform, boolean uvLock) {
|
public static MultiVariant createMultiVariant(ResourceLocation resourceLocation, Transformation transform, boolean uvLock) {
|
||||||
|
@ -116,7 +126,7 @@ public class ModelsHelper {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void add() {
|
||||||
modelParts.add(this);
|
modelParts.add(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
import net.minecraft.world.item.Rarity;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
|
@ -27,6 +27,6 @@ public class EnchantedPetalItem extends ModelProviderItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return ModelProvider.createItemModel("hydralux_petal");
|
return ModelsHelper.createItemModel("hydralux_petal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.item.SpawnEggItem;
|
import net.minecraft.world.item.SpawnEggItem;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -22,6 +23,6 @@ public class EndSpawnEggItem extends SpawnEggItem implements ModelProvider {
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_SPAWN_EGG, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_SPAWN_EGG, resourceLocation.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -20,6 +21,6 @@ public class ModelProviderItem extends Item implements ModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return ModelProvider.createItemModel(resourceLocation.getPath());
|
return ModelsHelper.createItemModel(resourceLocation.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import ru.betterend.world.generator.GeneratorOptions;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -54,7 +55,7 @@ public abstract class ModelLoaderMixin {
|
||||||
String path = resourceLocation.getPath();
|
String path = resourceLocation.getPath();
|
||||||
ResourceLocation clearLoc = new ResourceLocation(modId, path);
|
ResourceLocation clearLoc = new ResourceLocation(modId, path);
|
||||||
ModelResourceLocation modelId = (ModelResourceLocation) resourceLocation;
|
ModelResourceLocation modelId = (ModelResourceLocation) resourceLocation;
|
||||||
if (Objects.equals(modelId.getVariant(), "inventory")) {
|
if ("inventory".equals(modelId.getVariant())) {
|
||||||
ResourceLocation itemLoc = new ResourceLocation(modId, "item/" + path);
|
ResourceLocation itemLoc = new ResourceLocation(modId, "item/" + path);
|
||||||
ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
|
ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
|
||||||
if (!resourceManager.hasResource(itemModelLoc)) {
|
if (!resourceManager.hasResource(itemModelLoc)) {
|
||||||
|
@ -76,14 +77,15 @@ public abstract class ModelLoaderMixin {
|
||||||
if (!resourceManager.hasResource(stateLoc)) {
|
if (!resourceManager.hasResource(stateLoc)) {
|
||||||
Block block = Registry.BLOCK.get(clearLoc);
|
Block block = Registry.BLOCK.get(clearLoc);
|
||||||
if (block instanceof BlockModelProvider) {
|
if (block instanceof BlockModelProvider) {
|
||||||
Optional<BlockState> stateOptional = block.getStateDefinition().getPossibleStates().stream()
|
List<BlockState> possibleStates = block.getStateDefinition().getPossibleStates();
|
||||||
|
Optional<BlockState> possibleState = possibleStates.stream()
|
||||||
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
|
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (stateOptional.isPresent()) {
|
if (possibleState.isPresent()) {
|
||||||
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
|
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache);
|
||||||
if (modelVariant != null) {
|
if (modelVariant != null) {
|
||||||
if (modelVariant instanceof MultiPart) {
|
if (modelVariant instanceof MultiPart) {
|
||||||
block.getStateDefinition().getPossibleStates().forEach(state -> {
|
possibleStates.forEach(state -> {
|
||||||
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
|
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
|
||||||
cacheAndQueueDependencies(stateId, modelVariant);
|
cacheAndQueueDependencies(stateId, modelVariant);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue