diff --git a/src/main/java/net/frozenblock/wilderwild/WilderWild.java b/src/main/java/net/frozenblock/wilderwild/WilderWild.java index 3de6256f54..52dab3c906 100644 --- a/src/main/java/net/frozenblock/wilderwild/WilderWild.java +++ b/src/main/java/net/frozenblock/wilderwild/WilderWild.java @@ -55,19 +55,10 @@ import net.frozenblock.wilderwild.registry.RegisterWorldgen; import net.frozenblock.wilderwild.registry.WilderRegistry; import net.frozenblock.wilderwild.world.additions.gen.WilderWorldGen; -import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; public final class WilderWild extends FrozenModInitializer implements FrozenMobCategoryEntrypoint { - // PACKETS - public static final ResourceLocation SEED_PACKET = WilderSharedConstants.id("seed_particle_packet"); - public static final ResourceLocation CONTROLLED_SEED_PACKET = WilderSharedConstants.id("controlled_seed_particle_packet"); - public static final ResourceLocation FLOATING_SCULK_BUBBLE_PACKET = WilderSharedConstants.id("floating_sculk_bubble_easy_packet"); - public static final ResourceLocation TERMITE_PARTICLE_PACKET = WilderSharedConstants.id("termite_particle_packet"); - public static final ResourceLocation SENSOR_HICCUP_PACKET = WilderSharedConstants.id("sensor_hiccup_packet"); - public static final ResourceLocation JELLY_STING_PACKET = WilderSharedConstants.id("jelly_sting_packet"); - public WilderWild() { super(WilderSharedConstants.MOD_ID); } diff --git a/src/main/java/net/frozenblock/wilderwild/WilderWildClient.java b/src/main/java/net/frozenblock/wilderwild/WilderWildClient.java index b2353a1291..dcb8d64dd2 100644 --- a/src/main/java/net/frozenblock/wilderwild/WilderWildClient.java +++ b/src/main/java/net/frozenblock/wilderwild/WilderWildClient.java @@ -19,12 +19,10 @@ package net.frozenblock.wilderwild; import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; @@ -32,7 +30,6 @@ import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; import net.frozenblock.lib.item.api.ItemBlockStateTagUtils; -import net.frozenblock.lib.math.api.AdvancedMath; import net.frozenblock.lib.menu.api.Panoramas; import net.frozenblock.lib.menu.api.SplashTextAPI; import net.frozenblock.lib.sound.api.FlyBySoundHub; @@ -52,14 +49,13 @@ import net.frozenblock.wilderwild.entity.render.renderer.TumbleweedRenderer; import net.frozenblock.wilderwild.item.FireflyBottle; import net.frozenblock.wilderwild.misc.WilderSharedConstants; +import net.frozenblock.wilderwild.networking.client.WilderClientNetworking; import net.frozenblock.wilderwild.particle.FallingParticle; import net.frozenblock.wilderwild.particle.FloatingSculkBubbleParticle; import net.frozenblock.wilderwild.particle.MesogleaDripParticle; import net.frozenblock.wilderwild.particle.PollenParticle; import net.frozenblock.wilderwild.particle.SeedParticle; import net.frozenblock.wilderwild.particle.TermiteParticle; -import net.frozenblock.wilderwild.particle.options.FloatingSculkBubbleParticleOptions; -import net.frozenblock.wilderwild.particle.options.SeedParticleOptions; import net.frozenblock.wilderwild.registry.RegisterBlockEntities; import net.frozenblock.wilderwild.registry.RegisterBlocks; import net.frozenblock.wilderwild.registry.RegisterEntities; @@ -68,14 +64,11 @@ import net.frozenblock.wilderwild.registry.RegisterProperties; import net.frozenblock.wilderwild.registry.RegisterSounds; import net.minecraft.client.model.geom.ModelLayerLocation; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.BiomeColors; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.client.renderer.entity.ThrownItemRenderer; import net.minecraft.client.renderer.item.ItemProperties; -import net.minecraft.core.particles.ParticleTypes; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.resources.ResourceManager; @@ -83,7 +76,6 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) @@ -99,112 +91,6 @@ public final class WilderWildClient implements ClientModInitializer { public static final ModelLayerLocation TUMBLEWEED = new ModelLayerLocation(WilderSharedConstants.id("tumbleweed"), "main"); public static final ModelLayerLocation CRAB = new ModelLayerLocation(WilderSharedConstants.id("crab"), "main"); - private static void receiveEasyEchoerBubblePacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.FLOATING_SCULK_BUBBLE_PACKET, (ctx, handler, byteBuf, responseSender) -> { - Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); - double size = byteBuf.readDouble(); - int age = byteBuf.readInt(); - double yVel = byteBuf.readDouble(); - int count = byteBuf.readVarInt(); - ctx.execute(() -> { - if (ctx.level == null) - throw new IllegalStateException("why is your world null"); - var random = AdvancedMath.random(); - for (int i = 0; i < count; i++) { - double xVel = (random.nextDouble() - 0.5) / 9.5; - double zVel = (random.nextDouble() - 0.5) / 9.5; - if (size >= 1) { - xVel = (random.nextDouble() - 0.5) / 10.5; - zVel = (random.nextDouble() - 0.5) / 10.5; - } - ctx.level.addParticle(new FloatingSculkBubbleParticleOptions(size, age, new Vec3(xVel, yVel, zVel)), pos.x, pos.y, pos.z, 0, 0, 0); - } - }); - }); - } - - private static void receiveSeedPacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.SEED_PACKET, (ctx, handler, byteBuf, responseSender) -> { - Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); - int count = byteBuf.readVarInt(); - boolean milkweed = byteBuf.readBoolean(); - ctx.execute(() -> { - if (ctx.level == null) - throw new IllegalStateException("why is your world null"); - for (int i = 0; i < count; i++) { - ctx.level.addParticle(new SeedParticleOptions(milkweed, false), pos.x, pos.y, pos.z, 0, 0, 0); - } - }); - }); - } - - private static void receiveControlledSeedPacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.CONTROLLED_SEED_PACKET, (ctx, handler, byteBuf, responseSender) -> { - Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); - double velx = byteBuf.readDouble(); - double vely = byteBuf.readDouble(); - double velz = byteBuf.readDouble(); - int count = byteBuf.readVarInt(); - boolean milkweed = byteBuf.readBoolean(); - double posRandomizer = byteBuf.readDouble(); - ctx.execute(() -> { - if (ctx.level == null) - throw new IllegalStateException("why is your world null"); - for (int i = 0; i < count; i++) { - ctx.level.addParticle(new SeedParticleOptions(milkweed, true), pos.x, pos.y + ((ctx.level.random.nextBoolean() ? -1 : 1) * (ctx.level.random.nextDouble() * posRandomizer)), pos.z, velx, vely + (ctx.level.random.nextDouble() * 0.07), velz); - } - }); - }); - } - - private static void receiveTermitePacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.TERMITE_PARTICLE_PACKET, (ctx, handler, byteBuf, responseSender) -> { - Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); - AtomicInteger count = new AtomicInteger(byteBuf.readVarInt()); - ctx.execute(() -> { - if (ctx.level == null) - throw new IllegalStateException("why is your world null"); - - count.addAndGet(-1); - ctx.level.addAlwaysVisibleParticle(RegisterParticles.TERMITE, pos.x, pos.y, pos.z, 0, 0, 0); - for (int i = 0; i < count.get(); i++) { - ctx.level.addParticle(RegisterParticles.TERMITE, pos.x, pos.y, pos.z, 0, 0, 0); - } - }); - }); - } - - private static void receiveSensorHiccupPacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.SENSOR_HICCUP_PACKET, (ctx, handler, byteBuf, responseSender) -> { - Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); - ctx.execute(() -> { - if (ctx.level == null) - throw new IllegalStateException("why is your world null"); - ClientLevel level = ctx.level; - int i = 5578058; - boolean bl2 = level.random.nextBoolean(); - if (bl2) { - double d = (double) (i >> 16 & 255) / 255.0D; - double e = (double) (i >> 8 & 255) / 255.0D; - double f = (double) (i & 255) / 255.0D; - level.addParticle(ParticleTypes.ENTITY_EFFECT, pos.x, pos.y, pos.z, d, e, f); - } - }); - }); - } - - private static void receiveJellyStingPacket() { - ClientPlayNetworking.registerGlobalReceiver(WilderWild.JELLY_STING_PACKET, (ctx, handler, byteBuf, responseSender) -> ctx.execute(() -> { - boolean baby = byteBuf.readBoolean(); - if (ctx.level != null) { - LocalPlayer player = ctx.player; - if (player != null) { - ctx.level.playSound(player, player.getX(), player.getY(), player.getZ(), RegisterSounds.ENTITY_JELLYFISH_STING, SoundSource.NEUTRAL, 1.0F, ctx.level.random.nextFloat() * 0.2F + (baby ? 1.2F : 0.9F)); - } - } - })); - } - @Override public void onInitializeClient() { SplashTextAPI.addSplashLocation(WilderSharedConstants.id("texts/splashes.txt")); @@ -359,12 +245,7 @@ public void onInitializeClient() { EntityModelLayerRegistry.registerModelLayer(DOUBLE_STONE_CHEST_LEFT, StoneChestBlockEntityRenderer::createDoubleBodyLeftLayer); EntityModelLayerRegistry.registerModelLayer(DOUBLE_STONE_CHEST_RIGHT, StoneChestBlockEntityRenderer::createDoubleBodyRightLayer); - receiveEasyEchoerBubblePacket(); - receiveSeedPacket(); - receiveControlledSeedPacket(); - receiveTermitePacket(); - receiveSensorHiccupPacket(); - receiveJellyStingPacket(); + WilderClientNetworking.registerPacketReceivers(); FlyBySoundHub.AUTO_ENTITIES_AND_SOUNDS.put(RegisterEntities.ANCIENT_HORN_PROJECTILE_ENTITY, new FlyBySoundHub.FlyBySound(1.0F, 0.5F, SoundSource.PLAYERS, RegisterSounds.ENTITY_ANCIENT_HORN_PROJECTILE_FLYBY)); diff --git a/src/main/java/net/frozenblock/wilderwild/block/MilkweedBlock.java b/src/main/java/net/frozenblock/wilderwild/block/MilkweedBlock.java index e53d4da7ed..f07319f5e9 100644 --- a/src/main/java/net/frozenblock/wilderwild/block/MilkweedBlock.java +++ b/src/main/java/net/frozenblock/wilderwild/block/MilkweedBlock.java @@ -18,7 +18,7 @@ package net.frozenblock.wilderwild.block; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterItems; import net.frozenblock.wilderwild.registry.RegisterSounds; import net.minecraft.core.BlockPos; @@ -85,7 +85,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level level, @N shear(level, pos, state, player); } else { level.playSound(null, player.getX(), player.getY(), player.getZ(), RegisterSounds.BLOCK_MILKWEED_RUSTLE, SoundSource.BLOCKS, 0.8F, 0.9F + (level.random.nextFloat() * 0.15F)); - EasyPacket.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), level.random.nextIntBetweenInclusive(14, 28), true); + WilderNetworking.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), level.random.nextIntBetweenInclusive(14, 28), true); setAgeOnBothHalves(this, state, level, pos, 0); } } diff --git a/src/main/java/net/frozenblock/wilderwild/block/SeedingFlowerBlock.java b/src/main/java/net/frozenblock/wilderwild/block/SeedingFlowerBlock.java index 54ec8e958c..dfd5431f90 100644 --- a/src/main/java/net/frozenblock/wilderwild/block/SeedingFlowerBlock.java +++ b/src/main/java/net/frozenblock/wilderwild/block/SeedingFlowerBlock.java @@ -18,7 +18,7 @@ package net.frozenblock.wilderwild.block; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.particle.options.SeedParticleOptions; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; @@ -49,7 +49,7 @@ public void animateTick(@NotNull BlockState state, @NotNull Level level, @NotNul public void entityInside(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull Entity entity) { if (level instanceof ServerLevel server) { if (server.random.nextFloat() > 0.95) { - EasyPacket.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), server.random.nextIntBetweenInclusive(1, 3), false); + WilderNetworking.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), server.random.nextIntBetweenInclusive(1, 3), false); } } } @@ -58,7 +58,7 @@ public void entityInside(@NotNull BlockState state, @NotNull Level level, @NotNu public void playerWillDestroy(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Player player) { super.playerWillDestroy(level, pos, state, player); if (level instanceof ServerLevel server) { - EasyPacket.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), server.random.nextIntBetweenInclusive(3, 7), false); + WilderNetworking.EasySeedPacket.createParticle(level, Vec3.atCenterOf(pos).add(0, 0.3, 0), server.random.nextIntBetweenInclusive(3, 7), false); } } } diff --git a/src/main/java/net/frozenblock/wilderwild/entity/AncientHornProjectile.java b/src/main/java/net/frozenblock/wilderwild/entity/AncientHornProjectile.java index 796d21fb03..92b8d957c2 100644 --- a/src/main/java/net/frozenblock/wilderwild/entity/AncientHornProjectile.java +++ b/src/main/java/net/frozenblock/wilderwild/entity/AncientHornProjectile.java @@ -30,7 +30,7 @@ import static net.frozenblock.wilderwild.item.AncientHorn.*; import net.frozenblock.wilderwild.misc.WilderSharedConstants; import net.frozenblock.wilderwild.misc.mod_compat.WilderModIntegrations; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterBlocks; import net.frozenblock.wilderwild.registry.RegisterDamageTypes; import net.frozenblock.wilderwild.registry.RegisterEntities; @@ -167,7 +167,7 @@ public void tick() { this.shakeTime = 0; if (this.bubbles > 0 && this.level() instanceof ServerLevel server) { --this.bubbles; - EasyPacket.EasyFloatingSculkBubblePacket.createParticle(server, this.position(), server.random.nextDouble() > 0.7 ? 1 : 0, 20 + server.random.nextInt(40), 0.05, server.random.nextIntBetweenInclusive(1, 3)); + WilderNetworking.EasyFloatingSculkBubblePacket.createParticle(server, this.position(), server.random.nextDouble() > 0.7 ? 1 : 0, 20 + server.random.nextInt(40), 0.05, server.random.nextIntBetweenInclusive(1, 3)); } if (this.aliveTicks > ItemConfig.get().ancientHorn.ancientHornLifespan) { this.remove(RemovalReason.DISCARDED); @@ -192,7 +192,7 @@ public void tick() { Vec3 deltaPosition; if (this.isInWater() && level() instanceof ServerLevel server) { - EasyPacket.EasyFloatingSculkBubblePacket.createParticle(server, new Vec3(this.xo, this.yo, this.zo), 0, 60, 0.05, 4); + WilderNetworking.EasyFloatingSculkBubblePacket.createParticle(server, new Vec3(this.xo, this.yo, this.zo), 0, 60, 0.05, 4); } if (this.isInWaterOrRain() || blockState.is(Blocks.POWDER_SNOW)) { this.clearFire(); diff --git a/src/main/java/net/frozenblock/wilderwild/entity/Jellyfish.java b/src/main/java/net/frozenblock/wilderwild/entity/Jellyfish.java index 1e2fbe3607..2afa0bdd40 100644 --- a/src/main/java/net/frozenblock/wilderwild/entity/Jellyfish.java +++ b/src/main/java/net/frozenblock/wilderwild/entity/Jellyfish.java @@ -30,7 +30,7 @@ import net.frozenblock.wilderwild.entity.ai.jellyfish.JellyfishAi; import net.frozenblock.wilderwild.entity.ai.jellyfish.JellyfishTemptGoal; import net.frozenblock.wilderwild.entity.variant.JellyfishVariant; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterEntities; import net.frozenblock.wilderwild.registry.RegisterItems; import net.frozenblock.wilderwild.registry.RegisterSounds; @@ -439,7 +439,7 @@ public void stingEntities() { if (entity instanceof ServerPlayer player) { if (player.hurt(this.damageSources().mobAttack(this), damage)) { player.addEffect(new MobEffectInstance(MobEffects.POISON, poisonDuration, 0, false, false), this); - EasyPacket.sendJellySting(player, baby); + WilderNetworking.sendJellySting(player, baby); } } else if (entity instanceof Mob mob) { if (mob.hurt(this.damageSources().mobAttack(this), damage)) { diff --git a/src/main/java/net/frozenblock/wilderwild/entity/ai/TermiteManager.java b/src/main/java/net/frozenblock/wilderwild/entity/ai/TermiteManager.java index e917a1b983..1c7ad0858b 100644 --- a/src/main/java/net/frozenblock/wilderwild/entity/ai/TermiteManager.java +++ b/src/main/java/net/frozenblock/wilderwild/entity/ai/TermiteManager.java @@ -32,7 +32,7 @@ import net.frozenblock.wilderwild.block.HollowedLogBlock; import net.frozenblock.wilderwild.config.BlockConfig; import net.frozenblock.wilderwild.misc.WilderSharedConstants; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterBlocks; import net.frozenblock.wilderwild.registry.RegisterProperties; import net.frozenblock.wilderwild.registry.RegisterSounds; @@ -114,7 +114,7 @@ public void tick(@NotNull Level level, @NotNull BlockPos pos, boolean natural, b ArrayList termitesToRemove = new ArrayList<>(); for (Termite termite : this.termites) { if (termite.tick(level, natural)) { - EasyPacket.EasyTermitePacket.createParticle(level, Vec3.atCenterOf(termite.pos), termite.eating ? 4 : 6); + WilderNetworking.EasyTermitePacket.createParticle(level, Vec3.atCenterOf(termite.pos), termite.eating ? 4 : 6); } else { level.playSound(null, termite.pos, RegisterSounds.BLOCK_TERMITE_MOUND_ENTER, SoundSource.NEUTRAL, 0.6F, 1.0F); termitesToRemove.add(termite); diff --git a/src/main/java/net/frozenblock/wilderwild/item/MilkweedPod.java b/src/main/java/net/frozenblock/wilderwild/item/MilkweedPod.java index e1715336c3..c8488d4421 100644 --- a/src/main/java/net/frozenblock/wilderwild/item/MilkweedPod.java +++ b/src/main/java/net/frozenblock/wilderwild/item/MilkweedPod.java @@ -18,7 +18,7 @@ package net.frozenblock.wilderwild.item; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; @@ -50,7 +50,7 @@ public InteractionResultHolder use(@NotNull Level level, @NotNull Pla float f = -Mth.sin(yaw * 0.017453292F) * Mth.cos(pitch * 0.017453292F); float g = -Mth.sin((pitch + roll) * 0.017453292F); float h = Mth.cos(yaw * 0.017453292F) * Mth.cos(pitch * 0.017453292F); - EasyPacket.EasySeedPacket.createControlledParticle(level, user.getEyePosition().add(0, -0.1, 0), f, g, h, server.random.nextIntBetweenInclusive(5, 20), true, 48, 0.2); + WilderNetworking.EasySeedPacket.createControlledParticle(level, user.getEyePosition().add(0, -0.1, 0), f, g, h, server.random.nextIntBetweenInclusive(5, 20), true, 48, 0.2); } return InteractionResultHolder.consume(itemStack); diff --git a/src/main/java/net/frozenblock/wilderwild/misc/mod_compat/scp/SimpleCopperPipesIntegration.java b/src/main/java/net/frozenblock/wilderwild/misc/mod_compat/scp/SimpleCopperPipesIntegration.java index 66441d238d..5303a18090 100644 --- a/src/main/java/net/frozenblock/wilderwild/misc/mod_compat/scp/SimpleCopperPipesIntegration.java +++ b/src/main/java/net/frozenblock/wilderwild/misc/mod_compat/scp/SimpleCopperPipesIntegration.java @@ -26,7 +26,7 @@ import net.frozenblock.wilderwild.entity.CoconutProjectile; import net.frozenblock.wilderwild.entity.Tumbleweed; import net.frozenblock.wilderwild.misc.WilderSharedConstants; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterBlocks; import net.frozenblock.wilderwild.registry.RegisterEntities; import net.frozenblock.wilderwild.registry.RegisterItems; @@ -121,7 +121,7 @@ public void init() { UniformInt ran2 = UniformInt.of(-1, 1); UniformInt ran3 = UniformInt.of(-3, 3); for (int o = 0; o < random.nextIntBetweenInclusive(10, 30); ++o) { - EasyPacket.EasySeedPacket.createControlledParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), velX, velY, velZ, 1, true, 64, 0.3); + WilderNetworking.EasySeedPacket.createControlledParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), velX, velY, velZ, 1, true, 64, 0.3); } }); @@ -149,7 +149,7 @@ public void init() { UniformInt ran2 = UniformInt.of(-1, 1); UniformInt ran3 = UniformInt.of(-3, 3); for (int o = 0; o < random.nextIntBetweenInclusive(1, 10); ++o) { - EasyPacket.EasySeedPacket.createControlledParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), velX, velY, velZ, 1, false, 64, 0.3); + WilderNetworking.EasySeedPacket.createControlledParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), velX, velY, velZ, 1, false, 64, 0.3); } }); @@ -173,7 +173,7 @@ public void init() { UniformInt ran2 = UniformInt.of(-1, 1); UniformInt ran3 = UniformInt.of(-3, 3); for (int o = 0; o < random.nextIntBetweenInclusive(1, 4); ++o) { - EasyPacket.EasyFloatingSculkBubblePacket.createParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), AdvancedMath.random().nextDouble() > 0.7 ? 1 : 0, random.nextIntBetweenInclusive(60, 80), velY * 0.05, 1); + WilderNetworking.EasyFloatingSculkBubblePacket.createParticle(level, new Vec3(d + (double) ran1.sample(level.random) * 0.1D, e + (double) ran2.sample(level.random) * 0.1D, f + (double) ran3.sample(level.random) * 0.1D), AdvancedMath.random().nextDouble() > 0.7 ? 1 : 0, random.nextIntBetweenInclusive(60, 80), velY * 0.05, 1); } } }); diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/CalibratedSculkSensorBlockEntityMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/CalibratedSculkSensorBlockEntityMixin.java index 40abca9968..924367e675 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/CalibratedSculkSensorBlockEntityMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/CalibratedSculkSensorBlockEntityMixin.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.networking.v1.PlayerLookup; import net.frozenblock.lib.math.api.AdvancedMath; import net.frozenblock.wilderwild.misc.interfaces.SculkSensorTickInterface; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterGameEvents; import net.frozenblock.wilderwild.registry.RegisterProperties; import net.frozenblock.wilderwild.registry.RegisterSounds; @@ -66,7 +66,7 @@ private CalibratedSculkSensorBlockEntityMixin(BlockEntityType type, BlockPos double x = (pos.getX() - 0.1) + (level.random.nextFloat() * 1.2); double y = pos.getY() + level.random.nextFloat(); double z = (pos.getZ() - 0.1) + (level.random.nextFloat() * 1.2); - EasyPacket.EasySensorHiccupPacket.createParticle(level, new Vec3(x, y, z)); + WilderNetworking.EasySensorHiccupPacket.createParticle(level, new Vec3(x, y, z)); } if (SculkSensorBlock.canActivate(state) && level.random.nextInt(320) <= 1) { ((SculkSensorBlock) state.getBlock()).activate(null, level, pos, state, AdvancedMath.random().nextInt(15), sensor.getLastVibrationFrequency()); diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkSensorBlockEntityMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkSensorBlockEntityMixin.java index dec659d251..7b05b35d88 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkSensorBlockEntityMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkSensorBlockEntityMixin.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.networking.v1.PlayerLookup; import net.frozenblock.lib.math.api.AdvancedMath; import net.frozenblock.wilderwild.misc.interfaces.SculkSensorTickInterface; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterGameEvents; import net.frozenblock.wilderwild.registry.RegisterProperties; import net.frozenblock.wilderwild.registry.RegisterSounds; @@ -91,7 +91,7 @@ private SculkSensorBlockEntityMixin(BlockEntityType type, BlockPos pos, Block double x = (pos.getX() - 0.1) + (level.random.nextFloat() * 1.2); double y = pos.getY() + level.random.nextFloat(); double z = (pos.getZ() - 0.1) + (level.random.nextFloat() * 1.2); - EasyPacket.EasySensorHiccupPacket.createParticle(level, new Vec3(x, y, z)); + WilderNetworking.EasySensorHiccupPacket.createParticle(level, new Vec3(x, y, z)); } if (SculkSensorBlock.canActivate(state) && level.random.nextInt(320) <= 1) { ((SculkSensorBlock) state.getBlock()).activate(null, level, pos, state, AdvancedMath.random().nextInt(15), sensor.getLastVibrationFrequency()); diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkShriekerBlockEntityMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkShriekerBlockEntityMixin.java index eaca59b6c7..5ccabce78d 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkShriekerBlockEntityMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/sculk/SculkShriekerBlockEntityMixin.java @@ -20,7 +20,7 @@ import net.frozenblock.lib.math.api.AdvancedMath; import net.frozenblock.wilderwild.misc.interfaces.SculkShriekerTickInterface; -import net.frozenblock.wilderwild.misc.server.EasyPacket; +import net.frozenblock.wilderwild.networking.WilderNetworking; import net.frozenblock.wilderwild.registry.RegisterProperties; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -95,7 +95,7 @@ public abstract class SculkShriekerBlockEntityMixin implements SculkShriekerTick --this.wilderWild$bubbles; var random = AdvancedMath.random(); - EasyPacket.EasyFloatingSculkBubblePacket.createParticle(level, Vec3.atCenterOf(pos), random.nextDouble() > 0.7 ? 1 : 0, 20 + random.nextInt(80), 0.075, 1); + WilderNetworking.EasyFloatingSculkBubblePacket.createParticle(level, Vec3.atCenterOf(pos), random.nextDouble() > 0.7 ? 1 : 0, 20 + random.nextInt(80), 0.075, 1); } } } diff --git a/src/main/java/net/frozenblock/wilderwild/misc/server/EasyPacket.java b/src/main/java/net/frozenblock/wilderwild/networking/WilderNetworking.java similarity index 75% rename from src/main/java/net/frozenblock/wilderwild/misc/server/EasyPacket.java rename to src/main/java/net/frozenblock/wilderwild/networking/WilderNetworking.java index 2fce3ed125..397632438a 100644 --- a/src/main/java/net/frozenblock/wilderwild/misc/server/EasyPacket.java +++ b/src/main/java/net/frozenblock/wilderwild/networking/WilderNetworking.java @@ -16,20 +16,30 @@ * along with this program; if not, see . */ -package net.frozenblock.wilderwild.misc.server; +package net.frozenblock.wilderwild.networking; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.frozenblock.wilderwild.WilderWild; +import net.frozenblock.wilderwild.misc.WilderSharedConstants; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; -public class EasyPacket { +public class WilderNetworking { + + public static final ResourceLocation SEED_PACKET = WilderSharedConstants.id("seed_particle_packet"); + public static final ResourceLocation CONTROLLED_SEED_PACKET = WilderSharedConstants.id("controlled_seed_particle_packet"); + public static final ResourceLocation FLOATING_SCULK_BUBBLE_PACKET = WilderSharedConstants.id("floating_sculk_bubble_easy_packet"); + public static final ResourceLocation TERMITE_PARTICLE_PACKET = WilderSharedConstants.id("termite_particle_packet"); + public static final ResourceLocation SENSOR_HICCUP_PACKET = WilderSharedConstants.id("sensor_hiccup_packet"); + public static final ResourceLocation JELLY_STING_PACKET = WilderSharedConstants.id("jelly_sting_packet"); public static void sendJellySting(ServerPlayer player, boolean baby) { FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); @@ -38,7 +48,7 @@ public static void sendJellySting(ServerPlayer player, boolean baby) { } public static class EasySeedPacket { - public static void createParticle(Level level, Vec3 pos, int count, boolean isMilkweed) { + public static void createParticle(@NotNull Level level, Vec3 pos, int count, boolean isMilkweed) { if (level.isClientSide) throw new IllegalStateException("Particle attempting spawning on THE CLIENT JESUS CHRIST WHAT THE HECK SPAWN ON SERVER NEXT TIME PLS"); FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); @@ -52,7 +62,7 @@ public static void createParticle(Level level, Vec3 pos, int count, boolean isMi } } - public static void createControlledParticle(Level level, Vec3 pos, double xvel, double yvel, double zvel, int count, boolean isMilkweed, int radius, double posRandomizer) { + public static void createControlledParticle(@NotNull Level level, Vec3 pos, double xvel, double yvel, double zvel, int count, boolean isMilkweed, int radius, double posRandomizer) { if (level.isClientSide) throw new IllegalStateException("Particle attempting spawning on THE CLIENT JESUS CHRIST WHAT THE HECK SPAWN ON SERVER NEXT TIME PLS"); FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); @@ -72,7 +82,7 @@ public static void createControlledParticle(Level level, Vec3 pos, double xvel, } public static class EasyFloatingSculkBubblePacket { - public static void createParticle(Level level, Vec3 pos, double size, int maxAge, double yVel, int count) { + public static void createParticle(@NotNull Level level, Vec3 pos, double size, int maxAge, double yVel, int count) { if (level.isClientSide) throw new IllegalStateException("Particle attempting spawning on THE CLIENT JESUS CHRIST WHAT THE HECK SPAWN ON SERVER NEXT TIME PLS"); FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); @@ -90,7 +100,7 @@ public static void createParticle(Level level, Vec3 pos, double size, int maxAge } public static class EasySensorHiccupPacket { - public static void createParticle(Level level, Vec3 pos) { + public static void createParticle(@NotNull Level level, Vec3 pos) { if (level.isClientSide) throw new IllegalStateException("Particle attempting spawning on THE CLIENT JESUS CHRIST WHAT THE HECK SPAWN ON SERVER NEXT TIME STUPID IDIOT"); FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); @@ -104,7 +114,7 @@ public static void createParticle(Level level, Vec3 pos) { } public static class EasyTermitePacket { - public static void createParticle(Level level, Vec3 pos, int count) { + public static void createParticle(@NotNull Level level, Vec3 pos, int count) { if (level.isClientSide) throw new IllegalStateException("Particle attempting spawning on THE CLIENT JESUS CHRIST WHAT THE HECK SPAWN ON SERVER NEXT TIME PLS"); FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); diff --git a/src/main/java/net/frozenblock/wilderwild/networking/client/WilderClientNetworking.java b/src/main/java/net/frozenblock/wilderwild/networking/client/WilderClientNetworking.java new file mode 100644 index 0000000000..70c4aa2c92 --- /dev/null +++ b/src/main/java/net/frozenblock/wilderwild/networking/client/WilderClientNetworking.java @@ -0,0 +1,136 @@ +package net.frozenblock.wilderwild.networking.client; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.frozenblock.lib.math.api.AdvancedMath; +import net.frozenblock.wilderwild.networking.WilderNetworking; +import net.frozenblock.wilderwild.particle.options.FloatingSculkBubbleParticleOptions; +import net.frozenblock.wilderwild.particle.options.SeedParticleOptions; +import net.frozenblock.wilderwild.registry.RegisterParticles; +import net.frozenblock.wilderwild.registry.RegisterSounds; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.phys.Vec3; +import java.util.concurrent.atomic.AtomicInteger; + +@Environment(EnvType.CLIENT) +public class WilderClientNetworking { + + public static void registerPacketReceivers() { + receiveEasyEchoerBubblePacket(); + receiveSeedPacket(); + receiveControlledSeedPacket(); + receiveTermitePacket(); + receiveSensorHiccupPacket(); + receiveJellyStingPacket(); + } + private static void receiveEasyEchoerBubblePacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.FLOATING_SCULK_BUBBLE_PACKET, (ctx, handler, byteBuf, responseSender) -> { + Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); + double size = byteBuf.readDouble(); + int age = byteBuf.readInt(); + double yVel = byteBuf.readDouble(); + int count = byteBuf.readVarInt(); + ctx.execute(() -> { + if (ctx.level == null) + throw new IllegalStateException("why is your world null"); + var random = AdvancedMath.random(); + for (int i = 0; i < count; i++) { + double xVel = (random.nextDouble() - 0.5) / 9.5; + double zVel = (random.nextDouble() - 0.5) / 9.5; + if (size >= 1) { + xVel = (random.nextDouble() - 0.5) / 10.5; + zVel = (random.nextDouble() - 0.5) / 10.5; + } + ctx.level.addParticle(new FloatingSculkBubbleParticleOptions(size, age, new Vec3(xVel, yVel, zVel)), pos.x, pos.y, pos.z, 0, 0, 0); + } + }); + }); + } + + private static void receiveSeedPacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.SEED_PACKET, (ctx, handler, byteBuf, responseSender) -> { + Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); + int count = byteBuf.readVarInt(); + boolean milkweed = byteBuf.readBoolean(); + ctx.execute(() -> { + if (ctx.level == null) + throw new IllegalStateException("why is your world null"); + for (int i = 0; i < count; i++) { + ctx.level.addParticle(new SeedParticleOptions(milkweed, false), pos.x, pos.y, pos.z, 0, 0, 0); + } + }); + }); + } + + private static void receiveControlledSeedPacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.CONTROLLED_SEED_PACKET, (ctx, handler, byteBuf, responseSender) -> { + Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); + double velx = byteBuf.readDouble(); + double vely = byteBuf.readDouble(); + double velz = byteBuf.readDouble(); + int count = byteBuf.readVarInt(); + boolean milkweed = byteBuf.readBoolean(); + double posRandomizer = byteBuf.readDouble(); + ctx.execute(() -> { + if (ctx.level == null) + throw new IllegalStateException("why is your world null"); + for (int i = 0; i < count; i++) { + ctx.level.addParticle(new SeedParticleOptions(milkweed, true), pos.x, pos.y + ((ctx.level.random.nextBoolean() ? -1 : 1) * (ctx.level.random.nextDouble() * posRandomizer)), pos.z, velx, vely + (ctx.level.random.nextDouble() * 0.07), velz); + } + }); + }); + } + + private static void receiveTermitePacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.TERMITE_PARTICLE_PACKET, (ctx, handler, byteBuf, responseSender) -> { + Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); + AtomicInteger count = new AtomicInteger(byteBuf.readVarInt()); + ctx.execute(() -> { + if (ctx.level == null) + throw new IllegalStateException("why is your world null"); + + count.addAndGet(-1); + ctx.level.addAlwaysVisibleParticle(RegisterParticles.TERMITE, pos.x, pos.y, pos.z, 0, 0, 0); + for (int i = 0; i < count.get(); i++) { + ctx.level.addParticle(RegisterParticles.TERMITE, pos.x, pos.y, pos.z, 0, 0, 0); + } + }); + }); + } + + private static void receiveSensorHiccupPacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.SENSOR_HICCUP_PACKET, (ctx, handler, byteBuf, responseSender) -> { + Vec3 pos = new Vec3(byteBuf.readDouble(), byteBuf.readDouble(), byteBuf.readDouble()); + ctx.execute(() -> { + if (ctx.level == null) + throw new IllegalStateException("why is your world null"); + ClientLevel level = ctx.level; + int i = 5578058; + boolean bl2 = level.random.nextBoolean(); + if (bl2) { + double d = (double) (i >> 16 & 255) / 255.0D; + double e = (double) (i >> 8 & 255) / 255.0D; + double f = (double) (i & 255) / 255.0D; + level.addParticle(ParticleTypes.ENTITY_EFFECT, pos.x, pos.y, pos.z, d, e, f); + } + }); + }); + } + + private static void receiveJellyStingPacket() { + ClientPlayNetworking.registerGlobalReceiver(WilderNetworking.JELLY_STING_PACKET, (ctx, handler, byteBuf, responseSender) -> ctx.execute(() -> { + boolean baby = byteBuf.readBoolean(); + if (ctx.level != null) { + LocalPlayer player = ctx.player; + if (player != null) { + ctx.level.playSound(player, player.getX(), player.getY(), player.getZ(), RegisterSounds.ENTITY_JELLYFISH_STING, SoundSource.NEUTRAL, 1.0F, ctx.level.random.nextFloat() * 0.2F + (baby ? 1.2F : 0.9F)); + } + } + })); + } + +}