-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- CraftingTable and Trapdoor models fix
- Loading branch information
Showing
3 changed files
with
146 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 56 additions & 55 deletions
111
src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |