diff --git a/src/main/java/com/atsuishio/superbwarfare/config/ServerConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/ServerConfig.java index ec1bc343c..6015c455d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/config/ServerConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/config/ServerConfig.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.config; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.config.server.ProjectileConfig; import com.atsuishio.superbwarfare.config.server.SpawnConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import net.minecraftforge.common.ForgeConfigSpec; @@ -11,6 +12,7 @@ public class ServerConfig { ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); SpawnConfig.init(builder); + ProjectileConfig.init(builder); ExplosionConfig.init(builder); VehicleConfig.init(builder); diff --git a/src/main/java/com/atsuishio/superbwarfare/config/server/ProjectileConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/server/ProjectileConfig.java new file mode 100644 index 000000000..e6e3be56a --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/config/server/ProjectileConfig.java @@ -0,0 +1,17 @@ +package com.atsuishio.superbwarfare.config.server; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class ProjectileConfig { + + public static ForgeConfigSpec.BooleanValue ALLOW_PROJECTILE_DESTROY_GLASS; + + public static void init(ForgeConfigSpec.Builder builder) { + builder.push("projectile"); + + builder.comment("Set true to allow projectiles to destroy glasses"); + ALLOW_PROJECTILE_DESTROY_GLASS = builder.define("allow_projectile_destroy_glass", false); + + builder.pop(); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index da7576d1e..b0e463acc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.block.BarbedWireBlock; +import com.atsuishio.superbwarfare.config.server.ProjectileConfig; import com.atsuishio.superbwarfare.entity.ICustomKnockback; import com.atsuishio.superbwarfare.entity.TargetEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; @@ -47,6 +48,7 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.*; import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraftforge.common.Tags; import net.minecraftforge.entity.IEntityAdditionalSpawnData; import net.minecraftforge.entity.PartEntity; import net.minecraftforge.network.PacketDistributor; @@ -72,10 +74,9 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private static final Predicate PROJECTILE_TARGETS = input -> input != null && input.isPickable() && !input.isSpectator() && input.isAlive(); - private static final Predicate IGNORE_LEAVES = input -> input != null && (input.getBlock() instanceof LeavesBlock + private static final Predicate IGNORE_LIST = input -> input != null && (input.getBlock() instanceof LeavesBlock || input.getBlock() instanceof FenceBlock - || input.getBlock() instanceof IronBarsBlock - || input.getBlock() instanceof StainedGlassPaneBlock + || input.is(Blocks.IRON_BARS) || input.getBlock() instanceof DoorBlock || input.getBlock() instanceof TrapDoorBlock || input.getBlock() instanceof BarbedWireBlock); @@ -244,7 +245,8 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa if (!this.level().isClientSide() && this.shooter != null) { Vec3 startVec = this.position(); Vec3 endVec = startVec.add(this.getDeltaMovement()); - HitResult result = rayTraceBlocks(this.level(), new ClipContext(startVec, endVec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), IGNORE_LEAVES); + HitResult result = rayTraceBlocks(this.level(), new ClipContext(startVec, endVec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), + ProjectileConfig.ALLOW_PROJECTILE_DESTROY_GLASS.get() ? IGNORE_LIST : IGNORE_LIST.or(input -> input.is(Tags.Blocks.GLASS_PANES))); if (result.getType() != HitResult.Type.MISS) { endVec = result.getLocation(); } @@ -344,6 +346,12 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); } + if (ProjectileConfig.ALLOW_PROJECTILE_DESTROY_GLASS.get()) { + if (state.is(Tags.Blocks.GLASS) || state.is(Tags.Blocks.GLASS_PANES)) { + this.level().destroyBlock(resultPos, false, this.getShooter()); + } + } + if (state.getBlock() instanceof TargetBlock) { if (this.shooter == null) return;