添加原版标靶显示射击成绩功能

This commit is contained in:
Atsuihsio 2024-08-14 21:08:03 +08:00
parent 40050a79fa
commit 674cd881d6
5 changed files with 46 additions and 3 deletions

View file

@ -47,12 +47,14 @@ import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.entity.PartEntity;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
@ -312,6 +314,24 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
}
if (state.getBlock() instanceof TargetBlock) {
int rings = getRings(blockHitResult, hitVec);
double dis = shooter.position().distanceTo(hitVec);
if (shooter instanceof Player player) {
player.displayClientMessage(Component.literal(String.valueOf(rings))
.append(Component.translatable("des.superbwarfare.shoot.rings"))
.append(Component.literal(new DecimalFormat("##.#").format(dis) + "M")), false);
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer splayer) {
var holder = rings == 10 ? Holder.direct(ModSounds.HEADSHOT.get()) : Holder.direct(ModSounds.INDICATION.get());
splayer.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ClientIndicatorMessage(rings == 10 ? 1 : 0, 5));
}
}
}
this.onHitBlock(hitVec);
}
@ -332,6 +352,24 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
}
}
private static int getRings(@NotNull BlockHitResult blockHitResult, @NotNull Vec3 hitVec) {
Direction $$2 = blockHitResult.getDirection();
double $$3 = Math.abs(Mth.frac(hitVec.x) - 0.5);
double $$4 = Math.abs(Mth.frac(hitVec.y) - 0.5);
double $$5 = Math.abs(Mth.frac(hitVec.z) - 0.5);
Direction.Axis $$6 = $$2.getAxis();
double $$9;
if ($$6 == Direction.Axis.Y) {
$$9 = Math.max($$3, $$5);
} else if ($$6 == Direction.Axis.Z) {
$$9 = Math.max($$3, $$4);
} else {
$$9 = Math.max($$4, $$5);
}
return Math.max(1, Mth.ceil(10.0 * Mth.clamp((0.5 - $$9) / 0.5, 0.0, 1.0)));
}
protected void onHitBlock(Vec3 location) {
if (this.level() instanceof ServerLevel serverLevel) {
if (this.beast) {
@ -382,7 +420,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
} else {
living.setHealth(0);
living.level().broadcastEntityEvent(living, (byte) 60);
living.remove(Entity.RemovalReason.KILLED);
living.remove(RemovalReason.KILLED);
living.gameEvent(GameEvent.ENTITY_DIE);
}

View file

@ -315,5 +315,7 @@
"des.superbwarfare.drone.kamikaze": "KAMIKAZE",
"des.superbwarfare.drone.warning": "WARNING!",
"des.superbwarfare.shoot.rings": "Rings ",
"container.superbwarfare.reforging_table": "Gun Reforge Table"
}

View file

@ -315,5 +315,8 @@
"des.superbwarfare.drone.kamikaze": "自爆模式",
"des.superbwarfare.drone.warning": "警告!",
"des.superbwarfare.shoot.rings": "环 ",
"container.superbwarfare.reforging_table": "枪械重铸台"
}

View file

@ -19,6 +19,6 @@
},
"result": {
"item": "superbwarfare:hand_grenade",
"count": 2
"count": 4
}
}

View file

@ -22,6 +22,6 @@
},
"result": {
"item": "superbwarfare:rgo_grenade",
"count": 2
"count": 4
}
}