实现无人机任意弹药挂载和取回
This commit is contained in:
parent
31fa3ff792
commit
24fb5c99aa
4 changed files with 114 additions and 148 deletions
|
@ -3,14 +3,15 @@ package com.atsuishio.superbwarfare.entity.vehicle;
|
|||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.data.CustomData;
|
||||
import com.atsuishio.superbwarfare.data.drone_attachment.DroneAttachmentData;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.*;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.C4Entity;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.LaserEntity;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.RgoGrenadeEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.Monitor;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
|
||||
import com.atsuishio.superbwarfare.tools.*;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -297,79 +298,40 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (stack.is(ModItems.CROWBAR.get()) && player.isCrouching()) {
|
||||
// 返还物品
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.DRONE.get()));
|
||||
} else if (player.isCrouching()) {
|
||||
if (stack.is(ModItems.CROWBAR.get())) {
|
||||
// 无人机拆除
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.DRONE.get()));
|
||||
|
||||
// TODO 返还弹药
|
||||
// 返还普通弹药
|
||||
for (int index0 = 0; index0 < this.entityData.get(AMMO); index0++) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.RGO_GRENADE.get()));
|
||||
}
|
||||
|
||||
// 返还神风弹药
|
||||
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, this.currentItem);
|
||||
}
|
||||
|
||||
player.getInventory().items.stream().filter(stack_ -> stack_.getItem() == ModItems.MONITOR.get())
|
||||
.forEach(itemStack -> {
|
||||
var tag = NBTTool.getTag(itemStack);
|
||||
if (tag.getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(tag, player);
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.level().isClientSide()) {
|
||||
this.discard();
|
||||
}
|
||||
} else if (stack.getItem() == ModItems.RGO_GRENADE.get() && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||
// TODO 清理 装载普通弹药
|
||||
if (this.entityData.get(AMMO) < 6) {
|
||||
this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
// 返还弹药
|
||||
for (int index0 = 0; index0 < this.entityData.get(AMMO); index0++) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, this.currentItem.copy());
|
||||
}
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
|
||||
player.getInventory().items.stream().filter(stack_ -> stack_.getItem() == ModItems.MONITOR.get())
|
||||
.forEach(itemStack -> {
|
||||
var tag = NBTTool.getTag(itemStack);
|
||||
if (tag.getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(tag, player);
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.level().isClientSide()) {
|
||||
this.discard();
|
||||
}
|
||||
} else {
|
||||
// 返还单个弹药
|
||||
int ammo = this.entityData.get(AMMO);
|
||||
if (ammo > 0) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, this.currentItem.copy());
|
||||
this.entityData.set(AMMO, ammo - 1);
|
||||
if (ammo == 1) {
|
||||
this.entityData.set(ATTACHED_ENTITY, "");
|
||||
this.entityData.set(MAX_AMMO, 1);
|
||||
this.currentItem = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (stack.getItem() instanceof MortarShell && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||
// TODO 清理 迫击炮神风
|
||||
var copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
this.currentItem = copy;
|
||||
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
this.entityData.set(KAMIKAZE_MODE, 1);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
}
|
||||
// } else if (stack.getItem() == ModItems.C4_BOMB.get() && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||
// // C4神风
|
||||
// this.currentItem = new ItemStack(stack.getItem(), 1);
|
||||
//
|
||||
// if (!player.isCreative()) {
|
||||
// stack.shrink(1);
|
||||
// }
|
||||
// this.entityData.set(KAMIKAZE_MODE, 2);
|
||||
// if (player instanceof ServerPlayer serverPlayer) {
|
||||
// serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
// }
|
||||
// } else if (stack.getItem() == ModItems.ROCKET.get() && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||
// // RPG神风
|
||||
// this.currentItem = new ItemStack(stack.getItem(), 1);
|
||||
//
|
||||
// if (!player.isCreative()) {
|
||||
// stack.shrink(1);
|
||||
// }
|
||||
// this.entityData.set(KAMIKAZE_MODE, 3);
|
||||
// if (player instanceof ServerPlayer serverPlayer) {
|
||||
// serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
// }
|
||||
} else {
|
||||
// 自定义挂载
|
||||
var itemID = stack.getItem().toString();
|
||||
|
@ -377,7 +339,9 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
// 是否能挂载该物品
|
||||
if (attachmentData != null && this.entityData.get(AMMO) < attachmentData.count()) {
|
||||
if (this.entityData.get(ATTACHED_ENTITY).equals(attachmentData.entityID)) {
|
||||
if (this.entityData.get(ATTACHED_ENTITY).equals(attachmentData.entityID)
|
||||
&& ItemStack.matches(this.currentItem, stack.copyWithCount(1))
|
||||
) {
|
||||
// 同种物品挂载
|
||||
this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
|
||||
|
||||
|
@ -389,6 +353,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
} else if (this.entityData.get(AMMO) == 0) {
|
||||
// 不同种物品挂载
|
||||
this.currentItem = stack.copyWithCount(1);
|
||||
this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID);
|
||||
// TODO 正确处理和渲染AMMO
|
||||
this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
|
||||
|
@ -609,16 +574,22 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
|
||||
}
|
||||
|
||||
// TODO 清理 神风自爆
|
||||
if (this.entityData.get(KAMIKAZE_MODE) != 0 || !this.entityData.get(ATTACHED_ENTITY).isEmpty()) {
|
||||
kamikazeExplosion(this.entityData.get(KAMIKAZE_MODE));
|
||||
}
|
||||
var attachedEntity = this.entityData.get(ATTACHED_ENTITY);
|
||||
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
// RGO投弹
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
int count = this.entityData.get(AMMO);
|
||||
for (int i = 0; i < count; i++) {
|
||||
droneDrop(controller);
|
||||
if (data != null) {
|
||||
if (data.isKamikaze) {
|
||||
kamikazeExplosion();
|
||||
} else {
|
||||
// TODO 清理 RGO投弹
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
int count = this.entityData.get(AMMO);
|
||||
for (int i = 0; i < count; i++) {
|
||||
droneDrop(controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,71 +617,44 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
super.destroy();
|
||||
}
|
||||
|
||||
private void kamikazeExplosion(int mode) {
|
||||
private void kamikazeExplosion() {
|
||||
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
|
||||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||
|
||||
assert controller != null;
|
||||
Entity mortarShell = new MortarShellEntity(controller, level());
|
||||
// Entity c4 = new C4Entity(controller, level());
|
||||
// Entity rpg = new RpgRocketEntity(controller, level());
|
||||
CustomExplosion explosion;
|
||||
|
||||
// TODO 清理这一坨
|
||||
CustomExplosion explosion = switch (mode) {
|
||||
case 1 -> new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), mortarShell, attacker), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(),
|
||||
this.getX(), this.getY(), this.getZ(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
||||
// 挂载实体的数据
|
||||
var attachedEntity = this.entityData.get(ATTACHED_ENTITY);
|
||||
if (attachedEntity.isEmpty()) return;
|
||||
|
||||
// case 2 -> new CustomExplosion(this.level(), this,
|
||||
// ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), c4, attacker), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
|
||||
// this.getX(), this.getY(), this.getZ(), ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
||||
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
if (data == null) return;
|
||||
|
||||
// case 3 -> new CustomExplosion(this.level(), this,
|
||||
// ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), rpg, attacker), ExplosionConfig.RPG_EXPLOSION_DAMAGE.get(),
|
||||
// this.getX(), this.getY(), this.getZ(), ExplosionConfig.RPG_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
||||
var bomb = EntityType.byString(attachedEntity).map(entityType ->
|
||||
entityType.create(this.level())
|
||||
).orElse(null);
|
||||
if (bomb == null) return;
|
||||
|
||||
default -> null;
|
||||
};
|
||||
|
||||
// 自定义实体挂载
|
||||
if (explosion == null) {
|
||||
var attachedEntity = this.entityData.get(ATTACHED_ENTITY);
|
||||
if (attachedEntity.isEmpty()) return;
|
||||
|
||||
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
if (data == null) return;
|
||||
|
||||
if (data.isKamikaze) {
|
||||
var bomb = EntityType.byString(attachedEntity).map(entityType ->
|
||||
entityType.create(this.level())
|
||||
).orElse(null);
|
||||
if (bomb == null) return;
|
||||
|
||||
explosion = new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), bomb, attacker), data.explosionDamage,
|
||||
this.getX(), this.getY(), this.getZ(), data.explosionRadius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
||||
} else {
|
||||
// TODO 非神风自爆
|
||||
return;
|
||||
}
|
||||
}
|
||||
explosion = new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), bomb, attacker), data.explosionDamage,
|
||||
this.getX(), this.getY(), this.getZ(), data.explosionRadius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
||||
|
||||
explosion.explode();
|
||||
EventHooks.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
if (mode == 1) {
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
|
||||
|
||||
if (this.currentItem.getItem() instanceof MortarShell) {
|
||||
this.createAreaCloud(this.currentItem.get(DataComponents.POTION_CONTENTS), this.level(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == 2 || mode == 3) {
|
||||
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
// TODO 药水迫击炮炮弹
|
||||
// if (mode == 1) {
|
||||
// ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
//
|
||||
// if (this.currentItem.getItem() instanceof MortarShell) {
|
||||
// this.createAreaCloud(this.currentItem.get(DataComponents.POTION_CONTENTS), this.level(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void createAreaCloud(PotionContents potion, Level level, int duration, float radius) {
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"ItemID": "superbwarfare:medium_aerial_bomb",
|
||||
"EntityID": "superbwarfare:mk_82",
|
||||
"Offset": [
|
||||
0,
|
||||
-0.1,
|
||||
0
|
||||
],
|
||||
"Scale": [
|
||||
0.4,
|
||||
0.4,
|
||||
0.4
|
||||
]
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"ItemID": "superbwarfare:mortar_shell",
|
||||
"EntityID": "superbwarfare:mortar_shell",
|
||||
"HitDamage": 200,
|
||||
"ExplosionDamage": 160,
|
||||
"ExplosionRadius": 9,
|
||||
"Offset": [
|
||||
0,
|
||||
0.02,
|
||||
0.25
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"ItemID": "superbwarfare:rgo_grenade",
|
||||
"EntityID": "superbwarfare:rgo_grenade",
|
||||
"IsKamikaze": false,
|
||||
"Count": 6,
|
||||
"HitDamage": 270,
|
||||
"ExplosionDamage": 130,
|
||||
"ExplosionRadius": 10,
|
||||
"Offset": [
|
||||
0,
|
||||
-0.04,
|
||||
0.025
|
||||
],
|
||||
"Rotation": [
|
||||
90,
|
||||
90,
|
||||
0
|
||||
],
|
||||
"Scale": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
]
|
||||
}
|
Loading…
Add table
Reference in a new issue