添加BEAST子弹

This commit is contained in:
Light_Quanta 2024-05-10 16:47:53 +08:00
parent 19f559d4a3
commit c3541ee834
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
6 changed files with 133 additions and 57 deletions

View file

@ -12,6 +12,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
@ -28,12 +29,14 @@ import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
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.entity.IEntityAdditionalSpawnData;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
@ -48,27 +51,34 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
protected int shooterId;
private float damage = 1f;
private float headShot = 1f;
private boolean beast = false;
public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) {
super(p_i50159_1_, p_i50159_2_);
}
public ProjectileEntity(Level world, LivingEntity entity) {
super(TargetCustomModEntities.PROJECTILE.get(), world);
this.shooter = entity;
public ProjectileEntity(Level level) {
super(TargetCustomModEntities.PROJECTILE.get(), level);
}
public ProjectileEntity(Level world, LivingEntity entity, float damage) {
super(TargetCustomModEntities.PROJECTILE.get(), world);
this.shooter = entity;
this.damage = damage;
public ProjectileEntity shooter(LivingEntity shooter) {
this.shooter = shooter;
return this;
}
public ProjectileEntity(Level world, LivingEntity entity, float damage, float headShot) {
super(TargetCustomModEntities.PROJECTILE.get(), world);
this.shooter = entity;
public ProjectileEntity damage(float damage) {
this.damage = damage;
return this;
}
public ProjectileEntity headShot(float headShot) {
this.headShot = headShot;
return this;
}
public ProjectileEntity beast() {
this.beast = true;
return this;
}
@Nullable
@ -76,15 +86,20 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
Vec3 hitVec = null;
Entity hitEntity = null;
boolean headshot = false;
List<Entity> entities = this.level().getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS);
List<Entity> entities = this.level()
.getEntities(this,
this.getBoundingBox()
.expandTowards(this.getDeltaMovement())
.inflate(this.beast ? 3 : 1),
PROJECTILE_TARGETS
);
double closestDistance = Double.MAX_VALUE;
for (Entity entity : entities) {
if (!entity.equals(this.shooter)) {
if (entity.equals(this.shooter)) continue;
EntityResult result = this.getHitResult(entity, startVec, endVec);
if (result == null) {
continue;
}
if (result == null) continue;
Vec3 hitPos = result.getHitPos();
double distanceToHit = startVec.distanceTo(hitPos);
@ -95,24 +110,28 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
headshot = result.isHeadshot();
}
}
}
return hitEntity != null ? new EntityResult(hitEntity, hitVec, headshot) : null;
}
// @Nullable
// protected List<EntityResult> findEntitiesOnPath(Vec3 startVec, Vec3 endVec) {
// List<EntityResult> hitEntities = new ArrayList<>();
// List<Entity> entities = this.level().getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS);
// for (Entity entity : entities) {
// if (!entity.equals(this.shooter)) {
// EntityResult result = this.getHitResult(entity, startVec, endVec);
// if (result == null)
// continue;
// hitEntities.add(result);
// }
// }
// return hitEntities;
// }
@Nullable
protected List<EntityResult> findEntitiesOnPath(Vec3 startVec, Vec3 endVec) {
List<EntityResult> hitEntities = new ArrayList<>();
List<Entity> entities = this.level().getEntities(
this,
this.getBoundingBox()
.expandTowards(this.getDeltaMovement())
.inflate(this.beast ? 3 : 1),
PROJECTILE_TARGETS
);
for (Entity entity : entities) {
if (!entity.equals(this.shooter)) {
EntityResult result = this.getHitResult(entity, startVec, endVec);
if (result == null) continue;
hitEntities.add(result);
}
}
return hitEntities;
}
@Nullable
@SuppressWarnings("unchecked")
@ -120,6 +139,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
double expandHeight = entity instanceof Player && !entity.isCrouching() ? 0.0625 : 0.0;
AABB boundingBox = entity.getBoundingBox();
if (this.beast) {
boundingBox = boundingBox.inflate(3);
}
// 延迟补偿
if (entity instanceof ServerPlayer && this.shooter != null) {
int ping = (int) Math.floor((((ServerPlayer) this.shooter).latency / 1000.0) * 20.0 + 4.0);
@ -186,9 +209,17 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
endVec = result.getLocation();
}
EntityResult entityResult = this.findEntityOnPath(startVec, endVec);
List<EntityResult> entityResults = new ArrayList<>();
if (entityResult != null) {
if (this.beast) {
var temp = findEntitiesOnPath(startVec, endVec);
if (temp != null) entityResults.addAll(temp);
} else {
var temp = this.findEntityOnPath(startVec, endVec);
if (temp != null) entityResults.add(temp);
}
for (var entityResult : entityResults) {
result = new ExtendedEntityRayTraceResult(entityResult);
if (((EntityHitResult) result).getEntity() instanceof Player player) {
if (this.shooter instanceof Player && !((Player) this.shooter).canHarmPlayer(player)) {
@ -198,7 +229,8 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
if (result != null) {
this.onHit(result);
}
} else {
}
if (entityResults.isEmpty()) {
this.onHit(result);
}
@ -268,41 +300,57 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
}
protected void onHitEntity(Entity entity, boolean headshot) {
if (headshot) {
if (entity == null)
return;
if (entity == null) return;
if (beast && entity instanceof LivingEntity living) {
if (living.isDeadOrDying()) return;
if (living instanceof ServerPlayer victim) {
living.setHealth(0);
living.level().players().forEach(
p -> p.sendSystemMessage(
Component.translatable("death.attack.beast_gun",
victim.getDisplayName(),
shooter.getDisplayName()
)
)
);
} else {
living.setHealth(0);
living.level().broadcastEntityEvent(living, (byte) 60);
living.remove(Entity.RemovalReason.KILLED);
living.gameEvent(GameEvent.ENTITY_DIE);
}
((ServerLevel) this.level()).sendParticles(ParticleTypes.DAMAGE_INDICATOR, living.getX(), living.getY() + .5, living.getZ(), 1000, .4, .7, .4, 0);
this.discard();
return;
}
if (headshot) {
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
var holder = Holder.direct(TargetModSounds.HEADSHOT.get());
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
}
double i = 25;
shooter.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.headind = i;
capability.headind = 25;
capability.syncPlayerVariables(shooter);
});
entity.hurt(TargetModDamageTypes.causeGunFireDamage(this.level().registryAccess(), this.shooter), this.damage * this.headShot);
this.discard();
} else {
if (entity == null)
return;
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
var holder = Holder.direct(TargetModSounds.INDICATION.get());
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
}
double i = 25;
shooter.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.hitind = i;
capability.hitind = 25;
capability.syncPlayerVariables(shooter);
});
entity.hurt(TargetModDamageTypes.causeGunFireDamage(this.level().registryAccess(), this.shooter), this.damage);
this.discard();
}
this.discard();
}
public void setDamage(float damage) {

View file

@ -236,7 +236,14 @@ public class GunEventHandler {
float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("adddamage"))
* (float) heldItem.getOrCreateTag().getDouble("damageadd");
ProjectileEntity projectile = new ProjectileEntity(player.level(), player, damage, headshot);
ProjectileEntity projectile = new ProjectileEntity(player.level())
.shooter(player)
.damage(damage)
.headShot(headshot);
if (heldItem.getOrCreateTag().getBoolean("beast")) {
projectile.beast();
}
projectile.setPos((player.getX() + (-0.5) * player.getLookAngle().x), (player.getEyeY() - 0.1 + (-0.5) * player.getLookAngle().y), (player.getZ() + (-0.5) * player.getLookAngle().z));
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, 1 * (float) heldItem.getOrCreateTag().getDouble("velocity"),

View file

@ -29,4 +29,9 @@ public class GunItem extends Item {
}
GunsTool.pvpModeCheck(itemstack, level);
}
@Override
public boolean isFoil(ItemStack stack) {
return stack.getOrCreateTag().getBoolean("beast");
}
}

