diff --git a/src/main/java/ru/bclib/blocks/BaseBlock.java b/src/main/java/ru/bclib/blocks/BaseBlock.java
index bfb52a10..e9e663bd 100644
--- a/src/main/java/ru/bclib/blocks/BaseBlock.java
+++ b/src/main/java/ru/bclib/blocks/BaseBlock.java
@@ -1,29 +1,71 @@
package ru.bclib.blocks;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Consumer;
+
+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.state.BlockState;
+import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.bclib.client.models.BlockModelProvider;
-import java.util.Collections;
-import java.util.List;
-
+/**
+ * Base class for a default Block.
+ *
+ * This Block-Type will:
+ *
+ * - Drop itself
+ * - Automatically create an Item-Model from the Block-Model
+ *
+ */
public class BaseBlock extends Block implements BlockModelProvider {
+ /**
+ * Creates a new Block with the passed properties
+ * @param settings The properties of the Block.
+ */
public BaseBlock(Properties settings) {
super(settings);
}
-
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation will drop the Block itself
+ */
@Override
@SuppressWarnings("deprecation")
public List getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
-
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation will load the Block-Model and return it as the Item-Model
+ */
@Override
public BlockModel getItemModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
}
+
+ /**
+ * This method is used internally.
+ *
+ * It is called from Block-Contructors, to allow the augmentation of the blocks
+ * preset properties.
+ *
+ * For example in {@link BaseLeavesBlock#BaseLeavesBlock(Block, MaterialColor, Consumer)}
+ * @param customizeProperties A {@link Consumer} to call with the preset properties
+ * @param settings The properties as created by the Block
+ * @return The reconfigured {@code settings}
+ */
+ static FabricBlockSettings acceptAndReturn(Consumer customizeProperties, FabricBlockSettings settings){
+ customizeProperties.accept(settings);
+ return settings;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java
index e77d96c5..c6386ef7 100644
--- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java
+++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java
@@ -1,6 +1,11 @@
package ru.bclib.blocks;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Consumer;
+
import com.google.common.collect.Lists;
+
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
@@ -20,19 +25,38 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.MHelper;
-import java.util.Collections;
-import java.util.List;
-
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped {
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);
+ }
+
+ public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer customizeProperties) {
+ super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color)));
+ this.sapling = sapling;
+ }
+
+ public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer customizeProperties) {
+ super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
+ this.sapling = sapling;
+ }
public BaseLeavesBlock(Block sapling, MaterialColor color) {
- super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true).isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
+ super(makeLeaves(color));
this.sapling = sapling;
}
public BaseLeavesBlock(Block sapling, MaterialColor color, int light) {
- super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).luminance(light).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
+ super(makeLeaves(color).lightLevel(light));
this.sapling = sapling;
}