From c21683de9c4795bbc7d8f94f421a75a3d6d24fa2 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 25 Mar 2025 17:05:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(fabric):=20=E4=BC=98=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E5=9D=97=E6=B3=A8=E5=86=8C=E5=92=8C=E6=B8=B2=E6=9F=93=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/network/BukkitNetworkManager.java | 1 - .../client/CraftEngineFabricModClient.java | 7 ++-- .../fabric/client/blocks/CustomBlock.java | 35 +++++++++++++++++++ .../fabric/CraftEngineFabricMod.java | 3 +- .../craftengine/fabric/util/BlockUtils.java | 11 +++++- .../fabric/util/RegisterBlocks.java | 29 ++------------- 6 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 client-mod/src/client/java/net/momirealms/craftengine/fabric/client/blocks/CustomBlock.java diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java index d7f9b23f9..1226fb980 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java @@ -26,7 +26,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRegisterChannelEvent; import org.jetbrains.annotations.NotNull; diff --git a/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/CraftEngineFabricModClient.java b/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/CraftEngineFabricModClient.java index db505bfef..f0ab3bcf0 100644 --- a/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/CraftEngineFabricModClient.java +++ b/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/CraftEngineFabricModClient.java @@ -17,6 +17,7 @@ import net.minecraft.registry.Registries; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.world.biome.FoliageColors; +import net.momirealms.craftengine.fabric.client.blocks.CustomBlock; import net.momirealms.craftengine.fabric.client.config.ModConfig; import net.momirealms.craftengine.fabric.client.network.CraftEnginePayload; @@ -38,8 +39,10 @@ public class CraftEngineFabricModClient implements ClientModInitializer { public static void registerRenderLayer() { Registries.BLOCK.forEach(block -> { Identifier id = Registries.BLOCK.getId(block); - if (id.getNamespace().equals(CraftEngineFabricModClient.MOD_ID)) { - BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getCutoutMipped()); + if (block instanceof CustomBlock customBlock) { + if (customBlock.isTransparent()) { + BlockRenderLayerMap.INSTANCE.putBlock(customBlock, RenderLayer.getCutoutMipped()); + } if (id.getPath().contains("leaves")) { registerColor(block); } diff --git a/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/blocks/CustomBlock.java b/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/blocks/CustomBlock.java new file mode 100644 index 000000000..c53045cdf --- /dev/null +++ b/client-mod/src/client/java/net/momirealms/craftengine/fabric/client/blocks/CustomBlock.java @@ -0,0 +1,35 @@ +package net.momirealms.craftengine.fabric.client.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; + +public class CustomBlock extends Block { + private final VoxelShape outlineShape; + private final VoxelShape collisionShape; + private final boolean isTransparent; + + public CustomBlock(Settings settings, VoxelShape outlineShape, VoxelShape collisionShape, boolean isTransparent) { + super(settings); + this.outlineShape = outlineShape; + this.collisionShape = collisionShape; + this.isTransparent = isTransparent; + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return this.outlineShape; + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return this.collisionShape; + } + + public boolean isTransparent() { + return this.isTransparent; + } +} diff --git a/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java b/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java index c83839921..e8ab5ecf7 100644 --- a/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java +++ b/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java @@ -40,7 +40,8 @@ public class CraftEngineFabricMod implements ModInitializer { RegisterBlocks.register( replacedBlockId.getPath() + "_" + i, BlockUtils.canPassThrough(blockState), - BlockUtils.getShape(blockState) + BlockUtils.getShape(blockState), + BlockUtils.isTransparent(blockState) ); } } diff --git a/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/BlockUtils.java b/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/BlockUtils.java index 70b6ee011..df3e500fb 100644 --- a/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/BlockUtils.java +++ b/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/BlockUtils.java @@ -3,10 +3,10 @@ package net.momirealms.craftengine.fabric.util; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.TransparentBlock; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,4 +64,13 @@ public class BlockUtils { return VoxelShapes.fullCube(); } } + + public static boolean isTransparent(BlockState state) { + if (state == null) return true; + Block block = state.getBlock(); + if (block instanceof TransparentBlock) { + return true; + } + return !state.isOpaque(); + } } diff --git a/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/RegisterBlocks.java b/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/RegisterBlocks.java index 33234b3aa..4cd2b959b 100644 --- a/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/RegisterBlocks.java +++ b/client-mod/src/main/java/net/momirealms/craftengine/fabric/util/RegisterBlocks.java @@ -2,24 +2,21 @@ package net.momirealms.craftengine.fabric.util; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ShapeContext; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; import net.momirealms.craftengine.fabric.CraftEngineFabricMod; +import net.momirealms.craftengine.fabric.client.blocks.CustomBlock; import java.util.function.Function; public class RegisterBlocks { @SuppressWarnings("UnusedReturnValue") - public static Block register(String name, boolean canPassThrough, VoxelShape outlineShape) { + public static Block register(String name, boolean canPassThrough, VoxelShape outlineShape, boolean isTransparent) { AbstractBlock.Settings settings = Block.Settings.create().nonOpaque().strength(-1.0F, 3600000.0F); VoxelShape collisionShape; if (canPassThrough) { @@ -28,7 +25,7 @@ public class RegisterBlocks { } else { collisionShape = outlineShape; } - return register(name, (settingsParam) -> new CustomBlock(settingsParam, outlineShape, collisionShape), settings); + return register(name, (settingsParam) -> new CustomBlock(settingsParam, outlineShape, collisionShape, isTransparent), settings); } public static Block register(String name, Function blockFactory, AbstractBlock.Settings settings) { @@ -44,23 +41,3 @@ public class RegisterBlocks { } -class CustomBlock extends Block { - private final VoxelShape outlineShape; - private final VoxelShape collisionShape; - - public CustomBlock(Settings settings, VoxelShape outlineShape, VoxelShape collisionShape) { - super(settings); - this.outlineShape = outlineShape; - this.collisionShape = collisionShape; - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return this.outlineShape; - } - - @Override - public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return this.collisionShape; - } -}