View file

@ -26,7 +26,14 @@ public class BulletFireNormalProcedure {
damage = 0.008333333f * (float) heldItem.getOrCreateTag().getDouble("damage") * (float) heldItem.getOrCreateTag().getDouble("speed") * (float) heldItem.getOrCreateTag().getDouble("damageadd");
ProjectileEntity projectile = new ProjectileEntity(player.level(), player, damage, headshot);
ProjectileEntity projectile = new ProjectileEntity(player.level())
.shooter(player)
.damage(damage)
.headShot(headshot);
if (heldItem.getOrCreateTag().getBoolean("beast")) {
projectile.beast();
}
projectile.setPos((player.getX() + (-0.5) * player.getLookAngle().x), (player.getEyeY() - 0.1 + (-0.5) * player.getLookAngle().y), (player.getZ() + (-0.5) * player.getLookAngle().z));
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, 1 * velocity, 2.5f);
@ -36,7 +43,14 @@ public class BulletFireNormalProcedure {
damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("adddamage"))
* (float) heldItem.getOrCreateTag().getDouble("damageadd");
ProjectileEntity projectile = new ProjectileEntity(player.level(), player, damage, headshot);
ProjectileEntity projectile = new ProjectileEntity(player.level())
.shooter(player)
.damage(damage)
.headShot(headshot);
if (heldItem.getOrCreateTag().getBoolean("beast")) {
projectile.beast();
}
projectile.setPos((player.getX() + (-0.5) * player.getLookAngle().x), (player.getEyeY() - 0.1 + (-0.5) * player.getLookAngle().y), (player.getZ() + (-0.5) * player.getLookAngle().z));
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, 1 * (float) heldItem.getOrCreateTag().getDouble("velocity"),

View file

@ -150,6 +150,7 @@
"death.attack.arrow_in_brain": "%2$s's arrow shot into %1$s's brain",
"death.attack.arrow_in_brain.item": "An arrow shot into %1$s's brain,murderer is %2$s used %3$s",
"death.attack.arrow_in_brain.player": "An arrow shot into %1$s's brain whilst trying to escape %2$s",
"death.attack.beast_gun": "%1$s was killed by %2$s using BEAST guns",
"Shell Estimated Range": "Estimated Range:",
"gui.target.mortar_gui.label_proc_range": "Estimated Range:",

View file

@ -150,6 +150,7 @@
"death.attack.arrow_in_brain": "%1$s的脑子进矢了,凶手是%2$s",
"death.attack.arrow_in_brain.item": "%1$s的脑子进矢了,凶手%2$s使用了%3$s",
"death.attack.arrow_in_brain.player": "%1$s在逃离%2$s的时候脑子进矢了",
"death.attack.beast_gun": "%1$s被%2$s用BEAST枪械臭炸了",
"Shell Estimated Range": "炮弹预估射程:",
"gui.target.mortar_gui.label_proc_range": "预估射程:",