Skip to content

Commit

Permalink
cleanup + explosions now affect their owners
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Oct 18, 2024
1 parent 2734900 commit 64e7fd5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ladysnake.blast.common.world;

import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock;
import net.minecraft.block.FluidFillable;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -21,7 +19,7 @@ public void affectWorld(boolean particles) {
for (BlockPos pos : affectedBlocks) {
if (canPlace(pos)) {
BlockState state = world.getBlockState(pos);
if (state.isAir() || state.getBlock() instanceof FluidBlock || state.getBlock() instanceof FluidFillable) {
if (state.isReplaceable()) {
if (!world.isClient) {
world.setBlockState(pos, blockStateToPlace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void collectBlocksAndDamageEntities() {
int minZ = MathHelper.floor(z - power - 1);
int maxZ = MathHelper.floor(z + power + 1);
Vec3d source = new Vec3d(x, y, z);
for (Entity entity : world.getOtherEntities(entity, new Box(minX, minY, minZ, maxX, maxY, maxZ))) {
if (!entity.isImmuneToExplosion(this)) {
for (Entity entity : world.getOtherEntities(null, new Box(minX, minY, minZ, maxX, maxY, maxZ))) {
if (!entity.isImmuneToExplosion(this) && ProtectionsProvider.canDamageEntity(entity, damageSource)) {
double distance = Math.sqrt(entity.squaredDistanceTo(source)) / power;
if (distance <= 1) {
double dX = entity.getX() - x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
Expand All @@ -22,7 +23,7 @@ public void affectWorld(boolean particles) {
}
}
for (Entity entity : affectedEntities) {
if (ProtectionsProvider.canDamageEntity(entity, damageSource)) {
if (ProtectionsProvider.canInteractEntity(entity, damageSource)) {
double distance = Math.sqrt(entity.squaredDistanceTo(source)) / (getPower() * 2);
if (distance <= 1.0D) {
double dX = entity.getX() - this.x;
Expand All @@ -33,7 +34,10 @@ public void affectWorld(boolean particles) {
dX /= product;
dY /= product;
dZ /= product;
double strength = (1 - distance) * getExposure(source, entity) * 3;
double strength = (1 - distance) * getExposure(source, entity);
if (entity instanceof PlayerEntity player) {
getAffectedPlayers().put(player, new Vec3d(dX * strength, dY * strength, dZ * strength));
}
if (entity instanceof LivingEntity living) {
strength *= 1 - living.getAttributeValue(EntityAttributes.GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE);
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/ladysnake/blast/mixin/ExplosionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import ladysnake.blast.common.util.ProtectionsProvider;
import ladysnake.blast.common.world.CustomExplosion;
import ladysnake.blast.common.world.EnderExplosion;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import java.util.Optional;

@Mixin(Explosion.class)
public class ExplosionMixin {
@Shadow
@Final
public DamageSource damageSource;

@WrapOperation(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/ExplosionBehavior;getBlastResistance(Lnet/minecraft/world/explosion/Explosion;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/fluid/FluidState;)Ljava/util/Optional;"))
private Optional<Float> blast$overrideBlastResistance(ExplosionBehavior instance, Explosion explosion, BlockView world, BlockPos pos, BlockState blockState, FluidState fluidState, Operation<Optional<Float>> original) {
if (isEffect(explosion, CustomExplosion.BlockBreakEffect.AQUATIC) || isEffect(explosion, CustomExplosion.BlockBreakEffect.FROSTY)) {
Expand All @@ -37,6 +46,23 @@ public class ExplosionMixin {
return original.call(instance, explosion, world, pos, blockState, fluidState);
}

@ModifyArg(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;)Ljava/util/List;"))
private Entity blast$removeOwner(Entity value) {
if ((Object) this instanceof CustomExplosion) {
return null;
}
return value;
}

@SuppressWarnings("ConstantValue")
@ModifyExpressionValue(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion(Lnet/minecraft/world/explosion/Explosion;)Z"))
private boolean blast$protections(boolean original, @Local Entity entity) {
if ((Object) this instanceof CustomExplosion && !ProtectionsProvider.canDamageEntity(entity, damageSource)) {
return false;
}
return original;
}

@ModifyExpressionValue(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/ExplosionBehavior;shouldDamage(Lnet/minecraft/world/explosion/Explosion;Lnet/minecraft/entity/Entity;)Z"))
private boolean blast$customDamage(boolean original, @Local Entity entity) {
if ((Object) this instanceof CustomExplosion customExplosion) {
Expand Down

0 comments on commit 64e7fd5

Please sign in to comment.