From 72b1b237f2f38f8566fba31b34f10337a6754e37 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Fri, 11 Jun 2021 15:12:33 +0300 Subject: [PATCH] - CraftingTable and Trapdoor models fix --- gradle.properties | 2 +- .../bclib/blocks/BaseCraftingTableBlock.java | 111 +++++------ .../ru/bclib/blocks/BaseTrapdoorBlock.java | 177 +++++++++--------- 3 files changed, 146 insertions(+), 144 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4175331c..1dd5ab46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=6 loader_version=0.11.3 # Mod Properties -mod_version = 0.1.27 +mod_version = 0.1.28 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java index 5b465ca3..e36b2374 100644 --- a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java @@ -1,55 +1,56 @@ -package ru.bclib.blocks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; - -import org.jetbrains.annotations.Nullable; - -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.CraftingTableBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.storage.loot.LootContext; -import ru.bclib.client.models.BasePatterns; -import ru.bclib.client.models.BlockModelProvider; -import ru.bclib.client.models.ModelsHelper; -import ru.bclib.client.models.PatternsHelper; - -public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider { - public BaseCraftingTableBlock(Block source) { - super(FabricBlockSettings.copyOf(source)); - } - - @Override - public List getDrops(BlockState state, LootContext.Builder builder) { - return Collections.singletonList(new ItemStack(this.asItem())); - } - - @Override - public BlockModel getItemModel(ResourceLocation resourceLocation) { - return getBlockModel(resourceLocation, defaultBlockState()); - } - - @Override - public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { - String blockName = blockId.getPath(); - Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap() { - private static final long serialVersionUID = 1L; - { - put("%particle%", blockName + "_front"); - put("%down%", blockName + "_bottom"); - put("%up%", blockName + "_top"); - put("%north%", blockName + "_front"); - put("%south%", blockName + "_side"); - put("%west%", blockName + "_front"); - put("%east%", blockName + "_side"); - } - }); - return ModelsHelper.fromPattern(pattern); - } -} +package ru.bclib.blocks; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; + +import org.jetbrains.annotations.Nullable; + +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CraftingTableBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import ru.bclib.client.models.BasePatterns; +import ru.bclib.client.models.BlockModelProvider; +import ru.bclib.client.models.ModelsHelper; +import ru.bclib.client.models.PatternsHelper; + +public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider { + public BaseCraftingTableBlock(Block source) { + super(FabricBlockSettings.copyOf(source)); + } + + @Override + public List getDrops(BlockState state, LootContext.Builder builder) { + return Collections.singletonList(new ItemStack(this.asItem())); + } + + @Override + public BlockModel getItemModel(ResourceLocation resourceLocation) { + return getBlockModel(resourceLocation, defaultBlockState()); + } + + @Override + public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { + String blockName = blockId.getPath(); + Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap() { + private static final long serialVersionUID = 1L; + { + put("%modid%", blockId.getNamespace()); + put("%particle%", blockName + "_front"); + put("%down%", blockName + "_bottom"); + put("%up%", blockName + "_top"); + put("%north%", blockName + "_front"); + put("%south%", blockName + "_side"); + put("%west%", blockName + "_front"); + put("%east%", blockName + "_side"); + } + }); + return ModelsHelper.fromPattern(pattern); + } +} diff --git a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java index 95bb5d63..1121a1f4 100644 --- a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java @@ -1,88 +1,89 @@ -package ru.bclib.blocks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.jetbrains.annotations.Nullable; - -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.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.TrapDoorBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.Half; -import net.minecraft.world.level.storage.loot.LootContext; -import ru.bclib.client.models.BasePatterns; -import ru.bclib.client.models.BlockModelProvider; -import ru.bclib.client.models.ModelsHelper; -import ru.bclib.client.models.PatternsHelper; -import ru.bclib.client.render.ERenderLayer; -import ru.bclib.interfaces.IRenderTyped; - -public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider { - public BaseTrapdoorBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); - } - - @Override - public List getDrops(BlockState state, LootContext.Builder builder) { - return Collections.singletonList(new ItemStack(this)); - } - - @Override - public ERenderLayer getRenderLayer() { - return ERenderLayer.CUTOUT; - } - - @Override - public BlockModel getItemModel(ResourceLocation resourceLocation) { - return getBlockModel(resourceLocation, defaultBlockState()); - } - - @Override - public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { - String name = resourceLocation.getPath(); - Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap() { - private static final long serialVersionUID = 1L; - { - put("%texture%", name); - put("%side%", name.replace("trapdoor", "door_side")); - } - }); - return ModelsHelper.fromPattern(pattern); - } - - @Override - public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath()); - registerBlockModel(stateId, modelId, blockState, modelCache); - boolean isTop = blockState.getValue(HALF) == Half.TOP; - boolean isOpen = blockState.getValue(OPEN); - int y = 0; - int x = (isTop && isOpen) ? 270 : isTop ? 180 : isOpen ? 90 : 0; - switch (blockState.getValue(FACING)) { - case EAST: - y = (isTop && isOpen) ? 270 : 90; - break; - case NORTH: - if (isTop && isOpen) y = 180; - break; - case SOUTH: - y = (isTop && isOpen) ? 0 : 180; - break; - case WEST: - y = (isTop && isOpen) ? 90 : 270; - break; - default: break; - } - BlockModelRotation rotation = BlockModelRotation.by(x, y); - return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); - } -} +package ru.bclib.blocks; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.jetbrains.annotations.Nullable; + +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.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.storage.loot.LootContext; +import ru.bclib.client.models.BasePatterns; +import ru.bclib.client.models.BlockModelProvider; +import ru.bclib.client.models.ModelsHelper; +import ru.bclib.client.models.PatternsHelper; +import ru.bclib.client.render.ERenderLayer; +import ru.bclib.interfaces.IRenderTyped; + +public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider { + public BaseTrapdoorBlock(Block source) { + super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); + } + + @Override + public List getDrops(BlockState state, LootContext.Builder builder) { + return Collections.singletonList(new ItemStack(this)); + } + + @Override + public ERenderLayer getRenderLayer() { + return ERenderLayer.CUTOUT; + } + + @Override + public BlockModel getItemModel(ResourceLocation resourceLocation) { + return getBlockModel(resourceLocation, defaultBlockState()); + } + + @Override + public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { + String name = resourceLocation.getPath(); + Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap() { + private static final long serialVersionUID = 1L; + { + put("%modid%", resourceLocation.getNamespace()); + put("%texture%", name); + put("%side%", name.replace("trapdoor", "door_side")); + } + }); + return ModelsHelper.fromPattern(pattern); + } + + @Override + public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath()); + registerBlockModel(stateId, modelId, blockState, modelCache); + boolean isTop = blockState.getValue(HALF) == Half.TOP; + boolean isOpen = blockState.getValue(OPEN); + int y = 0; + int x = (isTop && isOpen) ? 270 : isTop ? 180 : isOpen ? 90 : 0; + switch (blockState.getValue(FACING)) { + case EAST: + y = (isTop && isOpen) ? 270 : 90; + break; + case NORTH: + if (isTop && isOpen) y = 180; + break; + case SOUTH: + y = (isTop && isOpen) ? 0 : 180; + break; + case WEST: + y = (isTop && isOpen) ? 90 : 270; + break; + default: break; + } + BlockModelRotation rotation = BlockModelRotation.by(x, y); + return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); + } +}