Skip to content

Commit

Permalink
- CraftingTable and Trapdoor models fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulldog83 committed Jun 11, 2021
1 parent da1c27a commit 72b1b23
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 144 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
111 changes: 56 additions & 55 deletions src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap<String, String>() {
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<ItemStack> 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<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap<String, String>() {
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);
}
}
177 changes: 89 additions & 88 deletions src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
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<ResourceLocation, UnbakedModel> 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<ItemStack> 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<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
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<ResourceLocation, UnbakedModel> 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);
}
}

0 comments on commit 72b1b23

Please sign in to comment.