diff --git a/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java b/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java index cee7c8d..134d20e 100644 --- a/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java +++ b/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java @@ -3,6 +3,7 @@ import dev.micalobia.full_slabs.block.Blocks; import dev.micalobia.full_slabs.block.VerticalSlabBlock; import dev.micalobia.full_slabs.client.render.model.SlabModelProvider; +import dev.micalobia.full_slabs.event.Events; import dev.micalobia.full_slabs.util.LinkedSlabs; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; @@ -38,7 +39,6 @@ public void onInitializeClient() { RegistryEntryAddedCallback.event(Registry.BLOCK).register(FullSlabsClient::syncRenderLayer); BlockRenderLayerMap map = BlockRenderLayerMap.INSTANCE; map.putBlock(Blocks.FULL_SLAB_BLOCK, RenderLayer.getTranslucent()); + Events.client_init(); } - - } diff --git a/src/main/java/dev/micalobia/full_slabs/event/Events.java b/src/main/java/dev/micalobia/full_slabs/event/Events.java index c486156..e8dba14 100644 --- a/src/main/java/dev/micalobia/full_slabs/event/Events.java +++ b/src/main/java/dev/micalobia/full_slabs/event/Events.java @@ -13,6 +13,8 @@ import dev.micalobia.micalibria.event.enums.PairedEventReaction; import dev.micalobia.micalibria.event.enums.TypedEventReaction; import dev.micalobia.micalibria.server.network.ServerPlayerEntityUtil; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -45,21 +47,6 @@ public class Events { private static Pair ghostPair; - static { - SpawnSprintingParticlesEvent.EVENT.register(Events::spawnSlabSprintingParticles); - HitGroundParticlesEvent.EVENT.register(Events::spawnHitGroundParticles); - ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakFullSlab); - ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakHorizontalSlab); - ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakVerticalSlab); - ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakFullSlab); - ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakHorizontalSlab); - ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakVerticalSlab); - BlockBreakingParticleEvent.EVENT.register(Events::slabBreakingParticles); - RenderDamageEvent.EVENT.register(Events::renderSlabDamage); - PlaceBlockItemEvent.EVENT.register(Events::placeFullSlab); - SetBlockStateEvent.EVENT.register(Events::setFullSlab); - } - private static PairedEventReaction> setFullSlab(World world, BlockPos pos, BlockState state, BlockEntity entity, boolean moved) { if(!state.isOf(Blocks.FULL_SLAB_BLOCK) || moved || entity != null) return PairedEventReaction.ignore(); entity = new FullSlabBlockEntity(ghostPair.getFirst(), ghostPair.getSecond()); @@ -82,6 +69,7 @@ private static TypedEventReaction placeFullSlab(ItemPlacementContext return TypedEventReaction.complete(state); } + @Environment(EnvType.CLIENT) private static TypedEventReaction renderSlabDamage(BlockState state, BlockPos pos, BlockRenderView view, MatrixStack matrix, VertexConsumer consumer) { if(!(Helper.isAnySlab(state.getBlock()) && Helper.isDoubleSlab(state))) return TypedEventReaction.ignore(); Vec3d hit = MinecraftClient.getInstance().crosshairTarget.getPos(); @@ -98,6 +86,7 @@ private static TypedEventReaction renderSlabDamage(BlockState state, return TypedEventReaction.complete(ret); } + @Environment(EnvType.CLIENT) private static TypedEventReaction slabBreakingParticles(BlockState state, BlockPos pos, ClientWorld world, Direction direction, Random random) { if(!state.isOf(Blocks.FULL_SLAB_BLOCK)) return TypedEventReaction.ignore(); FullSlabBlockEntity entity = (FullSlabBlockEntity) world.getBlockEntity(pos); @@ -107,7 +96,8 @@ private static TypedEventReaction slabBreakingParticles(BlockState s return TypedEventReaction.complete(entity.getHitState(axis, hit)); } - private static EventReaction breakVerticalSlab(MinecraftClient client, BlockPos pos) { + @Environment(EnvType.CLIENT) + public static EventReaction breakVerticalSlab(MinecraftClient client, BlockPos pos) { BlockState state = client.world.getBlockState(pos); Block block = state.getBlock(); if(!(block instanceof VerticalSlabBlock)) return EventReaction.IGNORE; @@ -121,7 +111,8 @@ private static EventReaction breakVerticalSlab(MinecraftClient client, BlockPos return ret ? EventReaction.COMPLETE : EventReaction.CANCEL; // TODO: Replace with EventReaction.terminate(bool) } - private static EventReaction breakHorizontalSlab(MinecraftClient client, BlockPos pos) { + @Environment(EnvType.CLIENT) + public static EventReaction breakHorizontalSlab(MinecraftClient client, BlockPos pos) { BlockState state = client.world.getBlockState(pos); if(!(state.getBlock() instanceof SlabBlock)) return EventReaction.IGNORE; if(state.get(SlabBlock.TYPE) != SlabType.DOUBLE) return EventReaction.IGNORE; @@ -133,7 +124,8 @@ private static EventReaction breakHorizontalSlab(MinecraftClient client, BlockPo return ret ? EventReaction.COMPLETE : EventReaction.CANCEL; // TODO: Replace with EventReaction.terminate(bool) } - private static EventReaction breakFullSlab(MinecraftClient client, BlockPos pos) { + @Environment(EnvType.CLIENT) + public static EventReaction breakFullSlab(MinecraftClient client, BlockPos pos) { ClientWorld world = client.world; BlockState state = world.getBlockState(pos); if(!state.isOf(Blocks.FULL_SLAB_BLOCK)) return EventReaction.IGNORE; @@ -215,6 +207,7 @@ private static void breakSlab(BlockState brokenState, BlockState leftoverState, } } + @Environment(EnvType.CLIENT) private static boolean breakSlab(BlockState brokenState, BlockState leftoverState, BlockPos pos, MinecraftClient client) { Block broken = brokenState.getBlock(); broken.onBreak(client.world, pos, brokenState, client.player); @@ -224,6 +217,22 @@ private static boolean breakSlab(BlockState brokenState, BlockState leftoverStat } public static void init() { + SpawnSprintingParticlesEvent.EVENT.register(Events::spawnSlabSprintingParticles); + ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakFullSlab); + ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakHorizontalSlab); + ServerPlayerBrokeBlockEvent.EVENT.register(Events::tryBreakVerticalSlab); + PlaceBlockItemEvent.EVENT.register(Events::placeFullSlab); + SetBlockStateEvent.EVENT.register(Events::setFullSlab); + HitGroundParticlesEvent.EVENT.register(Events::spawnHitGroundParticles); + } + + @Environment(EnvType.CLIENT) + public static void client_init() { + ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakFullSlab); + ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakHorizontalSlab); + ClientPlayerBrokeBlockEvent.EVENT.register(Events::breakVerticalSlab); + RenderDamageEvent.EVENT.register(Events::renderSlabDamage); + BlockBreakingParticleEvent.EVENT.register(Events::slabBreakingParticles); } private static TypedEventReaction spawnHitGroundParticles(BlockState blockState, LivingEntity entity) {