diff --git a/src/main/java/ru/betterend/blocks/EndBlockProperties.java b/src/main/java/ru/betterend/blocks/EndBlockProperties.java index fe977a04..4785ece0 100644 --- a/src/main/java/ru/betterend/blocks/EndBlockProperties.java +++ b/src/main/java/ru/betterend/blocks/EndBlockProperties.java @@ -5,6 +5,7 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; import ru.bclib.blocks.BlockProperties; +import ru.bclib.blocks.properties.StringProperty; import ru.betterend.registry.EndPortals; public class EndBlockProperties extends BlockProperties { @@ -12,9 +13,10 @@ public class EndBlockProperties extends BlockProperties { public static final EnumProperty PEDESTAL_STATE = EnumProperty.create("state", PedestalState.class); public static final EnumProperty CACTUS_BOTTOM = EnumProperty.create("bottom", CactusBottom.class); - public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item"); public static final IntegerProperty PORTAL = IntegerProperty.create("portal", 0, EndPortals.getCount()); - public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 127); + public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 31); + public static final IntegerProperty SOIL_ID = IntegerProperty.create("soil_id", 0, 10); + public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item"); public enum PedestalState implements StringRepresentable { PEDESTAL_TOP("pedestal_top"), COLUMN_TOP("column_top"), BOTTOM("bottom"), PILLAR("pillar"), COLUMN("column"), DEFAULT("default"); diff --git a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java index 584af092..9ec0c2ef 100644 --- a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java +++ b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java @@ -15,6 +15,8 @@ import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -40,6 +42,8 @@ import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.ISpetialItem; import ru.bclib.util.BlocksHelper; import ru.bclib.util.JsonFactory; +import ru.betterend.BetterEnd; +import ru.betterend.blocks.basis.EndTerrainBlock; import ru.betterend.client.models.Patterns; import ru.betterend.interfaces.PottablePlant; import ru.betterend.registry.EndBlocks; @@ -49,13 +53,12 @@ import java.util.Map; import java.util.Optional; public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit { - private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 8, 12); private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID; - private static VoxelShape[] plantBoxes; - private static Block[] blocks; - - @Environment(EnvType.CLIENT) - private UnbakedModel source; + private static final IntegerProperty SOIL_ID = EndBlockProperties.SOIL_ID; + private static final VoxelShape SHAPE_EMPTY; + private static final VoxelShape SHAPE_FULL; + private static Block[] plants; + private static Block[] soils; public FlowerPotBlock(Block source) { super(FabricBlockSettings.copyOf(source)); @@ -65,28 +68,33 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); - builder.add(PLANT_ID); + builder.add(PLANT_ID, SOIL_ID); } @Override public void postInit() { - if (this.blocks != null) { + if (FlowerPotBlock.plants != null) { return; } - List blocks = Lists.newArrayList(); + List soils = Lists.newArrayList(); + List plants = Lists.newArrayList(); EndBlocks.getModBlocks().forEach(block -> { if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) { if (!(block instanceof ISpetialItem) || !((ISpetialItem) block).canPlaceOnWater()) { - blocks.add(block); + plants.add(block); } } + else if (block instanceof EndTerrainBlock) { + soils.add(block); + } }); - FlowerPotBlock.blocks = blocks.toArray(new Block[] {}); - FlowerPotBlock.plantBoxes = new VoxelShape[FlowerPotBlock.blocks.length]; - for (int i = 0; i < FlowerPotBlock.blocks.length; i++) { - Block block = FlowerPotBlock.blocks[i]; - VoxelShape shape = block.getShape(block.defaultBlockState(), null, BlockPos.ZERO, CollisionContext.empty()); - plantBoxes[i] = Shapes.or(SHAPE, shape.move(0.25, 0.5, 0.25)); + FlowerPotBlock.plants = plants.toArray(new Block[] {}); + FlowerPotBlock.soils = soils.toArray(new Block[] {}); + if (PLANT_ID.getValue(Integer.toString(FlowerPotBlock.plants.length)).isEmpty()) { + throw new RuntimeException("There are too much plant ID values!"); + } + if (SOIL_ID.getValue(Integer.toString(FlowerPotBlock.soils.length)).isEmpty()) { + throw new RuntimeException("There are too much soil ID values!"); } } @@ -96,13 +104,45 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP return InteractionResult.CONSUME; } ItemStack itemStack = player.getItemInHand(hand); + int soilID = state.getValue(SOIL_ID); + if (soilID == 0) { + if (!(itemStack.getItem() instanceof BlockItem)) { + return InteractionResult.PASS; + } + Block block = ((BlockItem) itemStack.getItem()).getBlock(); + for (int i = 0; i < soils.length; i++) { + if (block == soils[i]) { + BlocksHelper.setWithUpdate(level, pos, state.setValue(SOIL_ID, i + 1)); + return InteractionResult.SUCCESS; + } + } + return InteractionResult.PASS; + } + + int plantID = state.getValue(PLANT_ID); + if (itemStack.isEmpty()) { + if (plantID > 0 && plantID <= plants.length) { + BlocksHelper.setWithUpdate(level, pos, state.setValue(PLANT_ID, 0)); + player.addItem(new ItemStack(plants[plantID - 1])); + return InteractionResult.SUCCESS; + } + if (soilID > 0 && soilID <= soils.length) { + BlocksHelper.setWithUpdate(level, pos, state.setValue(SOIL_ID, 0)); + player.addItem(new ItemStack(soils[soilID - 1])); + } + return InteractionResult.PASS; + } if (!(itemStack.getItem() instanceof BlockItem)) { return InteractionResult.PASS; } BlockItem item = (BlockItem) itemStack.getItem(); - for (int i = 0; i < blocks.length; i++) { - if (item.getBlock() == blocks[i]) { + for (int i = 0; i < plants.length; i++) { + if (item.getBlock() == plants[i]) { + if (!((PottablePlant) plants[i]).canPlantOn(soils[soilID - 1])) { + return InteractionResult.PASS; + } BlocksHelper.setWithUpdate(level, pos, state.setValue(PLANT_ID, i + 1)); + level.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1, 1, false); return InteractionResult.SUCCESS; } } @@ -127,10 +167,11 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP MultiPartBuilder model = MultiPartBuilder.create(stateDefinition); model.part(new ModelResourceLocation(stateId.getNamespace(), stateId.getPath(), "inventory")).add(); - Transformation offset = new Transformation(new Vector3f(0, 0.5F, 0), null, null, null); - for (int i = 0; i < blocks.length; i++) { + Transformation offset = new Transformation(new Vector3f(0, 7.5F / 16F, 0), null, null, null); + + for (int i = 0; i < plants.length; i++) { final int compareID = i + 1; - ResourceLocation modelPath = Registry.BLOCK.getKey(blocks[i]); + ResourceLocation modelPath = Registry.BLOCK.getKey(plants[i]); ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath() + ".json"); if (Minecraft.getInstance().getResourceManager().hasResource(objSource)) { objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath()); @@ -152,6 +193,21 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP } } + for (int i = 0; i < soils.length; i++) { + ResourceLocation soilLoc = BetterEnd.makeID("flower_pot_soil_" + i); + if (!modelCache.containsKey(soilLoc)) { + String texture = Registry.BLOCK.getKey(soils[i]).getPath() + "_top"; + if (texture.contains("rutiscus")) { + texture += "_1"; + } + Optional pattern = Patterns.createJson(Patterns.BLOCK_FLOWER_POT_SOIL, texture); + UnbakedModel soil = ModelsHelper.fromPattern(pattern); + modelCache.put(soilLoc, soil); + } + final int compareID = i + 1; + model.part(soilLoc).setCondition(state -> state.getValue(SOIL_ID) == compareID).add(); + } + UnbakedModel result = model.build(); modelCache.put(key, result); return result; @@ -160,16 +216,21 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { int id = state.getValue(PLANT_ID); - return id > 0 && id <= blocks.length ? plantBoxes[id - 1] : SHAPE; + return id > 0 && id <= plants.length ? SHAPE_FULL : SHAPE_EMPTY; } @Override public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { - return SHAPE; + return SHAPE_EMPTY; } @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } -} + + static { + SHAPE_EMPTY = Shapes.or(Block.box(4, 1, 4, 12, 8, 12), Block.box(5, 0, 5, 11, 1, 11)); + SHAPE_FULL = Shapes.or(SHAPE_EMPTY, Block.box(3, 8, 3, 13, 16, 13)); + } +} \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java index 7346d031..d0501e30 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java @@ -1,12 +1,12 @@ package ru.betterend.blocks.basis; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import ru.bclib.api.TagAPI; import ru.bclib.blocks.BasePlantBlock; import ru.betterend.interfaces.PottablePlant; public class EndPlantBlock extends BasePlantBlock implements PottablePlant { - public EndPlantBlock() { this(false); } @@ -31,4 +31,9 @@ public class EndPlantBlock extends BasePlantBlock implements PottablePlant { protected boolean isTerrain(BlockState state) { return state.is(TagAPI.END_GROUND); } + + @Override + public boolean canPlantOn(Block block) { + return isTerrain(block.defaultBlockState()); + } } diff --git a/src/main/java/ru/betterend/client/models/Patterns.java b/src/main/java/ru/betterend/client/models/Patterns.java index b0fd6330..36e49e9c 100644 --- a/src/main/java/ru/betterend/client/models/Patterns.java +++ b/src/main/java/ru/betterend/client/models/Patterns.java @@ -75,6 +75,7 @@ public class Patterns { public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json"); 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"); //Item Models public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); diff --git a/src/main/java/ru/betterend/interfaces/PottablePlant.java b/src/main/java/ru/betterend/interfaces/PottablePlant.java index 111b36a4..7bc45e51 100644 --- a/src/main/java/ru/betterend/interfaces/PottablePlant.java +++ b/src/main/java/ru/betterend/interfaces/PottablePlant.java @@ -1,3 +1,7 @@ package ru.betterend.interfaces; -public interface PottablePlant {} +import net.minecraft.world.level.block.Block; + +public interface PottablePlant { + boolean canPlantOn(Block block); +} diff --git a/src/main/resources/assets/betterend/patterns/block/flower_pot.json b/src/main/resources/assets/betterend/patterns/block/flower_pot.json index e0bd0ed8..55088bf3 100644 --- a/src/main/resources/assets/betterend/patterns/block/flower_pot.json +++ b/src/main/resources/assets/betterend/patterns/block/flower_pot.json @@ -11,7 +11,7 @@ "from": [ 4, 7, 4 ], "to": [ 12, 8, 12 ], "faces": { - "down": { "uv": [ 4, 4, 12, 12 ], "texture": "#texture" }, + "down": { "uv": [ 8, 0, 16, 8 ], "texture": "#texture" }, "up": { "uv": [ 8, 0, 16, 8 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" }, @@ -25,6 +25,7 @@ "to": [ 11, 1, 11 ], "faces": { "down": { "uv": [ 9, 9, 15, 15 ], "texture": "#texture", "cullface": "down" }, + "up": { "uv": [ 9, 9, 15, 15 ], "texture": "#texture" }, "north": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, "south": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, "west": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, @@ -49,10 +50,21 @@ "from": [ 4.5, 6, 4.5 ], "to": [ 11.5, 7, 11.5 ], "faces": { - "north": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" }, - "south": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" }, - "west": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" }, - "east": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" } + "north": { "uv": [ 0.5, 1, 7.5, 2 ], "texture": "#texture" }, + "south": { "uv": [ 0.5, 1, 7.5, 2 ], "texture": "#texture" }, + "west": { "uv": [ 0.5, 1, 7.5, 2 ], "texture": "#texture" }, + "east": { "uv": [ 0.5, 1, 7.5, 2 ], "texture": "#texture" } + } + }, + { + "__comment": "Box14", + "from": [ 11, 8, 11 ], + "to": [ 5, 1, 5 ], + "faces": { + "north": { "uv": [ 1, 0, 7, 7 ], "texture": "#texture" }, + "south": { "uv": [ 1, 0, 7, 7 ], "texture": "#texture" }, + "west": { "uv": [ 1, 0, 7, 7 ], "texture": "#texture" }, + "east": { "uv": [ 1, 0, 7, 7 ], "texture": "#texture" } } } ] diff --git a/src/main/resources/assets/betterend/patterns/block/flower_pot_soil.json b/src/main/resources/assets/betterend/patterns/block/flower_pot_soil.json new file mode 100644 index 00000000..224858f1 --- /dev/null +++ b/src/main/resources/assets/betterend/patterns/block/flower_pot_soil.json @@ -0,0 +1,17 @@ +{ + "__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio", + "textures": { + "particle": "betterend:block/%texture%", + "texture": "betterend:block/%texture%" + }, + "elements": [ + { + "__comment": "PlaneY1", + "from": [ 5, 7.5, 5 ], + "to": [ 11, 7.501, 11 ], + "faces": { + "up": { "uv": [ 5, 5, 11, 11 ], "texture": "#texture" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/betterend/textures/block/azure_jadestone_flower_pot.png b/src/main/resources/assets/betterend/textures/block/azure_jadestone_flower_pot.png index e638b6dd..d47ecc24 100644 Binary files a/src/main/resources/assets/betterend/textures/block/azure_jadestone_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/azure_jadestone_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/endstone_flower_pot.png b/src/main/resources/assets/betterend/textures/block/endstone_flower_pot.png index 1c7365c4..d6d63dc5 100644 Binary files a/src/main/resources/assets/betterend/textures/block/endstone_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/endstone_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/flavolite_flower_pot.png b/src/main/resources/assets/betterend/textures/block/flavolite_flower_pot.png index 03e238c8..e8b2cfd9 100644 Binary files a/src/main/resources/assets/betterend/textures/block/flavolite_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/flavolite_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/sandy_jadestone_flower_pot.png b/src/main/resources/assets/betterend/textures/block/sandy_jadestone_flower_pot.png index 14b18458..1ed5f5af 100644 Binary files a/src/main/resources/assets/betterend/textures/block/sandy_jadestone_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/sandy_jadestone_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/sulphuric_rock_flower_pot.png b/src/main/resources/assets/betterend/textures/block/sulphuric_rock_flower_pot.png index 1beac410..93eb5e25 100644 Binary files a/src/main/resources/assets/betterend/textures/block/sulphuric_rock_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/sulphuric_rock_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/violecite_flower_pot.png b/src/main/resources/assets/betterend/textures/block/violecite_flower_pot.png index cf32f4f6..1f788065 100644 Binary files a/src/main/resources/assets/betterend/textures/block/violecite_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/violecite_flower_pot.png differ diff --git a/src/main/resources/assets/betterend/textures/block/virid_jadestone_flower_pot.png b/src/main/resources/assets/betterend/textures/block/virid_jadestone_flower_pot.png index 7e088685..4b633a7a 100644 Binary files a/src/main/resources/assets/betterend/textures/block/virid_jadestone_flower_pot.png and b/src/main/resources/assets/betterend/textures/block/virid_jadestone_flower_pot.png differ