允许无人机使用药水弹
This commit is contained in:
parent
77c763a7d8
commit
a13297bd7d
1 changed files with 52 additions and 17 deletions
|
@ -12,6 +12,7 @@ import com.atsuishio.superbwarfare.init.ModEntities;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.item.Monitor;
|
import com.atsuishio.superbwarfare.item.Monitor;
|
||||||
|
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
|
||||||
import com.atsuishio.superbwarfare.tools.ChunkLoadTool;
|
import com.atsuishio.superbwarfare.tools.ChunkLoadTool;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
|
@ -43,6 +44,9 @@ import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.entity.projectile.Projectile;
|
import net.minecraft.world.entity.projectile.Projectile;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.alchemy.Potion;
|
||||||
|
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||||
|
import net.minecraft.world.item.alchemy.Potions;
|
||||||
import net.minecraft.world.level.Explosion;
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
|
@ -79,6 +83,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
public int collisionCoolDown;
|
public int collisionCoolDown;
|
||||||
public double lastTickSpeed;
|
public double lastTickSpeed;
|
||||||
public double lastTickVerticalSpeed;
|
public double lastTickVerticalSpeed;
|
||||||
|
public ItemStack currentItem = ItemStack.EMPTY;
|
||||||
|
|
||||||
public float pitch;
|
public float pitch;
|
||||||
public float pitchO;
|
public float pitchO;
|
||||||
|
@ -156,6 +161,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
compound.putString("Controller", this.entityData.get(CONTROLLER));
|
compound.putString("Controller", this.entityData.get(CONTROLLER));
|
||||||
compound.putInt("Ammo", this.entityData.get(AMMO));
|
compound.putInt("Ammo", this.entityData.get(AMMO));
|
||||||
compound.putInt("KamikazeMode", this.entityData.get(KAMIKAZE_MODE));
|
compound.putInt("KamikazeMode", this.entityData.get(KAMIKAZE_MODE));
|
||||||
|
compound.put("Item", this.currentItem.save(compound));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -174,6 +180,8 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
this.entityData.set(AMMO, compound.getInt("Ammo"));
|
this.entityData.set(AMMO, compound.getInt("Ammo"));
|
||||||
if (compound.contains("KamikazeMode"))
|
if (compound.contains("KamikazeMode"))
|
||||||
this.entityData.set(KAMIKAZE_MODE, compound.getInt("KamikazeMode"));
|
this.entityData.set(KAMIKAZE_MODE, compound.getInt("KamikazeMode"));
|
||||||
|
if (compound.contains("Item"))
|
||||||
|
this.currentItem = ItemStack.of(compound.getCompound("Item"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -265,12 +273,13 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
int maxDistance = playerTicketManager.viewDistance;
|
int maxDistance = playerTicketManager.viewDistance;
|
||||||
|
|
||||||
if (this.position().vectorTo(player.position()).horizontalDistance() > maxDistance * 16) {
|
if (this.position().vectorTo(player.position()).horizontalDistance() > maxDistance * 16) {
|
||||||
upInputDown = false;
|
this.upInputDown = false;
|
||||||
downInputDown = false;
|
this.downInputDown = false;
|
||||||
forwardInputDown = false;
|
this.forwardInputDown = false;
|
||||||
backInputDown = false;
|
this.backInputDown = false;
|
||||||
leftInputDown = false;
|
this.leftInputDown = false;
|
||||||
rightInputDown = false;
|
this.rightInputDown = false;
|
||||||
|
|
||||||
Vec3 toVec = position().vectorTo(player.position()).normalize();
|
Vec3 toVec = position().vectorTo(player.position()).normalize();
|
||||||
setDeltaMovement(getDeltaMovement().add(new Vec3(toVec.x, 0, toVec.z).scale(0.2)));
|
setDeltaMovement(getDeltaMovement().add(new Vec3(toVec.x, 0, toVec.z).scale(0.2)));
|
||||||
}
|
}
|
||||||
|
@ -338,20 +347,20 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返还神风弹药
|
// 返还神风弹药
|
||||||
if (this.entityData.get(KAMIKAZE_MODE) == 1) {
|
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
|
||||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_SHELL.get()));
|
ItemHandlerHelper.giveItemToPlayer(player, this.currentItem);
|
||||||
} else if (this.entityData.get(KAMIKAZE_MODE) == 2) {
|
|
||||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.C4_BOMB.get()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().items.stream().filter(stack_ -> stack_.getItem() == ModItems.MONITOR.get())
|
player.getInventory().items.stream().filter(stack_ -> stack_.getItem() == ModItems.MONITOR.get())
|
||||||
.forEach(stack_ -> {
|
.forEach(itemStack -> {
|
||||||
if (stack_.getOrCreateTag().getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
if (itemStack.getOrCreateTag().getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||||
Monitor.disLink(stack_, player);
|
Monitor.disLink(itemStack, player);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.level().isClientSide()) this.discard();
|
if (!this.level().isClientSide()) {
|
||||||
|
this.discard();
|
||||||
|
}
|
||||||
} else if (stack.getItem() == ModItems.RGO_GRENADE.get() && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
} else if (stack.getItem() == ModItems.RGO_GRENADE.get() && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||||
// 装载普通弹药
|
// 装载普通弹药
|
||||||
if (this.entityData.get(AMMO) < 6) {
|
if (this.entityData.get(AMMO) < 6) {
|
||||||
|
@ -363,17 +372,24 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (stack.getItem() == ModItems.MORTAR_SHELL.get() && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
} else if (stack.getItem() instanceof MortarShell && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||||
// 迫击炮神风
|
// 迫击炮神风
|
||||||
|
var copy = stack.copy();
|
||||||
|
copy.setCount(1);
|
||||||
|
this.currentItem = copy;
|
||||||
|
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
}
|
}
|
||||||
this.entityData.set(KAMIKAZE_MODE, 1);
|
this.entityData.set(KAMIKAZE_MODE, 1);
|
||||||
|
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
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) {
|
} else if (stack.getItem() == ModItems.C4_BOMB.get() && this.entityData.get(AMMO) == 0 && this.entityData.get(KAMIKAZE_MODE) == 0) {
|
||||||
// C4神风
|
// C4神风
|
||||||
|
this.currentItem = new ItemStack(stack.getItem(), 1);
|
||||||
|
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
}
|
}
|
||||||
|
@ -591,6 +607,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
explosion.finalizeExplosion(false);
|
explosion.finalizeExplosion(false);
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||||
|
|
||||||
|
if (this.currentItem.getItem() instanceof MortarShell) {
|
||||||
|
this.createAreaCloud(PotionUtils.getPotion(this.currentItem), this.level(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == 2) {
|
if (mode == 2) {
|
||||||
|
@ -598,6 +618,21 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createAreaCloud(Potion potion, Level level, int duration, float radius) {
|
||||||
|
if (potion == Potions.EMPTY) return;
|
||||||
|
|
||||||
|
AreaEffectCloud cloud = new AreaEffectCloud(level, this.getX() + 0.75 * getDeltaMovement().x, this.getY() + 0.5 * getBbHeight() + 0.75 * getDeltaMovement().y, this.getZ() + 0.75 * getDeltaMovement().z);
|
||||||
|
cloud.setPotion(potion);
|
||||||
|
cloud.setDuration(duration);
|
||||||
|
cloud.setRadius(radius);
|
||||||
|
|
||||||
|
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||||
|
if (controller != null) {
|
||||||
|
cloud.setOwner(controller);
|
||||||
|
}
|
||||||
|
level.addFreshEntity(cloud);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNoGravity() {
|
public boolean isNoGravity() {
|
||||||
return super.isNoGravity();
|
return super.isNoGravity();
|
||||||
|
|
Loading…
Add table
Reference in a new issue