diff --git a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java index c47fadf6..584af092 100644 --- a/src/main/java/ru/betterend/blocks/FlowerPotBlock.java +++ b/src/main/java/ru/betterend/blocks/FlowerPotBlock.java @@ -3,66 +3,63 @@ package ru.betterend.blocks; import com.google.common.collect.Lists; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; import com.mojang.math.Transformation; 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.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.model.MultiVariant; -import net.minecraft.client.renderer.block.model.Variant; +import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.ModelResourceLocation; 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.server.packs.resources.Resource; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +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.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import org.jetbrains.annotations.Nullable; import ru.bclib.blocks.BaseBlockNotFull; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; +import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; +import ru.bclib.interfaces.IPostInit; import ru.bclib.interfaces.IRenderTyped; +import ru.bclib.interfaces.ISpetialItem; +import ru.bclib.util.BlocksHelper; import ru.bclib.util.JsonFactory; -import ru.bclib.util.MHelper; -import ru.betterend.BetterEnd; +import ru.betterend.client.models.Patterns; import ru.betterend.interfaces.PottablePlant; import ru.betterend.registry.EndBlocks; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.List; import java.util.Map; +import java.util.Optional; -public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped { - private static final VoxelShape SHAPE = Block.box(4, 4, 4, 12, 12, 12); +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 final ResourceLocation[] blocks; + private static VoxelShape[] plantBoxes; + private static Block[] blocks; @Environment(EnvType.CLIENT) private UnbakedModel source; public FlowerPotBlock(Block source) { super(FabricBlockSettings.copyOf(source)); - List blocks = Lists.newArrayList(); - EndBlocks.getModBlocks().forEach(block -> { - if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) { - blocks.add(Registry.BLOCK.getKey(block)); - } - }); - this.blocks = blocks.toArray(new ResourceLocation[] {}); + this.registerDefaultState(this.defaultBlockState().setValue(PLANT_ID, 0)); } @Override @@ -71,6 +68,54 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped { builder.add(PLANT_ID); } + @Override + public void postInit() { + if (this.blocks != null) { + return; + } + List blocks = Lists.newArrayList(); + EndBlocks.getModBlocks().forEach(block -> { + if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) { + if (!(block instanceof ISpetialItem) || !((ISpetialItem) block).canPlaceOnWater()) { + blocks.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)); + } + } + + @Override + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (level.isClientSide) { + return InteractionResult.CONSUME; + } + ItemStack itemStack = player.getItemInHand(hand); + 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]) { + BlocksHelper.setWithUpdate(level, pos, state.setValue(PLANT_ID, i + 1)); + return InteractionResult.SUCCESS; + } + } + return InteractionResult.PASS; + } + + @Override + @Environment(EnvType.CLIENT) + public BlockModel getItemModel(ResourceLocation blockId) { + Optional pattern = PatternsHelper.createJson(Patterns.BLOCK_FLOWER_POT, blockId); + return ModelsHelper.fromPattern(pattern); + } + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { @@ -81,11 +126,11 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped { } MultiPartBuilder model = MultiPartBuilder.create(stateDefinition); - model.part(new ResourceLocation("block/flower_pot")).add(); + 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++) { final int compareID = i + 1; - ResourceLocation modelPath = blocks[i]; + ResourceLocation modelPath = Registry.BLOCK.getKey(blocks[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()); @@ -114,7 +159,8 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped { @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { - return SHAPE; + int id = state.getValue(PLANT_ID); + return id > 0 && id <= blocks.length ? plantBoxes[id - 1] : SHAPE; } @Override diff --git a/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java b/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java index 125c391e..3eaca93f 100644 --- a/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java @@ -19,6 +19,7 @@ import ru.bclib.recipes.GridRecipe; import ru.bclib.util.TagHelper; import ru.betterend.BetterEnd; import ru.betterend.blocks.EndPedestal; +import ru.betterend.blocks.FlowerPotBlock; import ru.betterend.blocks.basis.StoneLanternBlock; import ru.betterend.config.Configs; import ru.betterend.recipe.CraftingRecipes; @@ -44,6 +45,7 @@ public class StoneMaterial { public final Block brick_slab; public final Block brick_wall; public final Block furnace; + public final Block flowerPot; public StoneMaterial(String name, MaterialColor color) { FabricBlockSettings material = FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color); @@ -65,6 +67,7 @@ public class StoneMaterial { brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new BaseSlabBlock(bricks)); brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks)); furnace = EndBlocks.registerBlock(name + "_furnace", new BaseFurnaceBlock(bricks)); + flowerPot = EndBlocks.registerBlock(name + "_flower_pot", new FlowerPotBlock(bricks)); // Recipes // GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks", bricks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("##", "##").addMaterial('#', stone).setGroup("end_bricks").build(); diff --git a/src/main/java/ru/betterend/client/models/Patterns.java b/src/main/java/ru/betterend/client/models/Patterns.java index fb7f4977..b0fd6330 100644 --- a/src/main/java/ru/betterend/client/models/Patterns.java +++ b/src/main/java/ru/betterend/client/models/Patterns.java @@ -74,6 +74,7 @@ public class Patterns { public final static ResourceLocation BLOCK_FURNACE_LIT = BetterEnd.makeID("patterns/block/furnace_glow.json"); 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"); //Item Models public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); diff --git a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java index 6c2736f4..99221b68 100644 --- a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java +++ b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java @@ -1,6 +1,7 @@ package ru.betterend.mixin.client; import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.resources.sounds.AbstractSoundInstance; import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.sounds.MusicManager; @@ -13,7 +14,9 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.api.BiomeAPI; import ru.betterend.client.ClientOptions; +import ru.betterend.world.biome.EndBiome; import java.util.Random; @@ -41,7 +44,7 @@ public abstract class MusicTrackerMixin { public void be_onTick(CallbackInfo info) { if (ClientOptions.blendBiomeMusic()) { Music musicSound = minecraft.getSituationalMusic(); - if (be_checkNullSound(musicSound) && volume > 0 && be_isInEnd() && be_shouldChangeSound(musicSound)) { + if (be_checkNullSound(musicSound) && volume > 0 && be_shouldChangeSound(musicSound) && be_isCorrectBiome()) { if (volume > 0) { if (srcVolume < 0) { srcVolume = currentMusic.getVolume(); @@ -80,8 +83,11 @@ public abstract class MusicTrackerMixin { } } - private boolean be_isInEnd() { - return minecraft.level != null && minecraft.level.dimension().equals(Level.END); + private boolean be_isCorrectBiome() { + if (minecraft.level == null) { + return false; + } + return BiomeAPI.getRenderBiome(minecraft.level.getBiome(minecraft.player.blockPosition())) instanceof EndBiome; } private boolean be_shouldChangeSound(Music musicSound) { diff --git a/src/main/java/ru/betterend/registry/EndBlocks.java b/src/main/java/ru/betterend/registry/EndBlocks.java index e5f852da..014f20e5 100644 --- a/src/main/java/ru/betterend/registry/EndBlocks.java +++ b/src/main/java/ru/betterend/registry/EndBlocks.java @@ -191,6 +191,7 @@ public class EndBlocks extends BlocksRegistry { public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock()); public static final Block SULPHUR_CRYSTAL = registerBlock("sulphur_crystal", new SulphurCrystalBlock()); public static final Block MISSING_TILE = registerBlock("missing_tile", new MissingTileBlock()); + public static final Block ENDSTONE_FLOWER_POT = registerBlock("endstone_flower_pot", new FlowerPotBlock(Blocks.END_STONE)); public static final Block FLAVOLITE_RUNED = registerBlock("flavolite_runed", new RunedFlavolite(false)); public static final Block FLAVOLITE_RUNED_ETERNAL = registerBlock("flavolite_runed_eternal", new RunedFlavolite(true)); @@ -424,7 +425,6 @@ public class EndBlocks extends BlocksRegistry { public static final Block AETERNIUM_ANVIL = registerBlock("aeternium_anvil", new AeterniumAnvil()); // Technical - public static final Block ENDSTONE_FLOWER_POT = registerBlock("endstone_flower_pot", new FlowerPotBlock(Blocks.END_STONE)); public static final Block END_PORTAL_BLOCK = registerEndBlockOnly("end_portal_block", new EndPortalBlock()); private static BlocksRegistry BLOCKS_REGISTRY; diff --git a/src/main/resources/assets/betterend/patterns/block/flower_pot.json b/src/main/resources/assets/betterend/patterns/block/flower_pot.json new file mode 100644 index 00000000..e0bd0ed8 --- /dev/null +++ b/src/main/resources/assets/betterend/patterns/block/flower_pot.json @@ -0,0 +1,59 @@ +{ + "__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio", + "parent": "block/block", + "textures": { + "particle": "betterend:block/%texture%", + "texture": "betterend:block/%texture%" + }, + "elements": [ + { + "__comment": "Box1", + "from": [ 4, 7, 4 ], + "to": [ 12, 8, 12 ], + "faces": { + "down": { "uv": [ 4, 4, 12, 12 ], "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" }, + "west": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" }, + "east": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" } + } + }, + { + "__comment": "Box1", + "from": [ 5, 0, 5 ], + "to": [ 11, 1, 11 ], + "faces": { + "down": { "uv": [ 9, 9, 15, 15 ], "texture": "#texture", "cullface": "down" }, + "north": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, + "south": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, + "west": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }, + "east": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" } + } + }, + { + "__comment": "Box1", + "from": [ 4, 1, 4 ], + "to": [ 12, 6, 12 ], + "faces": { + "down": { "uv": [ 8, 8, 16, 16 ], "texture": "#texture" }, + "up": { "uv": [ 8, 0, 16, 8 ], "texture": "#texture" }, + "north": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" }, + "south": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" }, + "west": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" }, + "east": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" } + } + }, + { + "__comment": "Box1", + "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" } + } + } + ] +} \ 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 new file mode 100644 index 00000000..e638b6dd Binary files /dev/null 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 new file mode 100644 index 00000000..1c7365c4 Binary files /dev/null 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 new file mode 100644 index 00000000..03e238c8 Binary files /dev/null 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 new file mode 100644 index 00000000..14b18458 Binary files /dev/null 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 new file mode 100644 index 00000000..1beac410 Binary files /dev/null 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 new file mode 100644 index 00000000..cf32f4f6 Binary files /dev/null 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 new file mode 100644 index 00000000..7e088685 Binary files /dev/null and b/src/main/resources/assets/betterend/textures/block/virid_jadestone_flower_pot.png differ