Code style fix, interface rename, custom item getter

This commit is contained in:
paulevsGitch 2021-07-20 00:10:00 +03:00
parent 179ada3296
commit c6afa74529
134 changed files with 3404 additions and 1244 deletions

View file

@ -4,10 +4,12 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
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.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.AnvilBlock;
@ -20,16 +22,18 @@ import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import ru.bclib.interfaces.CustomItemGetter;
import ru.bclib.items.BaseAnvilItem;
import ru.bclib.registry.BlocksRegistry;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelGetter, CustomItemGetter {
public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
public BaseAnvilBlock(MaterialColor color) {
@ -91,4 +95,9 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro
registerBlockModel(stateId, modelLocation, blockState, modelCache);
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
}
@Override
public BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings) {
return new BaseAnvilItem(this, settings);
}
}

View file

@ -28,9 +28,9 @@ import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseBarrelBlockEntity;
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.interfaces.BlockModelGetter;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
@ -38,7 +38,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Random;
public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
public class BaseBarrelBlock extends BarrelBlock implements BlockModelGetter {
public BaseBarrelBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noOcclusion());
}

View file

@ -8,7 +8,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
@ -23,7 +23,7 @@ import java.util.function.Consumer;
* <li>Automatically create an Item-Model from the Block-Model</li>
* </ul>
*/
public class BaseBlock extends Block implements BlockModelProvider {
public class BaseBlock extends Block implements BlockModelGetter {
/**
* Creates a new Block with the passed properties
*

View file

@ -15,16 +15,16 @@ import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelProvider {
public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelGetter {
private final Block parent;
@ -51,7 +51,10 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
@Environment(EnvType.CLIENT)
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(
BasePatterns.BLOCK_BUTTON_PRESSED,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
return ModelsHelper.fromPattern(pattern);
}

View file

@ -15,18 +15,18 @@ import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IRenderTyped {
public class BaseChainBlock extends ChainBlock implements BlockModelGetter, RenderLayerGetter {
public BaseChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color));
}

View file

@ -15,15 +15,15 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
import java.util.Optional;
public class BaseChestBlock extends ChestBlock implements BlockModelProvider {
public class BaseChestBlock extends ChestBlock implements BlockModelGetter {
private final Block parent;
public BaseChestBlock(Block source) {

View file

@ -13,17 +13,17 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseComposterBlock extends ComposterBlock implements BlockModelProvider {
public class BaseComposterBlock extends ComposterBlock implements BlockModelGetter {
public BaseComposterBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
}

View file

@ -12,16 +12,16 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelGetter {
public BaseCraftingTableBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
}

View file

@ -38,7 +38,12 @@ public class BaseCropBlock extends BasePlantBlock {
private final Item drop;
public BaseCropBlock(Item drop, Block... terrain) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.HOES)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
this.drop = drop;
this.terrain = terrain;
this.registerDefaultState(defaultBlockState().setValue(AGE, 0));

View file

@ -18,18 +18,18 @@ import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModelProvider {
public class BaseDoorBlock extends DoorBlock implements RenderLayerGetter, BlockModelGetter {
public BaseDoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion());
}
@ -114,7 +114,10 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
}
break;
}
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + doorType);
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + doorType
);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
}

View file

@ -31,25 +31,34 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements RenderLayerGetter, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
public static final IntegerProperty ROTATION = BlockProperties.ROTATION;
public static final BooleanProperty TOP = BooleanProperty.create("top");
public BaseDoublePlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
public BaseDoublePlantBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).lightLevel((state) -> state.getValue(TOP) ? light : 0).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
@ -101,7 +110,10 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
}
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -126,7 +138,13 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}

View file

@ -15,17 +15,17 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
public class BaseFenceBlock extends FenceBlock implements BlockModelGetter {
private final Block parent;
public BaseFenceBlock(Block source) {
@ -72,9 +72,21 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideId)
.setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
builder.part(postId).add();
return builder.build();

View file

@ -26,18 +26,18 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseFurnaceBlockEntity;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider, IRenderTyped {
public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelGetter, RenderLayerGetter {
public BaseFurnaceBlock(Block source) {
super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0));
}
@ -119,6 +119,10 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
@Nullable
protected static <T extends BlockEntity> BlockEntityTicker<T> createFurnaceTicker(Level level, BlockEntityType<T> blockEntityType, BlockEntityType<? extends AbstractFurnaceBlockEntity> blockEntityType2) {
return level.isClientSide ? null : createTickerHelper(blockEntityType, blockEntityType2, AbstractFurnaceBlockEntity::serverTick);
return level.isClientSide ? null : createTickerHelper(
blockEntityType,
blockEntityType2,
AbstractFurnaceBlockEntity::serverTick
);
}
}

View file

@ -14,16 +14,16 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider {
public class BaseGateBlock extends FenceGateBlock implements BlockModelGetter {
private final Block parent;
public BaseGateBlock(Block source) {
@ -51,10 +51,16 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern;
if (inWall) {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId);
pattern = isOpen ? PatternsHelper.createJson(
BasePatterns.BLOCK_GATE_OPEN_WALL,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId);
}
else {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
pattern = isOpen ? PatternsHelper.createJson(
BasePatterns.BLOCK_GATE_OPEN,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
}
return ModelsHelper.fromPattern(pattern);
}

View file

@ -28,18 +28,18 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import ru.bclib.util.BlocksHelper;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation")
public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider {
public class BaseLadderBlock extends BaseBlockNotFull implements RenderLayerGetter, BlockModelGetter {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);

View file

@ -15,20 +15,27 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped {
public class BaseLeavesBlock extends LeavesBlock implements BlockModelGetter, RenderLayerGetter {
private final Block sapling;
private static FabricBlockSettings makeLeaves(MaterialColor color) {
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true).allowsSpawning((state, world, pos, type) -> false).suffocates((state, world, pos) -> false).blockVision((state, world, pos) -> false);
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.mapColor(color)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.allowsSpawning((state, world, pos, type) -> false)
.suffocates((state, world, pos) -> false)
.blockVision((state, world, pos) -> false);
}
public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer<FabricBlockSettings> customizeProperties) {
@ -61,7 +68,10 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Collections.singletonList(new ItemStack(this));
}
int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);

View file

@ -16,18 +16,18 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, IRenderTyped {
public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelGetter, RenderLayerGetter {
public BaseMetalBarsBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion());
}
@ -81,11 +81,26 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi
registerBlockModel(sideId, sideId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(postId).setCondition(state -> !state.getValue(NORTH) && !state.getValue(EAST) && !state.getValue(SOUTH) && !state.getValue(WEST)).add();
builder.part(postId)
.setCondition(state -> !state.getValue(NORTH) && !state.getValue(EAST) && !state.getValue(SOUTH) && !state
.getValue(WEST))
.add();
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideId)
.setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
return builder.build();
}

View file

@ -16,19 +16,23 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
public class BaseOreBlock extends OreBlock implements BlockModelProvider {
public class BaseOreBlock extends OreBlock implements BlockModelGetter {
private final Item dropItem;
private final int minCount;
private final int maxCount;
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresCorrectToolForDrops().sound(SoundType.STONE), UniformInt.of(1, experience));
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.hardness(3F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE), UniformInt.of(1, experience));
this.dropItem = drop;
this.minCount = minCount;
this.maxCount = maxCount;

View file

@ -27,13 +27,13 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerGetter, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public BasePlantBlock() {
@ -45,11 +45,20 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
}
public BasePlantBlock(boolean replaceable) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public BasePlantBlock(boolean replaceable, int light) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public BasePlantBlock(Properties settings) {
@ -88,7 +97,10 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -113,7 +125,13 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}
}

View file

@ -19,7 +19,12 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public BasePlantWithAgeBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
}
public BasePlantWithAgeBlock(Properties settings) {

View file

@ -14,16 +14,16 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BasePressurePlateBlock extends PressurePlateBlock implements BlockModelProvider {
public class BasePressurePlateBlock extends PressurePlateBlock implements BlockModelGetter {
private final Block parent;
public BasePressurePlateBlock(Sensitivity rule, Block source) {

View file

@ -12,16 +12,16 @@ import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockModelGetter {
public BaseRotatedPillarBlock(Properties settings) {
super(settings);
}

View file

@ -2,6 +2,7 @@ package ru.bclib.blocks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos;
@ -13,6 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
@ -39,25 +41,34 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.CustomItemGetter;
import ru.bclib.registry.BlocksRegistry;
import ru.bclib.util.BlocksHelper;
import java.util.Collections;
import java.util.List;
@SuppressWarnings("deprecation")
public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
public class BaseSignBlock extends SignBlock implements BlockModelGetter, CustomItemGetter {
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D), Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)};
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
};
private final Block parent;
public BaseSignBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false));
this.registerDefaultState(this.stateDefinition.any()
.setValue(ROTATION, 0)
.setValue(FLOOR, false)
.setValue(WATERLOGGED, false));
this.parent = source;
}
@ -98,7 +109,8 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
if (!canSurvive(state, world, pos)) {
return state.getValue(WATERLOGGED) ? state.getFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState();
return state.getValue(WATERLOGGED) ? state.getFluidState()
.createLegacyBlock() : Blocks.AIR.defaultBlockState();
}
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
}
@ -118,7 +130,10 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
if (ctx.getClickedFace() == Direction.UP) {
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
return this.defaultBlockState().setValue(FLOOR, true).setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
return this.defaultBlockState()
.setValue(FLOOR, true)
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15)
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
else if (ctx.getClickedFace() != Direction.DOWN) {
BlockState blockState = this.defaultBlockState();
@ -133,7 +148,8 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
blockState = blockState.setValue(ROTATION, rot);
if (blockState.canSurvive(worldView, blockPos)) {
return blockState.setValue(FLOOR, false).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
return blockState.setValue(FLOOR, false)
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}
}
@ -177,12 +193,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
}
@Override
public int getStackSize() {
return 16;
}
@Override
public boolean canPlaceOnWater() {
return false;
public BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings) {
return new BlockItem(this, settings.maxCount(16));
}
}

View file

@ -16,16 +16,16 @@ import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
public class BaseSlabBlock extends SlabBlock implements BlockModelGetter {
private final Block parent;
public BaseSlabBlock(Block source) {
@ -63,7 +63,10 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
SlabType type = blockState.getValue(TYPE);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + type);
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + type
);
registerBlockModel(stateId, modelId, blockState, modelCache);
if (type == SlabType.TOP) {
return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true);

View file

@ -17,16 +17,16 @@ import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
public class BaseStairsBlock extends StairBlock implements BlockModelGetter {
private final Block parent;

View file

@ -30,7 +30,11 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos,
striped.defaultBlockState()
.setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)),
11
);
if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}

View file

@ -51,7 +51,10 @@ public class BaseTerrainBlock extends BaseBlock {
private Block pathBlock;
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
super(FabricBlockSettings.copyOf(baseBlock)
.materialColor(color)
.sound(BlockSounds.TERRAIN_SOUND)
.randomTicks());
this.baseBlock = baseBlock;
}
@ -104,7 +107,15 @@ public class BaseTerrainBlock extends BaseBlock {
return false;
}
else {
int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
int i = LayerLightEngine.getLightBlockInto(
worldView,
state,
pos,
blockState,
blockPos,
Direction.UP,
blockState.getLightBlock(worldView, blockPos)
);
return i < 5;
}
}

View file

@ -15,11 +15,11 @@ import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Collections;
import java.util.HashMap;
@ -27,7 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider {
public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerGetter, BlockModelGetter {
public BaseTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
}
@ -53,15 +53,18 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
@Environment(EnvType.CLIENT)
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"));
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);
}

View file

@ -17,11 +17,20 @@ import net.minecraft.world.level.material.Material;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer {
public BaseUnderwaterWallPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public BaseUnderwaterWallPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public BaseUnderwaterWallPlantBlock(Properties settings) {

View file

@ -30,14 +30,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.blocks.BlockProperties.TripleShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerGetter, BonemealableBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape VOXEL_SHAPE = Block.box(2, 0, 2, 14, 16, 14);
@ -50,7 +50,12 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
}
public BaseVineBlock(int light, boolean bottomOnly) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM));
}
@ -99,7 +104,10 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -16,16 +16,16 @@ import net.minecraft.world.level.block.state.properties.WallSide;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseWallBlock extends WallBlock implements BlockModelProvider {
public class BaseWallBlock extends WallBlock implements BlockModelGetter {
private final Block parent;
@ -71,20 +71,50 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider {
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side");
ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side_tall");
ResourceLocation sideTallId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.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(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();

View file

@ -28,15 +28,33 @@ import ru.bclib.util.BlocksHelper;
import java.util.EnumMap;
public abstract class BaseWallPlantBlock extends BasePlantBlock {
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8), Direction.WEST, Block.box(8, 1, 1, 16, 15, 15), Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(
Direction.NORTH,
Block.box(1, 1, 8, 15, 15, 16),
Direction.SOUTH,
Block.box(1, 1, 0, 15, 15, 8),
Direction.WEST,
Block.box(8, 1, 1, 16, 15, 15),
Direction.EAST,
Block.box(0, 1, 1, 8, 15, 15)
));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public BaseWallPlantBlock(int light) {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public BaseWallPlantBlock(Properties settings) {

View file

@ -14,20 +14,23 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
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.interfaces.BlockModelGetter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implements BlockModelProvider {
public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implements BlockModelGetter {
private final Block parent;
public BaseWeightedPlateBlock(Block source) {
super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F));
super(
15,
FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F)
);
this.parent = source;
}

View file

@ -25,11 +25,11 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
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.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelGetter;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Collections;
import java.util.List;
@ -37,15 +37,32 @@ import java.util.Optional;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider {
public abstract class FeatureSaplingBlock extends SaplingBlock implements RenderLayerGetter, BlockModelGetter {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public FeatureSaplingBlock() {
super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).instabreak().sound(SoundType.GRASS).randomTicks());
super(
null,
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks()
);
}
public FeatureSaplingBlock(int light) {
super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).luminance(light).instabreak().sound(SoundType.GRASS).randomTicks());
super(
null,
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.luminance(light)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks()
);
}
protected abstract Feature<?> getFeature();
@ -73,7 +90,13 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
@Override
public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) {
FeaturePlaceContext context = new FeaturePlaceContext(world, world.getChunkSource().getGenerator(), random, pos, null);
FeaturePlaceContext context = new FeaturePlaceContext(
world,
world.getChunkSource().getGenerator(),
random,
pos,
null
);
getFeature().place(context);
}

View file

@ -5,15 +5,30 @@ import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped {
public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerGetter {
public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).mapColor(color).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
super(FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.mapColor(color)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES).luminance(light).mapColor(color).strength(0.2F).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
super(FabricBlockSettings.of(Material.LEAVES)
.luminance(light)
.mapColor(color)
.strength(0.2F)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
@Override

View file

@ -37,13 +37,13 @@ import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation")
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped {
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, RenderLayerGetter {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
public static final IntegerProperty SIZE = BlockProperties.SIZE;
@ -51,7 +51,10 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
public StalactiteBlock(Block source) {
super(FabricBlockSettings.copy(source).noOcclusion());
this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false));
this.registerDefaultState(getStateDefinition().any()
.setValue(SIZE, 0)
.setValue(IS_FLOOR, true)
.setValue(WATERLOGGED, false));
}
@Override
@ -212,7 +215,10 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0;
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), stateId.getPath() + "_" + blockState.getValue(SIZE));
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
stateId.getPath() + "_" + blockState.getValue(SIZE)
);
registerBlockModel(modelId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
}

View file

@ -30,7 +30,11 @@ public class StripableBarkBlock extends BaseBarkBlock {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos,
striped.defaultBlockState()
.setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)),
11
);
if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}

View file

@ -153,7 +153,17 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
return new MultiVariant(variants);
}
else if (blockState.getValue(SHAPE) == TripleShape.TOP) {
return new MultiVariant(Lists.newArrayList(new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)));
return new MultiVariant(Lists.newArrayList(
new Variant(
modelId,
BlockModelRotation.X180_Y0.getRotation(),
false,
1
),
new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)
));
}
return ModelsHelper.createRandomTopModel(modelId);
}

View file

@ -31,21 +31,30 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer {
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerGetter, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(Properties settings) {
@ -86,7 +95,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -111,7 +123,13 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}

View file

@ -18,7 +18,12 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).randomTicks().noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.randomTicks()
.noCollission());
}
@Override

View file

@ -24,16 +24,20 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerGetter;
import java.util.List;
@SuppressWarnings("deprecation")
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped {
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerGetter {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
protected abstract boolean isTerrain(BlockState state);
@ -67,7 +71,10 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRend
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -16,7 +16,14 @@ import java.util.List;
public abstract class WallMushroomBlock extends BaseWallPlantBlock {
public WallMushroomBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).breakByHand(true).luminance(light).hardness(0.2F).sound(SoundType.GRASS).sound(SoundType.WOOD).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.AXES)
.breakByHand(true)
.luminance(light)
.hardness(0.2F)
.sound(SoundType.GRASS)
.sound(SoundType.WOOD)
.noCollission());
}
@Override