diff --git a/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java b/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java index 1c7d4f48..8e67ec12 100644 --- a/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java @@ -2,13 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class DragonTreeSaplingBlock extends FeatureSaplingBlock { +public class DragonTreeSaplingBlock extends PottableFeatureSapling { public DragonTreeSaplingBlock() { super(); } @@ -22,4 +24,9 @@ public class DragonTreeSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.SHADOW_GRASS); } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.SHADOW_GRASS; + } } diff --git a/src/main/java/ru/betterend/blocks/EndBlockProperties.java b/src/main/java/ru/betterend/blocks/EndBlockProperties.java index 4785ece0..9198d03c 100644 --- a/src/main/java/ru/betterend/blocks/EndBlockProperties.java +++ b/src/main/java/ru/betterend/blocks/EndBlockProperties.java @@ -14,7 +14,7 @@ public class EndBlockProperties extends BlockProperties { public static final EnumProperty CACTUS_BOTTOM = EnumProperty.create("bottom", CactusBottom.class); public static final IntegerProperty PORTAL = IntegerProperty.create("portal", 0, EndPortals.getCount()); - public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 31); + public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 127); public static final IntegerProperty SOIL_ID = IntegerProperty.create("soil_id", 0, 10); public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item"); diff --git a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java index 9ec0c2ef..a078f7fd 100644 --- a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java +++ b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java @@ -1,6 +1,8 @@ package ru.betterend.blocks; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.math.Transformation; @@ -8,6 +10,7 @@ import com.mojang.math.Vector3f; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.ModelResourceLocation; @@ -25,6 +28,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.SaplingBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; @@ -33,6 +38,8 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.blocks.BaseBlockNotFull; +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; @@ -44,13 +51,20 @@ import ru.bclib.util.BlocksHelper; import ru.bclib.util.JsonFactory; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.EndTerrainBlock; +import ru.betterend.blocks.basis.PottableLeavesBlock; import ru.betterend.client.models.Patterns; +import ru.betterend.config.Configs; import ru.betterend.interfaces.PottablePlant; import ru.betterend.registry.EndBlocks; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.SplittableRandom; public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit { private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID; @@ -76,20 +90,47 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP if (FlowerPotBlock.plants != null) { return; } - List soils = Lists.newArrayList(); - List plants = Lists.newArrayList(); + + Block[] plants = new Block[128]; + Block[] soils = new Block[16]; + + Map reservedPlantsIDs = Maps.newHashMap(); + Map reservedSoilIDs = Maps.newHashMap(); + + JsonObject obj = JsonFactory.getJsonObject(new File(FabricLoader.getInstance().getConfigDir().toFile(), BetterEnd.MOD_ID + "/blocks.json")); + if (obj.get("flower_pots") != null) { + JsonElement plantsObj = obj.get("flower_pots").getAsJsonObject().get("plants"); + JsonElement soilsObj = obj.get("flower_pots").getAsJsonObject().get("soils"); + if (plantsObj != null) { + plantsObj.getAsJsonObject().entrySet().forEach(entry -> { + String name = entry.getKey().substring(0, entry.getKey().indexOf(' ')); + reservedPlantsIDs.put(name, entry.getValue().getAsInt()); + }); + } + if (soilsObj != null) { + soilsObj.getAsJsonObject().entrySet().forEach(entry -> { + String name = entry.getKey().substring(0, entry.getKey().indexOf(' ')); + reservedSoilIDs.put(name, entry.getValue().getAsInt()); + }); + } + } + EndBlocks.getModBlocks().forEach(block -> { - if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) { - if (!(block instanceof ISpetialItem) || !((ISpetialItem) block).canPlaceOnWater()) { - plants.add(block); - } + if (block instanceof PottablePlant && canBeAdded(block)) { + processBlock(plants, block, "flower_pots.plants", reservedPlantsIDs); } else if (block instanceof EndTerrainBlock) { - soils.add(block); + processBlock(soils, block, "flower_pots.soils", reservedSoilIDs); } }); - FlowerPotBlock.plants = plants.toArray(new Block[] {}); - FlowerPotBlock.soils = soils.toArray(new Block[] {}); + Configs.BLOCK_CONFIG.saveChanges(); + + FlowerPotBlock.plants = new Block[maxNotNull(plants) + 1]; + System.arraycopy(plants, 0, FlowerPotBlock.plants, 0, FlowerPotBlock.plants.length); + + FlowerPotBlock.soils = new Block[maxNotNull(soils) + 1]; + System.arraycopy(soils, 0, FlowerPotBlock.soils, 0, FlowerPotBlock.soils.length); + if (PLANT_ID.getValue(Integer.toString(FlowerPotBlock.plants.length)).isEmpty()) { throw new RuntimeException("There are too much plant ID values!"); } @@ -98,6 +139,49 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP } } + private int maxNotNull(Block[] array) { + int max = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + max = i; + } + } + return max; + } + + private boolean canBeAdded(Block block) { + if (block instanceof SaplingBlock) { + return true; + } + else if (block instanceof PottableLeavesBlock) { + return true; + } + else if (block instanceof ISpetialItem) { + return !((ISpetialItem) block).canPlaceOnWater(); + } + else if (block.getStateDefinition().getProperties().isEmpty()) { + return true; + } + return false; + } + + private void processBlock(Block[] target, Block block, String path, Map idMap) { + ResourceLocation location = Registry.BLOCK.getKey(block); + if (idMap.containsKey(location.getPath())) { + target[idMap.get(location.getPath())] = block; + } + else { + for (int i = 0; i < target.length; i++) { + if (!idMap.values().contains(i)) { + target[i] = block; + idMap.put(location.getPath(), i); + Configs.BLOCK_CONFIG.getInt(path, location.getPath(), i); + break; + } + } + } + } + @Override public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (level.isClientSide) { @@ -105,7 +189,7 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP } ItemStack itemStack = player.getItemInHand(hand); int soilID = state.getValue(SOIL_ID); - if (soilID == 0) { + if (soilID == 0 || soils[soilID - 1] == null) { if (!(itemStack.getItem() instanceof BlockItem)) { return InteractionResult.PASS; } @@ -170,6 +254,10 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP Transformation offset = new Transformation(new Vector3f(0, 7.5F / 16F, 0), null, null, null); for (int i = 0; i < plants.length; i++) { + if (plants[i] == null) { + continue; + } + final int compareID = i + 1; ResourceLocation modelPath = Registry.BLOCK.getKey(plants[i]); ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath() + ".json"); @@ -178,6 +266,32 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP model.part(objSource).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add(); continue; } + + else if (plants[i] instanceof SaplingBlock) { + ResourceLocation loc = Registry.BLOCK.getKey(plants[i]); + modelPath = new ResourceLocation(loc.getNamespace(), "block/" + loc.getPath()); + Map textures = Maps.newHashMap(); + textures.put("%modid%", loc.getNamespace()); + textures.put("%texture%", loc.getPath()); + Optional pattern = Patterns.createJson(BasePatterns.BLOCK_CROSS, textures); + UnbakedModel unbakedModel = ModelsHelper.fromPattern(pattern); + modelCache.put(modelPath, unbakedModel); + model.part(modelPath).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add(); + continue; + } + else if (plants[i] instanceof PottableLeavesBlock) { + ResourceLocation loc = Registry.BLOCK.getKey(plants[i]); + modelPath = new ResourceLocation(loc.getNamespace(), "block/" + loc.getPath()); + Map textures = Maps.newHashMap(); + textures.put("%leaves%", loc.getPath().contains("lucernia") ? loc.getPath() + "_1" : loc.getPath()); + textures.put("%stem%", loc.getPath().replace("_leaves", "_log_side")); + Optional pattern = Patterns.createJson(Patterns.BLOCK_POTTED_LEAVES, textures); + UnbakedModel unbakedModel = ModelsHelper.fromPattern(pattern); + modelCache.put(modelPath, unbakedModel); + model.part(modelPath).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add(); + continue; + } + objSource = new ResourceLocation(modelPath.getNamespace(), "blockstates/" + modelPath.getPath() + ".json"); JsonObject obj = JsonFactory.getJsonObject(objSource); if (obj != null) { @@ -191,9 +305,21 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP } model.part(new ResourceLocation(path)).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add(); } + else { + for (ResourceLocation location: modelCache.keySet()) { + if (location.getPath().equals(modelPath.getPath())) { + model.part(location).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add(); + break; + } + } + } } for (int i = 0; i < soils.length; i++) { + if (soils[i] == null) { + continue; + } + ResourceLocation soilLoc = BetterEnd.makeID("flower_pot_soil_" + i); if (!modelCache.containsKey(soilLoc)) { String texture = Registry.BLOCK.getKey(soils[i]).getPath() + "_top"; diff --git a/src/main/java/ru/betterend/blocks/HelixTreeSaplingBlock.java b/src/main/java/ru/betterend/blocks/HelixTreeSaplingBlock.java index 527cfd49..3650496c 100644 --- a/src/main/java/ru/betterend/blocks/HelixTreeSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/HelixTreeSaplingBlock.java @@ -1,12 +1,28 @@ package ru.betterend.blocks; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; +import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class HelixTreeSaplingBlock extends FeatureSaplingBlock { +public class HelixTreeSaplingBlock extends PottableFeatureSapling { @Override protected Feature getFeature() { return EndFeatures.HELIX_TREE.getFeature(); } + + @Override + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return world.getBlockState(pos.below()).is(EndBlocks.AMBER_MOSS); + } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.AMBER_MOSS; + } } diff --git a/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java b/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java index 81aad389..968acaa7 100644 --- a/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java @@ -2,13 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class LacugroveSaplingBlock extends FeatureSaplingBlock { +public class LacugroveSaplingBlock extends PottableFeatureSapling { public LacugroveSaplingBlock() { super(); } @@ -22,4 +24,9 @@ public class LacugroveSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.ENDSTONE_DUST); } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.END_MOSS; + } } diff --git a/src/main/java/ru/betterend/blocks/LucerniaSaplingBlock.java b/src/main/java/ru/betterend/blocks/LucerniaSaplingBlock.java index 688e377f..fa378841 100644 --- a/src/main/java/ru/betterend/blocks/LucerniaSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/LucerniaSaplingBlock.java @@ -2,13 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class LucerniaSaplingBlock extends FeatureSaplingBlock { +public class LucerniaSaplingBlock extends PottableFeatureSapling { public LucerniaSaplingBlock() { super(); } @@ -22,4 +24,9 @@ public class LucerniaSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.RUTISCUS); } + + @Override + public boolean canPlantOn(Block block) { + return false; + } } diff --git a/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java b/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java index 49a6f59d..77f54185 100644 --- a/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java @@ -2,14 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class MossyGlowshroomSaplingBlock extends FeatureSaplingBlock { - +public class MossyGlowshroomSaplingBlock extends PottableFeatureSapling { public MossyGlowshroomSaplingBlock() { super(7); } @@ -23,4 +24,9 @@ public class MossyGlowshroomSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.END_MYCELIUM); } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.END_MOSS || block == EndBlocks.END_MYCELIUM; + } } diff --git a/src/main/java/ru/betterend/blocks/NeonCactusPlantBlock.java b/src/main/java/ru/betterend/blocks/NeonCactusPlantBlock.java index 3c789dda..b2571ff5 100644 --- a/src/main/java/ru/betterend/blocks/NeonCactusPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/NeonCactusPlantBlock.java @@ -41,6 +41,7 @@ import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; import ru.betterend.blocks.EndBlockProperties.CactusBottom; +import ru.betterend.interfaces.PottablePlant; import ru.betterend.registry.EndBlocks; import java.util.EnumMap; @@ -48,7 +49,7 @@ import java.util.List; import java.util.Random; @SuppressWarnings("deprecation") -public class NeonCactusPlantBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, IRenderTyped { +public class NeonCactusPlantBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, IRenderTyped, PottablePlant { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty CACTUS_BOTTOM = EndBlockProperties.CACTUS_BOTTOM; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; @@ -395,4 +396,9 @@ public class NeonCactusPlantBlock extends BaseBlockNotFull implements SimpleWate SMALL_SHAPES_OPEN.put(Direction.WEST, Block.box(4, 4, 4, 16, 12, 12)); SMALL_SHAPES_OPEN.put(Direction.EAST, Block.box(0, 4, 4, 12, 12, 12)); } + + @Override + public boolean canPlantOn(Block block) { + return true; + } } diff --git a/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java b/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java index bb9f5050..3f1df4a8 100644 --- a/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java @@ -2,13 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class PythadendronSaplingBlock extends FeatureSaplingBlock { +public class PythadendronSaplingBlock extends PottableFeatureSapling { public PythadendronSaplingBlock() { super(); } @@ -22,4 +24,9 @@ public class PythadendronSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.CHORUS_NYLIUM); } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.CHORUS_NYLIUM; + } } diff --git a/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java b/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java index 4de9a91c..d1bec804 100644 --- a/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java +++ b/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java @@ -30,13 +30,14 @@ import ru.bclib.blocks.BaseAttachedBlock; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.BlocksHelper; +import ru.betterend.interfaces.PottablePlant; import ru.betterend.registry.EndFeatures; import java.util.EnumMap; import java.util.List; import java.util.Random; -public class SmallJellyshroomBlock extends BaseAttachedBlock implements IRenderTyped, BonemealableBlock { +public class SmallJellyshroomBlock extends BaseAttachedBlock implements IRenderTyped, BonemealableBlock, PottablePlant { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); public SmallJellyshroomBlock() { @@ -97,4 +98,9 @@ public class SmallJellyshroomBlock extends BaseAttachedBlock implements IRenderT BlocksHelper.setWithUpdate(world, pos, Blocks.AIR); EndFeatures.JELLYSHROOM.getFeature().place(new FeaturePlaceContext<>(world, null, random, pos, null)); } + + @Override + public boolean canPlantOn(Block block) { + return true; + } } diff --git a/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java b/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java index e9594b7b..2e960926 100644 --- a/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java @@ -2,13 +2,15 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class TenaneaSaplingBlock extends FeatureSaplingBlock { +public class TenaneaSaplingBlock extends PottableFeatureSapling { public TenaneaSaplingBlock() { super(); } @@ -22,4 +24,9 @@ public class TenaneaSaplingBlock extends FeatureSaplingBlock { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.PINK_MOSS); } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.PINK_MOSS; + } } diff --git a/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java index 4beeaec8..782942a6 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java @@ -2,14 +2,16 @@ package ru.betterend.blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.blocks.FeatureSaplingBlock; import ru.bclib.client.render.BCLRenderLayer; +import ru.betterend.blocks.basis.PottableFeatureSapling; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; -public class UmbrellaTreeSaplingBlock extends FeatureSaplingBlock { +public class UmbrellaTreeSaplingBlock extends PottableFeatureSapling { public UmbrellaTreeSaplingBlock() { super(); } @@ -28,4 +30,9 @@ public class UmbrellaTreeSaplingBlock extends FeatureSaplingBlock { public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.TRANSLUCENT; } + + @Override + public boolean canPlantOn(Block block) { + return block == EndBlocks.JUNGLE_MOSS; + } } diff --git a/src/main/java/ru/betterend/blocks/basis/PottableFeatureSapling.java b/src/main/java/ru/betterend/blocks/basis/PottableFeatureSapling.java new file mode 100644 index 00000000..387f0a2f --- /dev/null +++ b/src/main/java/ru/betterend/blocks/basis/PottableFeatureSapling.java @@ -0,0 +1,16 @@ +package ru.betterend.blocks.basis; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.feature.Feature; +import ru.bclib.blocks.FeatureSaplingBlock; +import ru.betterend.interfaces.PottablePlant; + +public abstract class PottableFeatureSapling extends FeatureSaplingBlock implements PottablePlant { + public PottableFeatureSapling() { + super(); + } + + public PottableFeatureSapling(int light) { + super(light); + } +} diff --git a/src/main/java/ru/betterend/blocks/basis/PottableLeavesBlock.java b/src/main/java/ru/betterend/blocks/basis/PottableLeavesBlock.java new file mode 100644 index 00000000..e8672e54 --- /dev/null +++ b/src/main/java/ru/betterend/blocks/basis/PottableLeavesBlock.java @@ -0,0 +1,28 @@ +package ru.betterend.blocks.basis; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.MaterialColor; +import ru.bclib.blocks.BaseLeavesBlock; +import ru.betterend.interfaces.PottablePlant; + +public class PottableLeavesBlock extends BaseLeavesBlock implements PottablePlant { + private Block sapling; + + public PottableLeavesBlock(Block sapling, MaterialColor color) { + super(sapling, color); + this.sapling = sapling; + } + + public PottableLeavesBlock(Block sapling, MaterialColor color, int light) { + super(sapling, color, light); + this.sapling = sapling; + } + + @Override + public boolean canPlantOn(Block block) { + if (sapling instanceof PottablePlant) { + ((PottablePlant) sapling).canPlantOn(block); + } + return true; + } +} diff --git a/src/main/java/ru/betterend/client/models/Patterns.java b/src/main/java/ru/betterend/client/models/Patterns.java index 36e49e9c..9b4609d5 100644 --- a/src/main/java/ru/betterend/client/models/Patterns.java +++ b/src/main/java/ru/betterend/client/models/Patterns.java @@ -76,6 +76,7 @@ public class Patterns { public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json"); public final static ResourceLocation BLOCK_FLOWER_POT = BetterEnd.makeID("patterns/block/flower_pot.json"); public final static ResourceLocation BLOCK_FLOWER_POT_SOIL = BetterEnd.makeID("patterns/block/flower_pot_soil.json"); + public final static ResourceLocation BLOCK_POTTED_LEAVES = BetterEnd.makeID("patterns/block/potted_leaves.json"); //Item Models public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); diff --git a/src/main/java/ru/betterend/registry/EndBlocks.java b/src/main/java/ru/betterend/registry/EndBlocks.java index 014f20e5..78c2ae4d 100644 --- a/src/main/java/ru/betterend/registry/EndBlocks.java +++ b/src/main/java/ru/betterend/registry/EndBlocks.java @@ -12,7 +12,6 @@ import ru.bclib.blocks.BaseBarrelBlock; import ru.bclib.blocks.BaseChestBlock; import ru.bclib.blocks.BaseCropBlock; import ru.bclib.blocks.BaseFurnaceBlock; -import ru.bclib.blocks.BaseLeavesBlock; import ru.bclib.blocks.BaseOreBlock; import ru.bclib.blocks.BasePathBlock; import ru.bclib.blocks.BaseRotatedPillarBlock; @@ -133,6 +132,7 @@ import ru.betterend.blocks.basis.EndUnderwaterWallPlantBlock; import ru.betterend.blocks.basis.EndWallMushroom; import ru.betterend.blocks.basis.EndWallPlantBlock; import ru.betterend.blocks.basis.FurBlock; +import ru.betterend.blocks.basis.PottableLeavesBlock; import ru.betterend.blocks.basis.StoneLanternBlock; import ru.betterend.blocks.complex.ColoredMaterial; import ru.betterend.blocks.complex.CrystalSubblocksMaterial; @@ -221,7 +221,7 @@ public class EndBlocks extends BlocksRegistry { public static final WoodenMaterial MOSSY_GLOWSHROOM = new WoodenMaterial("mossy_glowshroom", MaterialColor.COLOR_GRAY, MaterialColor.WOOD); public static final Block PYTHADENDRON_SAPLING = registerBlock("pythadendron_sapling", new PythadendronSaplingBlock()); - public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", new BaseLeavesBlock(PYTHADENDRON_SAPLING, MaterialColor.COLOR_MAGENTA)); + public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", new PottableLeavesBlock(PYTHADENDRON_SAPLING, MaterialColor.COLOR_MAGENTA)); public static final WoodenMaterial PYTHADENDRON = new WoodenMaterial("pythadendron", MaterialColor.COLOR_MAGENTA, MaterialColor.COLOR_PURPLE); public static final Block END_LOTUS_SEED = registerBlock("end_lotus_seed", new EndLotusSeedBlock()); @@ -231,15 +231,15 @@ public class EndBlocks extends BlocksRegistry { public static final WoodenMaterial END_LOTUS = new WoodenMaterial("end_lotus", MaterialColor.COLOR_LIGHT_BLUE, MaterialColor.COLOR_CYAN); public static final Block LACUGROVE_SAPLING = registerBlock("lacugrove_sapling", new LacugroveSaplingBlock()); - public static final Block LACUGROVE_LEAVES = registerBlock("lacugrove_leaves", new BaseLeavesBlock(LACUGROVE_SAPLING, MaterialColor.COLOR_CYAN)); + public static final Block LACUGROVE_LEAVES = registerBlock("lacugrove_leaves", new PottableLeavesBlock(LACUGROVE_SAPLING, MaterialColor.COLOR_CYAN)); public static final WoodenMaterial LACUGROVE = new WoodenMaterial("lacugrove", MaterialColor.COLOR_BROWN, MaterialColor.COLOR_YELLOW); public static final Block DRAGON_TREE_SAPLING = registerBlock("dragon_tree_sapling", new DragonTreeSaplingBlock()); - public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", new BaseLeavesBlock(DRAGON_TREE_SAPLING, MaterialColor.COLOR_MAGENTA)); + public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", new PottableLeavesBlock(DRAGON_TREE_SAPLING, MaterialColor.COLOR_MAGENTA)); public static final WoodenMaterial DRAGON_TREE = new WoodenMaterial("dragon_tree", MaterialColor.COLOR_BLACK, MaterialColor.COLOR_MAGENTA); public static final Block TENANEA_SAPLING = registerBlock("tenanea_sapling", new TenaneaSaplingBlock()); - public static final Block TENANEA_LEAVES = registerBlock("tenanea_leaves", new BaseLeavesBlock(TENANEA_SAPLING, MaterialColor.COLOR_PINK)); + public static final Block TENANEA_LEAVES = registerBlock("tenanea_leaves", new PottableLeavesBlock(TENANEA_SAPLING, MaterialColor.COLOR_PINK)); public static final Block TENANEA_FLOWERS = registerBlock("tenanea_flowers", new TenaneaFlowersBlock()); public static final Block TENANEA_OUTER_LEAVES = registerBlock("tenanea_outer_leaves", new FurBlock(TENANEA_SAPLING, 32)); public static final WoodenMaterial TENANEA = new WoodenMaterial("tenanea", MaterialColor.COLOR_BROWN, MaterialColor.COLOR_PINK); @@ -258,7 +258,7 @@ public class EndBlocks extends BlocksRegistry { public static final WoodenMaterial JELLYSHROOM = new WoodenMaterial("jellyshroom", MaterialColor.COLOR_PURPLE, MaterialColor.COLOR_LIGHT_BLUE); public static final Block LUCERNIA_SAPLING = registerBlock("lucernia_sapling", new LucerniaSaplingBlock()); - public static final Block LUCERNIA_LEAVES = registerBlock("lucernia_leaves", new BaseLeavesBlock(LUCERNIA_SAPLING, MaterialColor.COLOR_ORANGE)); + public static final Block LUCERNIA_LEAVES = registerBlock("lucernia_leaves", new PottableLeavesBlock(LUCERNIA_SAPLING, MaterialColor.COLOR_ORANGE)); public static final Block LUCERNIA_OUTER_LEAVES = registerBlock("lucernia_outer_leaves", new FurBlock(LUCERNIA_SAPLING, 32)); public static final WoodenMaterial LUCERNIA = new WoodenMaterial("lucernia", MaterialColor.COLOR_ORANGE, MaterialColor.COLOR_ORANGE); diff --git a/src/main/resources/assets/betterend/patterns/block/potted_leaves.json b/src/main/resources/assets/betterend/patterns/block/potted_leaves.json new file mode 100644 index 00000000..8e2446f5 --- /dev/null +++ b/src/main/resources/assets/betterend/patterns/block/potted_leaves.json @@ -0,0 +1,35 @@ +{ + "__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio", + "textures": { + "particle": "betterend:block/%leaves%", + "stem": "betterend:block/%stem%", + "leaves": "betterend:block/%leaves%" + }, + "elements": [ + { + "__comment": "Box1", + "from": [ 3, 2, 3 ], + "to": [ 13, 12, 13 ], + "faces": { + "down": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" }, + "up": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" }, + "north": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" }, + "south": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" }, + "west": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" }, + "east": { "uv": [ 3, 3, 13, 13 ], "texture": "#leaves" } + } + }, + { + "__comment": "Box1", + "from": [ 7, 0, 7 ], + "to": [ 9, 8, 9 ], + "faces": { + "up": { "uv": [ 7, 7, 9, 9 ], "texture": "#stem" }, + "north": { "uv": [ 7, 8, 9, 16 ], "texture": "#stem" }, + "south": { "uv": [ 7, 8, 9, 16 ], "texture": "#stem" }, + "west": { "uv": [ 7, 8, 9, 16 ], "texture": "#stem" }, + "east": { "uv": [ 7, 8, 9, 16 ], "texture": "#stem" } + } + } + ] +} \ No newline at end of file