允许武器打碎玻璃,添加配置
This commit is contained in:
parent
47cd2db515
commit
b5b2ca6cae
3 changed files with 31 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.config;
|
package com.atsuishio.superbwarfare.config;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
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.SpawnConfig;
|
||||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
@ -11,6 +12,7 @@ public class ServerConfig {
|
||||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
||||||
|
|
||||||
SpawnConfig.init(builder);
|
SpawnConfig.init(builder);
|
||||||
|
ProjectileConfig.init(builder);
|
||||||
ExplosionConfig.init(builder);
|
ExplosionConfig.init(builder);
|
||||||
VehicleConfig.init(builder);
|
VehicleConfig.init(builder);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity.projectile;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.block.BarbedWireBlock;
|
import com.atsuishio.superbwarfare.block.BarbedWireBlock;
|
||||||
|
import com.atsuishio.superbwarfare.config.server.ProjectileConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
|
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
|
||||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
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.level.material.FluidState;
|
||||||
import net.minecraft.world.phys.*;
|
import net.minecraft.world.phys.*;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
import net.minecraftforge.common.Tags;
|
||||||
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||||
import net.minecraftforge.entity.PartEntity;
|
import net.minecraftforge.entity.PartEntity;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
@ -72,10 +74,9 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
|
||||||
private static final Predicate<Entity> PROJECTILE_TARGETS = input -> input != null && input.isPickable() && !input.isSpectator() && input.isAlive();
|
private static final Predicate<Entity> PROJECTILE_TARGETS = input -> input != null && input.isPickable() && !input.isSpectator() && input.isAlive();
|
||||||
private static final Predicate<BlockState> IGNORE_LEAVES = input -> input != null && (input.getBlock() instanceof LeavesBlock
|
private static final Predicate<BlockState> IGNORE_LIST = input -> input != null && (input.getBlock() instanceof LeavesBlock
|
||||||
|| input.getBlock() instanceof FenceBlock
|
|| input.getBlock() instanceof FenceBlock
|
||||||
|| input.getBlock() instanceof IronBarsBlock
|
|| input.is(Blocks.IRON_BARS)
|
||||||
|| input.getBlock() instanceof StainedGlassPaneBlock
|
|
||||||
|| input.getBlock() instanceof DoorBlock
|
|| input.getBlock() instanceof DoorBlock
|
||||||
|| input.getBlock() instanceof TrapDoorBlock
|
|| input.getBlock() instanceof TrapDoorBlock
|
||||||
|| input.getBlock() instanceof BarbedWireBlock);
|
|| input.getBlock() instanceof BarbedWireBlock);
|
||||||
|
@ -244,7 +245,8 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa
|
||||||
if (!this.level().isClientSide() && this.shooter != null) {
|
if (!this.level().isClientSide() && this.shooter != null) {
|
||||||
Vec3 startVec = this.position();
|
Vec3 startVec = this.position();
|
||||||
Vec3 endVec = startVec.add(this.getDeltaMovement());
|
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) {
|
if (result.getType() != HitResult.Type.MISS) {
|
||||||
endVec = result.getLocation();
|
endVec = result.getLocation();
|
||||||
}
|
}
|
||||||
|
@ -344,6 +346,12 @@ public class ProjectileEntity extends Projectile implements IEntityAdditionalSpa
|
||||||
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
|
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 (state.getBlock() instanceof TargetBlock) {
|
||||||
if (this.shooter == null) return;
|
if (this.shooter == null) return;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue