Skip to content

Commit

Permalink
added Explosive Enhancement compat
Browse files Browse the repository at this point in the history
  • Loading branch information
CammiePone committed Apr 12, 2024
1 parent 3071d15 commit a578165
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ dependencies {
// iris
modImplementation libs.iris

// explosive enhancement
modImplementation libs.explosive.enhancement

// pehkui
modCompileOnly libs.pehkui
modRuntimeOnly libs.pehkui
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lambdynamiclights = "2.3.2+1.20.1"
spruceui = "5.0.2+1.20"
sodium = "mc1.20.1-0.5.3"
iris = "1.6.11+1.20.1"
explosive_enhancement = "1.2.2-1.20.x"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
Expand Down Expand Up @@ -50,6 +51,7 @@ lambdynamiclights = { module = "maven.modrinth:lambdynamiclights", version.ref =
spruceui = { module = "dev.lambdaurora:spruceui", version.ref = "spruceui" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
iris = { module = "maven.modrinth:iris", version.ref = "iris" }
explosive_enhancement = { module = "maven.modrinth:explosive-enhancement", version.ref = "explosive_enhancement" }

# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example".
[bundles]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public void onInitializeClient(ModContainer mod) {
ClientPlayNetworking.registerGlobalReceiver(SyncStaffTemplatePacket.ID, SyncStaffTemplatePacket::handle);
ClientPlayNetworking.registerGlobalReceiver(SyncSupporterData.ID, SyncSupporterData::handle);
ClientPlayNetworking.registerGlobalReceiver(SyncConfigValuesPacket.ID, SyncConfigValuesPacket::handle);
ClientPlayNetworking.registerGlobalReceiver(SyncExplosionParticlesPacket.ID, SyncExplosionParticlesPacket::handle);

ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? StaffItem.getPrimaryColour(stack) : tintIndex == 1 ? StaffItem.getSecondaryColour(stack) : 0xffffff,
ArcanusItems.WOODEN_STAFF.get(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.cammiescorner.arcanuscontinuum.common.compat;

import net.minecraft.registry.tag.FluidTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.superkat.explosiveenhancement.ExplosiveEnhancement;
import net.superkat.explosiveenhancement.ExplosiveEnhancementClient;
import net.superkat.explosiveenhancement.api.ExplosiveApi;

public class ExplosiveEnhancementCompat {
public static void spawnEnhancedBooms(World world, double x, double y, double z, float power, boolean didDestroyBlocks) {
boolean isUnderWater = false;
BlockPos pos = BlockPos.create(x, y, z);

if(ExplosiveEnhancementClient.config.underwaterExplosions && world.getFluidState(pos).isIn(FluidTags.WATER)) {
isUnderWater = true;

if(ExplosiveEnhancementClient.config.debugLogs)
ExplosiveEnhancement.LOGGER.info("particle is underwater!");
}

ExplosiveApi.spawnParticles(world, x, y, z, power, isUnderWater, didDestroyBlocks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.cammiescorner.arcanuscontinuum.common.packets.s2c;

import dev.cammiescorner.arcanuscontinuum.Arcanus;
import dev.cammiescorner.arcanuscontinuum.common.compat.ExplosiveEnhancementCompat;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.qsl.networking.api.PacketByteBufs;
import org.quiltmc.qsl.networking.api.PacketSender;
import org.quiltmc.qsl.networking.api.ServerPlayNetworking;

public class SyncExplosionParticlesPacket {
public static final Identifier ID = Arcanus.id("sync_explosion_particles");

public static void send(ServerPlayerEntity player, double x, double y, double z, float strength, boolean didDestroyBlocks) {
PacketByteBuf buf = PacketByteBufs.create();

buf.writeDouble(x);
buf.writeDouble(y);
buf.writeDouble(z);
buf.writeFloat(strength);
buf.writeBoolean(didDestroyBlocks);

ServerPlayNetworking.send(player, ID, buf);
}

public static void handle(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) {
double x = buf.readDouble();
double y = buf.readDouble();
double z = buf.readDouble();
float strength = buf.readFloat();
boolean didDestroyBlocks = buf.readBoolean();

client.execute(() -> {
World world = client.world;

if(QuiltLoader.isModLoaded("explosiveenhancement"))
ExplosiveEnhancementCompat.spawnEnhancedBooms(world, x, y, z, strength, didDestroyBlocks);
else
world.addParticle(ParticleTypes.EXPLOSION_EMITTER, x, y, z, 1, 1, 1);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import dev.cammiescorner.arcanuscontinuum.api.spells.SpellGroup;
import dev.cammiescorner.arcanuscontinuum.api.spells.SpellShape;
import dev.cammiescorner.arcanuscontinuum.api.spells.Weight;
import dev.cammiescorner.arcanuscontinuum.common.packets.s2c.SyncExplosionParticlesPacket;
import dev.cammiescorner.arcanuscontinuum.common.registry.ArcanusSpellComponents;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand All @@ -20,6 +22,7 @@
import net.minecraft.util.math.*;
import net.minecraft.world.event.GameEvent;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.qsl.networking.api.PlayerLookup;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -100,7 +103,10 @@ public void cast(@Nullable LivingEntity caster, Vec3d castFrom, @Nullable Entity
}

world.playSound(null, castFrom.getX(), castFrom.getY(), castFrom.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4F, (1F + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F, 1L);
world.spawnParticles(ParticleTypes.EXPLOSION_EMITTER, castFrom.getX(), castFrom.getY(), castFrom.getZ(), 1, 1, 0, 0, 1);

for(ServerPlayerEntity player : PlayerLookup.tracking(world, BlockPos.create(castFrom.getX(), castFrom.getY(), castFrom.getZ())))
SyncExplosionParticlesPacket.send(player, castFrom.getX(), castFrom.getY(), castFrom.getZ(), strength, effects.contains(ArcanusSpellComponents.MINE.get()));

castNext(caster, castFrom, castSource, world, stack, spellGroups, groupIndex, potency);
}
}

0 comments on commit a578165

Please sign in to comment.