优化智慧芯片
This commit is contained in:
parent
086b6784e8
commit
df1741a955
10 changed files with 77 additions and 31 deletions
|
@ -1,8 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.block.BarbedWireBlock;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.client.particle.BulletDecalOption;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.config.server.ProjectileConfig;
|
||||
import com.atsuishio.superbwarfare.entity.DPSGeneratorEntity;
|
||||
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
||||
|
@ -321,7 +321,7 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
|||
this.setPosRaw(this.getX() + vec.x, this.getY() + vec.y, this.getZ() + vec.z);
|
||||
}
|
||||
|
||||
this.setDeltaMovement(vec.x, vec.y - 0.02, vec.z);
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(0, -0.05, 0));
|
||||
|
||||
if (this.tickCount > (fireLevel > 0 ? 10 : 40)) {
|
||||
this.discard();
|
||||
|
|
|
@ -60,6 +60,7 @@ import software.bernie.geckolib.animation.AnimationProcessor;
|
|||
import software.bernie.geckolib.cache.object.GeoBone;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
||||
public class ClientEventHandler {
|
||||
|
@ -724,7 +725,7 @@ public class ClientEventHandler {
|
|||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
PacketDistributor.sendToServer(new ShootMessage(gunSpread, zoom));
|
||||
PacketDistributor.sendToServer(new ShootMessage(gunSpread, zoom, entity != null ? entity.getUUID() : UUID.randomUUID()));
|
||||
fireRecoilTime = 10;
|
||||
|
||||
var gunRecoilY = data.recoilY() * 10;
|
||||
|
@ -1491,14 +1492,17 @@ public class ClientEventHandler {
|
|||
ClientEventHandler.entity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (intelligentChipLevel - 1), 16 / customZoom);
|
||||
}
|
||||
if (entity != null && entity.isAlive()) {
|
||||
Vec3 toVec = getVec3(event, player);
|
||||
Vec3 targetVec = new Vec3(Mth.lerp(event.getPartialTick(), entity.xo, entity.getX()), Mth.lerp(event.getPartialTick(), entity.yo + entity.getEyeHeight(), entity.getEyeY()), Mth.lerp(event.getPartialTick(), entity.zo, entity.getZ()));
|
||||
Vec3 playerVec = new Vec3(Mth.lerp(event.getPartialTick(), player.xo - 0.1 * player.getViewVector(1).x, player.getX() - 0.1 * player.getViewVector(1).x),
|
||||
Mth.lerp(event.getPartialTick(), player.yo + player.getEyeHeight() - 0.1 * player.getViewVector(1).y, player.getEyeY() - 0.1 * player.getViewVector(1).y),
|
||||
Mth.lerp(event.getPartialTick(), player.zo - 0.1 * player.getViewVector(1).z, player.getZ() - 0.1 * player.getViewVector(1).z));
|
||||
Vec3 toVec = RangeTool.calculateFiringSolution(playerVec, targetVec, entity.getDeltaMovement(), data.velocity(), 0.03);
|
||||
look(player, toVec);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
entity = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1509,12 +1513,6 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static Vec3 getVec3(ViewportEvent.ComputeFov event, Player player) {
|
||||
Vec3 targetVec = new Vec3(Mth.lerp(event.getPartialTick(), entity.xo, entity.getX()), Mth.lerp(event.getPartialTick(), entity.yo + entity.getEyeHeight(), entity.getEyeY()), Mth.lerp(event.getPartialTick(), entity.zo, entity.getZ()));
|
||||
Vec3 playerVec = new Vec3(Mth.lerp(event.getPartialTick(), player.xo, player.getX()), Mth.lerp(event.getPartialTick(), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(event.getPartialTick(), player.zo, player.getZ()));
|
||||
return playerVec.vectorTo(targetVec);
|
||||
}
|
||||
|
||||
public static void look(Player player, Vec3 pTarget) {
|
||||
double d0 = pTarget.x;
|
||||
double d1 = pTarget.y;
|
||||
|
@ -1522,9 +1520,6 @@ public class ClientEventHandler {
|
|||
double d3 = Math.sqrt(d0 * d0 + d2 * d2);
|
||||
player.setXRot(Mth.wrapDegrees((float) (-(Mth.atan2(d1, d3) * 57.2957763671875))));
|
||||
player.setYRot(Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F));
|
||||
player.setYHeadRot(player.getYRot());
|
||||
player.xRotO = player.getXRot();
|
||||
player.yRotO = player.getYRot();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.atsuishio.superbwarfare.init.ModSounds;
|
|||
import com.atsuishio.superbwarfare.item.CustomRendererItem;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.tools.RangeTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
|
@ -62,6 +63,8 @@ import java.util.*;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.EntityFindUtil.findEntity;
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||
public abstract class GunItem extends Item implements CustomRendererItem, GeoItem {
|
||||
|
||||
|
@ -510,7 +513,7 @@ public abstract class GunItem extends Item implements CustomRendererItem, GeoIte
|
|||
/**
|
||||
* 服务端处理开火
|
||||
*/
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom) {
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom, UUID uuid) {
|
||||
if (!data.hasEnoughAmmoToShoot(player)) return;
|
||||
|
||||
// 开火前事件
|
||||
|
@ -521,7 +524,7 @@ public abstract class GunItem extends Item implements CustomRendererItem, GeoIte
|
|||
|
||||
// 生成所有子弹
|
||||
for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) {
|
||||
if (!shootBullet(player, data, spread, zoom)) return;
|
||||
if (!shootBullet(player, data, spread, zoom, uuid)) return;
|
||||
}
|
||||
|
||||
// 添加热量
|
||||
|
@ -603,7 +606,7 @@ public abstract class GunItem extends Item implements CustomRendererItem, GeoIte
|
|||
*
|
||||
* @return 是否发射成功
|
||||
*/
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom, UUID uuid) {
|
||||
var stack = data.stack;
|
||||
var level = player.level();
|
||||
|
||||
|
@ -686,6 +689,19 @@ public abstract class GunItem extends Item implements CustomRendererItem, GeoIte
|
|||
var y = player.getLookAngle().y + 0.001f;
|
||||
var z = player.getLookAngle().z;
|
||||
|
||||
if (zoom && !player.isShiftKeyDown()) {
|
||||
Entity target = findEntity(player.level(), String.valueOf(uuid));
|
||||
int intelligentChipLevel = GunData.from(stack).perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
if (intelligentChipLevel > 0 && target != null) {
|
||||
Vec3 targetVec = target.getEyePosition();
|
||||
Vec3 playerVec = player.getEyePosition();
|
||||
Vec3 toVec = RangeTool.calculateFiringSolution(playerVec, targetVec, Vec3.ZERO, data.velocity(), 0.03);
|
||||
x = toVec.x;
|
||||
y = toVec.y;
|
||||
z = toVec.z;
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Projectile projectile) {
|
||||
projectile.shoot(x, y, z, velocity, (float) spread);
|
||||
} else {
|
||||
|
|
|
@ -48,6 +48,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class JavelinItem extends GunItem {
|
||||
|
@ -247,7 +248,7 @@ public class JavelinItem extends GunItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom) {
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom, UUID uuid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class M79Item extends GunItem {
|
||||
|
@ -96,8 +97,9 @@ public class M79Item extends GunItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
|
||||
if (!super.shootBullet(player, data, spread, zoom)) return false;
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom, UUID uuid) {
|
||||
if (data.reloading()) return false;
|
||||
if (!super.shootBullet(player, data, spread, zoom, uuid)) return false;
|
||||
|
||||
ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
|
||||
player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -119,8 +120,9 @@ public class RpgItem extends GunItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
|
||||
if (!super.shootBullet(player, data, spread, zoom)) return false;
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom, UUID uuid) {
|
||||
if (data.reloading()) return false;
|
||||
if (!super.shootBullet(player, data, spread, zoom, uuid)) return false;
|
||||
|
||||
ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
|
||||
player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
|
||||
|
|
|
@ -9,12 +9,14 @@ import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModEnumExtensions;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import com.atsuishio.superbwarfare.tools.RangeTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
@ -31,6 +33,7 @@ import net.minecraft.world.item.ItemDisplayContext;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
|
@ -40,8 +43,11 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.EntityFindUtil.findEntity;
|
||||
|
||||
public class SecondaryCataclysm extends GunItem implements EnergyStorageItem {
|
||||
|
||||
public SecondaryCataclysm() {
|
||||
|
@ -211,7 +217,7 @@ public class SecondaryCataclysm extends GunItem implements EnergyStorageItem {
|
|||
|
||||
// TODO 这玩意能提取吗
|
||||
@Override
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom, UUID uuid) {
|
||||
if (data.reloading()) return false;
|
||||
var stack = data.stack;
|
||||
|
||||
|
@ -241,8 +247,25 @@ public class SecondaryCataclysm extends GunItem implements EnergyStorageItem {
|
|||
|
||||
gunGrenadeEntity.charged(isChargedFire);
|
||||
|
||||
var x = player.getLookAngle().x;
|
||||
var y = player.getLookAngle().y + 0.001f;
|
||||
var z = player.getLookAngle().z;
|
||||
|
||||
if (zoom && !player.isShiftKeyDown()) {
|
||||
Entity target = findEntity(player.level(), String.valueOf(uuid));
|
||||
int intelligentChipLevel = GunData.from(stack).perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
if (intelligentChipLevel > 0 && target != null) {
|
||||
Vec3 targetVec = target.getEyePosition();
|
||||
Vec3 playerVec = player.getEyePosition();
|
||||
Vec3 toVec = RangeTool.calculateFiringSolution(playerVec, targetVec, Vec3.ZERO, (isChargedFire ? 4 : 1) * velocity, 0.05);
|
||||
x = toVec.x;
|
||||
y = toVec.y;
|
||||
z = toVec.z;
|
||||
}
|
||||
}
|
||||
|
||||
gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (isChargedFire ? 4 : 1) * velocity,
|
||||
gunGrenadeEntity.shoot(x, y, z, (isChargedFire ? 4 : 1) * velocity,
|
||||
(float) (zoom ? 0.1 : spread));
|
||||
serverLevel.addFreshEntity(gunGrenadeEntity);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BocekItem extends GunItem {
|
||||
|
@ -142,7 +143,7 @@ public class BocekItem extends GunItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom) {
|
||||
public void onShoot(GunData data, Player player, double spread, boolean zoom, UUID uuid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,7 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TaserItem extends GunItem implements EnergyStorageItem {
|
||||
|
@ -149,7 +150,7 @@ public class TaserItem extends GunItem implements EnergyStorageItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
|
||||
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom, UUID uuid) {
|
||||
var stack = data.stack;
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 5);
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.data.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
@ -11,7 +12,9 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ShootMessage(double spread, boolean zoom) implements CustomPacketPayload {
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShootMessage(double spread, boolean zoom, UUID uuid) implements CustomPacketPayload {
|
||||
|
||||
public static final Type<ShootMessage> TYPE = new Type<>(Mod.loc("shoot"));
|
||||
|
||||
|
@ -20,19 +23,21 @@ public record ShootMessage(double spread, boolean zoom) implements CustomPacketP
|
|||
ShootMessage::spread,
|
||||
ByteBufCodecs.BOOL,
|
||||
ShootMessage::zoom,
|
||||
UUIDUtil.STREAM_CODEC,
|
||||
ShootMessage::uuid,
|
||||
ShootMessage::new
|
||||
);
|
||||
|
||||
public static void handler(final ShootMessage message, final IPayloadContext context) {
|
||||
pressAction(context.player(), message.spread, message.zoom);
|
||||
pressAction(context.player(), message.spread, message.zoom, message.uuid);
|
||||
}
|
||||
|
||||
public static void pressAction(Player player, double spread, boolean zoom) {
|
||||
public static void pressAction(Player player, double spread, boolean zoom, UUID uuid) {
|
||||
var stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
data.item.onShoot(data, player, spread, zoom);
|
||||
data.item.onShoot(data, player, spread, zoom, uuid);
|
||||
|
||||
data.save();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue