添加发射粒子效果,修复右键交互
This commit is contained in:
parent
1e56aad393
commit
f163ce1e5a
3 changed files with 54 additions and 30 deletions
|
@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.client.overlay;
|
|||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Type63Entity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.RangeTool;
|
||||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||
|
@ -16,6 +15,9 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.SHOOT_PITCH;
|
||||
import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.SHOOT_YAW;
|
||||
|
||||
public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||
|
||||
public static final ResourceLocation ID = Mod.loc("type_63_info");
|
||||
|
@ -33,13 +35,13 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
|||
}
|
||||
if (lookingEntity instanceof Type63Entity type63Entity) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
||||
.append(Component.literal(FormatTool.format2D(VehicleEntity.getXRotFromVector(type63Entity.getShootVector(deltaTracker.getGameTimeDeltaPartialTick(true))), "°"))),
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_PITCH), "°"))),
|
||||
screenWidth / 2 - 90, screenHeight / 2 - 26, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
|
||||
.append(Component.literal(FormatTool.format2D(-VehicleEntity.getYRotFromVector(type63Entity.getShootVector(deltaTracker.getGameTimeDeltaPartialTick(true))), "°"))),
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_YAW), "°"))),
|
||||
screenWidth / 2 - 90, screenHeight / 2 - 16, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.range")
|
||||
.append(Component.literal(FormatTool.format1D((int) RangeTool.getRange(VehicleEntity.getXRotFromVector(type63Entity.getShootVector(deltaTracker.getGameTimeDeltaPartialTick(true))), 10, 0.05), "m"))),
|
||||
.append(Component.literal(FormatTool.format1D((int) RangeTool.getRange(type63Entity.getEntityData().get(SHOOT_PITCH), 10, 0.05), "m"))),
|
||||
screenWidth / 2 - 90, screenHeight / 2 - 6, -1, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
|||
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModSerializers;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
|
@ -16,6 +17,7 @@ import com.atsuishio.superbwarfare.tools.OBB;
|
|||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import com.atsuishio.superbwarfare.tools.VectorTool;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
|
@ -36,8 +38,8 @@ import net.minecraft.world.phys.Vec3;
|
|||
import net.neoforged.neoforge.event.EventHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Math;
|
||||
import org.joml.*;
|
||||
import org.joml.Math;
|
||||
import software.bernie.geckolib.animatable.GeoEntity;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.AnimatableManager;
|
||||
|
@ -50,6 +52,9 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
public static final EntityDataAccessor<Float> SHOOT_PITCH = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> SHOOT_YAW = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<List<Integer>> LOADED_AMMO = SynchedEntityData.defineId(Type63Entity.class, ModSerializers.INT_LIST_SERIALIZER.get());
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
|
@ -106,6 +111,8 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
builder.define(PITCH, 0F)
|
||||
.define(YAW, 0F)
|
||||
.define(SHOOT_PITCH, 0F)
|
||||
.define(SHOOT_YAW, 0F)
|
||||
.define(LOADED_AMMO, list);
|
||||
}
|
||||
|
||||
|
@ -162,14 +169,14 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
if (stack.getItem() instanceof MediumRocketItem) {
|
||||
for (int i = 0; i < this.barrel.length; i++) {
|
||||
if (OBB.getLookingObb(player, player.entityInteractionRange()) == this.barrel[i] && items.get(i).isEmpty()) {
|
||||
if (OBB.getLookingObb(player, player.entityInteractionRange()) == this.barrel[i] && items.get(i).isEmpty() && level() instanceof ServerLevel) {
|
||||
this.setItem(i, stack.copyWithCount(1));
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
setChanged();
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +194,7 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
} else {
|
||||
// 撬棍发射
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (items.get(i).getItem() instanceof MediumRocketItem) {
|
||||
if (items.get(i).getItem() instanceof MediumRocketItem && cooldown == 0) {
|
||||
shoot(player, i);
|
||||
items.set(i, ItemStack.EMPTY);
|
||||
setChanged();
|
||||
|
@ -204,6 +211,7 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
public void interactEvent(Vec3 vec3) {
|
||||
if (level() instanceof ServerLevel serverLevel) {
|
||||
interactionTick++;
|
||||
interactionTick += 0.5;
|
||||
if (tickCount % 2 == 0) {
|
||||
serverLevel.playSound(null, vec3.x, vec3.y, vec3.z, ModSounds.HAND_WHEEL_ROT.get(), SoundSource.PLAYERS, 1f, random.nextFloat() * 0.1f + 0.9f);
|
||||
}
|
||||
|
@ -211,27 +219,34 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
}
|
||||
|
||||
public void shoot(Player player, int i) {
|
||||
if (level() instanceof ServerLevel server) {
|
||||
ItemStack stack = items.get(i);
|
||||
ItemStack stack = items.get(i);
|
||||
|
||||
if (!(stack.getItem() instanceof MediumRocketItem rocketItem)) {
|
||||
return;
|
||||
if (!(stack.getItem() instanceof MediumRocketItem rocketItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
OBB obb = this.barrel[i];
|
||||
Vec3 shootPos = new Vec3(obb.center());
|
||||
|
||||
MediumRocketEntity entityToSpawn = rocketItem.createProjectile(level(), shootPos);
|
||||
entityToSpawn.setOwner(player);
|
||||
entityToSpawn.shoot(getShootVector(1).x, getShootVector(1).y, getShootVector(1).z, 10, (float) 0.5);
|
||||
level().addFreshEntity(entityToSpawn);
|
||||
level().playSound(null, shootPos.x, shootPos.y, shootPos.z, ModSounds.MEDIUM_ROCKET_FIRE.get(), SoundSource.PLAYERS, 4f, random.nextFloat() * 0.1f + 0.95f);
|
||||
|
||||
cooldown = 10;
|
||||
if (level() instanceof ServerLevel serverLevel) {
|
||||
for (int p = 0; p < 15; p++) {
|
||||
Vec3 pPos = shootPos.add(getShootVector(1).scale(p * -0.5));
|
||||
serverLevel.sendParticles(ParticleTypes.SMOKE, pPos.x, pPos.y, pPos.z, 3, 0.05, 0.05, 0.05, 0.007);
|
||||
serverLevel.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, pPos.x, pPos.y, pPos.z, 3, 0.05, 0.05, 0.05, 0.007);
|
||||
serverLevel.sendParticles(ParticleTypes.FLAME, pPos.x, pPos.y, pPos.z, 2, 0.05, 0.05, 0.05, 0.007);
|
||||
|
||||
Vec3 pPos2 = shootPos.add(getShootVector(1).scale(-p));
|
||||
serverLevel.sendParticles(ParticleTypes.SMOKE, pPos2.x, pPos2.y, pPos2.z, 3, 0.05, 0.05, 0.05, 0.007);
|
||||
serverLevel.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, pPos2.x, pPos2.y, pPos2.z, 3, 0.05, 0.05, 0.05, 0.007);
|
||||
serverLevel.sendParticles(ParticleTypes.FLAME, pPos2.x, pPos2.y, pPos2.z, 2, 0.05, 0.05, 0.05, 0.007);
|
||||
}
|
||||
|
||||
OBB obb = this.barrel[i];
|
||||
Vec3 shootPos = new Vec3(obb.center());
|
||||
|
||||
MediumRocketEntity entityToSpawn = rocketItem.createProjectile(server, shootPos);
|
||||
entityToSpawn.setOwner(player);
|
||||
entityToSpawn.shoot(getShootVector(1).x, getShootVector(1).y, getShootVector(1).z, 10, (float) 0.25);
|
||||
server.addFreshEntity(entityToSpawn);
|
||||
|
||||
server.playSound(null, shootPos.x, shootPos.y, shootPos.z, ModSounds.MEDIUM_ROCKET_FIRE.get(), SoundSource.PLAYERS, 4f, random.nextFloat() * 0.1f + 0.95f);
|
||||
|
||||
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4,
|
||||
// 0.007);
|
||||
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,11 +277,17 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
this.setDeltaMovement(this.getDeltaMovement().multiply(f1, 0.85, f1));
|
||||
}
|
||||
|
||||
// setTurretYRot(getTurretYRot() + 1);
|
||||
// setTurretXRot(getTurretXRot() + 1);
|
||||
if (cooldown > 0) {
|
||||
cooldown--;
|
||||
}
|
||||
|
||||
interactionTick *= 0.96;
|
||||
|
||||
if (level() instanceof ServerLevel) {
|
||||
entityData.set(SHOOT_PITCH, (float) VehicleEntity.getXRotFromVector(getShootVector(1)));
|
||||
entityData.set(SHOOT_YAW, (float) -VehicleEntity.getYRotFromVector(getShootVector(1)));
|
||||
}
|
||||
|
||||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
|
@ -341,6 +362,7 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
public int cooldown;
|
||||
|
||||
@Override
|
||||
public ResourceLocation getVehicleIcon() {
|
||||
|
|
|
@ -126,7 +126,7 @@ public class ModItems {
|
|||
public static final DeferredHolder<Item, SmallRocketItem> SMALL_ROCKET = AMMO.register("small_rocket", SmallRocketItem::new);
|
||||
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_AP = AMMO.register("medium_rocket_ap", () -> new MediumRocketItem(500, 6, 100, 0, 0, MediumRocketEntity.Type.AP, 0));
|
||||
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_HE = AMMO.register("medium_rocket_he", () -> new MediumRocketItem(200, 12, 200, 0.2f, 40, MediumRocketEntity.Type.HE, 0));
|
||||
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_CM = AMMO.register("medium_rocket_cm", () -> new MediumRocketItem(300, 12, 300, 0, 0, MediumRocketEntity.Type.CM, 50));
|
||||
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_CM = AMMO.register("medium_rocket_cm", () -> new MediumRocketItem(300, 12, 300, 0, 0, MediumRocketEntity.Type.CM, 20));
|
||||
public static final DeferredHolder<Item, WireGuideMissileItem> WIRE_GUIDE_MISSILE = AMMO.register("wire_guide_missile", WireGuideMissileItem::new);
|
||||
public static final DeferredHolder<Item, AgmItem> AGM = AMMO.register("agm", AgmItem::new);
|
||||
public static final DeferredHolder<Item, SwarmDroneItem> SWARM_DRONE = AMMO.register("swarm_drone", SwarmDroneItem::new);
|
||||
|
|
Loading…
Add table
Reference in a new issue