综合铲雪

This commit is contained in:
Light_Quanta 2025-03-04 01:15:33 +08:00
parent dcd40da7f0
commit 2a598c81a0
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
10 changed files with 183 additions and 113 deletions

View file

@ -35,7 +35,6 @@ import org.joml.Math;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*;
import static com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity.WEAPON_TYPE;
import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.COAX_HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.COAX_HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.AMMO; import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.AMMO;
@ -105,7 +104,7 @@ public class VehicleHudOverlay {
if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))
&& !(iVehicle instanceof ICannonEntity && !(iVehicle instanceof ICannonEntity
|| (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getEntityData().get(WEAPON_TYPE) == 1)) || (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponType() == 1))
) { ) {
event.getGuiGraphics().drawString( event.getGuiGraphics().drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
@ -157,7 +156,7 @@ public class VehicleHudOverlay {
return Component.translatable("des.superbwarfare.tips.ammo_type.cal50").getString(); return Component.translatable("des.superbwarfare.tips.ammo_type.cal50").getString();
} }
if (iVehicle instanceof Ah6Entity ah6Entity) { if (iVehicle instanceof Ah6Entity ah6Entity) {
if (ah6Entity.getEntityData().get(WEAPON_TYPE) == 0) { if (ah6Entity.getWeaponType() == 0) {
return Component.translatable("des.superbwarfare.tips.ammo_type.20mm_cannon").getString(); return Component.translatable("des.superbwarfare.tips.ammo_type.20mm_cannon").getString();
} else { } else {
return Component.translatable("des.superbwarfare.tips.ammo_type.rocket").getString(); return Component.translatable("des.superbwarfare.tips.ammo_type.rocket").getString();

View file

@ -211,10 +211,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
return AmmoType.HEAVY.get(stack) > 0; return AmmoType.HEAVY.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.HEAVY::get).sum() }).mapToInt(AmmoType.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get());
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum();
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).mapToInt(ItemStack::getCount).sum() > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) { if ((countItem(ModItems.ROCKET_70.get()) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) {
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1); this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1);
reloadCoolDown = 25; reloadCoolDown = 25;
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
@ -223,7 +222,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
} }
if (this.getEntityData().get(WEAPON_TYPE) == 0) { if (this.getWeaponType() == 0) {
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);
} else { } else {
this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET)); this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET));
@ -539,7 +538,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
Vector4f worldPositionRight; Vector4f worldPositionRight;
Vector4f worldPositionLeft; Vector4f worldPositionLeft;
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
if (this.cannotFire) return; if (this.cannotFire) return;
x = 1.15f; x = 1.15f;
@ -616,7 +615,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ())); ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ()));
} }
} }
} else if (entityData.get(WEAPON_TYPE) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) { } else if (getWeaponType() == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) {
x = 1.7f; x = 1.7f;
y = 0.62f - 1.45f; y = 0.62f - 1.45f;
z = 0.8f; z = 0.8f;
@ -712,9 +711,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override @Override
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
return this.entityData.get(AMMO) > 0; return this.entityData.get(AMMO) > 0;
} }
return false; return false;
@ -767,8 +766,8 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override @Override
public void changeWeapon(int scroll) { public void changeWeapon(int scroll) {
var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; var type = (getWeaponType() + scroll + 2) % 2;
entityData.set(WEAPON_TYPE, type); setWeaponType(type);
var sound = switch (type) { var sound = switch (type) {
case 0 -> ModSounds.INTO_MISSILE.get(); case 0 -> ModSounds.INTO_MISSILE.get();
@ -784,6 +783,11 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
return entityData.get(WEAPON_TYPE); return entityData.get(WEAPON_TYPE);
} }
@Override
public void setWeaponType(int type) {
entityData.set(WEAPON_TYPE, type);
}
@Override @Override
public ResourceLocation getVehicleIcon() { public ResourceLocation getVehicleIcon() {
return ModUtils.loc("textures/vehicle_icon/ah_6_icon.png"); return ModUtils.loc("textures/vehicle_icon/ah_6_icon.png");

View file

@ -274,10 +274,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
return AmmoType.RIFLE.get(stack) > 0; return AmmoType.RIFLE.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.RIFLE::get).sum() }).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get());
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum();
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.WIRE_GUIDE_MISSILE.get())).mapToInt(ItemStack::getCount).sum() > 0 if ((countItem(ModItems.WIRE_GUIDE_MISSILE.get()) > 0
|| player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
&& this.reloadCoolDown <= 0 && this.getEntityData().get(LOADED_MISSILE) < 1) { && this.reloadCoolDown <= 0 && this.getEntityData().get(LOADED_MISSILE) < 1) {
this.entityData.set(LOADED_MISSILE, this.getEntityData().get(LOADED_MISSILE) + 1); this.entityData.set(LOADED_MISSILE, this.getEntityData().get(LOADED_MISSILE) + 1);
@ -288,9 +287,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
this.level().playSound(null, this, ModSounds.BMP_MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.BMP_MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
} }
if (this.getEntityData().get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum()); this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get()));
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);
} else { } else {
this.entityData.set(AMMO, this.getEntityData().get(LOADED_MISSILE)); this.entityData.set(AMMO, this.getEntityData().get(LOADED_MISSILE));
@ -308,7 +307,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override @Override
public void vehicleShoot(Player player) { public void vehicleShoot(Player player) {
Matrix4f transform = getBarrelTransform(); Matrix4f transform = getBarrelTransform();
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
if (this.cannotFire) return; if (this.cannotFire) return;
float x = -0.1125f; float x = -0.1125f;
float y = 0.174025f; float y = 0.174025f;
@ -349,7 +348,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
this.entityData.set(HEAT, this.entityData.get(HEAT) + 7); this.entityData.set(HEAT, this.entityData.get(HEAT) + 7);
this.entityData.set(FIRE_ANIM, 3); this.entityData.set(FIRE_ANIM, 3);
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
if (this.cannotFireCoax) return; if (this.cannotFireCoax) return;
float x = 0.1125f; float x = 0.1125f;
float y = 0.174025f; float y = 0.174025f;
@ -397,7 +396,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1); serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1);
} }
} }
} else if (entityData.get(WEAPON_TYPE) == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) { } else if (getWeaponType() == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) {
Matrix4f transformT = getBarrelTransform(); Matrix4f transformT = getBarrelTransform();
Vector4f worldPosition = transformPosition(transformT, 0, 1, 0); Vector4f worldPosition = transformPosition(transformT, 0, 1, 0);
@ -682,11 +681,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
} }
private PlayState firePredicate(AnimationState<Bmp2Entity> event) { private PlayState firePredicate(AnimationState<Bmp2Entity> event) {
if (this.entityData.get(FIRE_ANIM) > 1 && entityData.get(WEAPON_TYPE) == 0) { if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType() == 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire"));
} }
if (this.entityData.get(FIRE_ANIM) > 0 && entityData.get(WEAPON_TYPE) == 1) { if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType() == 1) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2"));
} }
@ -720,9 +719,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override @Override
public int mainGunRpm() { public int mainGunRpm() {
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
return 250; return 250;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
return 750; return 750;
} }
return 250; return 250;
@ -730,11 +729,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override @Override
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax; return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
} else if (entityData.get(WEAPON_TYPE) == 2) { } else if (getWeaponType() == 2) {
return (this.entityData.get(LOADED_MISSILE) > 0); return (this.entityData.get(LOADED_MISSILE) > 0);
} }
return false; return false;
@ -762,8 +761,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override @Override
public void changeWeapon(int scroll) { public void changeWeapon(int scroll) {
var type = (entityData.get(WEAPON_TYPE) + scroll + 3) % 3; var type = (getWeaponType() + scroll + 3) % 3;
entityData.set(WEAPON_TYPE, type); setWeaponType(type);
var sound = switch (type) { var sound = switch (type) {
case 0, 2 -> ModSounds.INTO_MISSILE.get(); case 0, 2 -> ModSounds.INTO_MISSILE.get();
@ -779,6 +778,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
return entityData.get(WEAPON_TYPE); return entityData.get(WEAPON_TYPE);
} }
@Override
public void setWeaponType(int type) {
entityData.set(WEAPON_TYPE, type);
}
@Override @Override
public ResourceLocation getVehicleIcon() { public ResourceLocation getVehicleIcon() {
return ModUtils.loc("textures/vehicle_icon/bmp2_icon.png"); return ModUtils.loc("textures/vehicle_icon/bmp2_icon.png");

View file

@ -12,10 +12,12 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HasCustomInventoryScreen; import net.minecraft.world.entity.HasCustomInventoryScreen;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.entity.vehicle.ContainerEntity;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.gameevent.GameEvent;
@ -23,6 +25,7 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.InvWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
@ -129,6 +132,70 @@ public class ContainerMobileVehicleEntity extends MobileVehicleEntity implements
return this.items; return this.items;
} }
/**
* 计算当前载具内指定物品的数量
*
* @param item 物品类型
* @return 物品数量
*/
public int countItem(@NotNull Item item) {
return this.getItemStacks().stream()
.filter(stack -> stack.is(item))
.mapToInt(ItemStack::getCount)
.sum();
}
/**
* 消耗载具内指定物品
*
* @param item 物品类型
* @param count 要消耗的数量
* @return 成功消耗的物品数量
*/
public int consumeItem(Item item, int count) {
int initialCount = count;
var items = this.getItemStacks().stream().filter(stack -> stack.is(item)).toList();
for (var stack : items) {
var countToShrink = Math.min(stack.getCount(), count);
stack.shrink(countToShrink);
count -= countToShrink;
if (count <= 0) break;
}
return initialCount - count;
}
/**
* 尝试插入指定物品指定数量如果载具内已满则生成掉落物
*
* @param item 物品类型
* @param count 要插入的数量
*/
public void insertItem(Item item, int count) {
var defaultStack = new ItemStack(item);
var maxStackSize = item.getMaxStackSize(defaultStack);
for (int i = 0; i < this.getItemStacks().size(); i++) {
var stack = this.getItemStacks().get(i);
if (stack.is(item) && stack.getCount() < maxStackSize) {
var countToAdd = Math.min(maxStackSize - stack.getCount(), count);
stack.grow(countToAdd);
count -= countToAdd;
} else if (stack.isEmpty()) {
var countToAdd = Math.min(maxStackSize, count);
this.getItemStacks().set(i, new ItemStack(item, countToAdd));
count -= countToAdd;
}
if (count <= 0) break;
}
if (count > 0) {
var stackToDrop = new ItemStack(item, count);
this.level().addFreshEntity(new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), stackToDrop));
}
}
@Override @Override
public void clearItemStacks() { public void clearItemStacks() {
this.items.clear(); this.items.clear();

View file

@ -249,20 +249,18 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
} }
private void handleAmmo() { private void handleAmmo() {
if (!(this.getFirstPassenger() instanceof Player player)) return; if (!(this.getFirstPassenger() instanceof Player)) return;
int ammoCount = this.getItemStacks().stream().filter(stack -> { int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0; return AmmoType.RIFLE.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.RIFLE::get).sum() }).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get());
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum();
if (getWeaponType() == 0) {
if (this.getEntityData().get(WEAPON_TYPE) == 0) { this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get()));
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum()); } else if (getWeaponType() == 1) {
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) {
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);
} }
} }
@ -280,7 +278,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
Matrix4f transform = getBarrelTransform(); Matrix4f transform = getBarrelTransform();
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
if (this.cannotFire) return; if (this.cannotFire) return;
float x = -0.0234375f; float x = -0.0234375f;
float y = 0f; float y = 0f;
@ -322,7 +320,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
this.entityData.set(FIRE_ANIM, 3); this.entityData.set(FIRE_ANIM, 3);
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
if (this.cannotFireCoax) return; if (this.cannotFireCoax) return;
float x = 0.3f; float x = 0.3f;
float y = 0.08f; float y = 0.08f;
@ -629,11 +627,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
} }
private PlayState firePredicate(AnimationState<Lav150Entity> event) { private PlayState firePredicate(AnimationState<Lav150Entity> event) {
if (this.entityData.get(FIRE_ANIM) > 1 && entityData.get(WEAPON_TYPE) == 0) { if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType() == 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire"));
} }
if (this.entityData.get(FIRE_ANIM) > 0 && entityData.get(WEAPON_TYPE) == 1) { if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType() == 1) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2"));
} }
@ -667,9 +665,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override @Override
public int mainGunRpm() { public int mainGunRpm() {
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
return 300; return 300;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
return 600; return 600;
} }
return 300; return 300;
@ -677,9 +675,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override @Override
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax; return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
} }
return false; return false;
@ -707,8 +705,8 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override @Override
public void changeWeapon(int scroll) { public void changeWeapon(int scroll) {
var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; var type = (getWeaponType() + scroll + 2) % 2;
entityData.set(WEAPON_TYPE, type); setWeaponType(type);
var sound = switch (type) { var sound = switch (type) {
case 0 -> ModSounds.INTO_MISSILE.get(); case 0 -> ModSounds.INTO_MISSILE.get();
@ -724,6 +722,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
return entityData.get(WEAPON_TYPE); return entityData.get(WEAPON_TYPE);
} }
@Override
public void setWeaponType(int type) {
entityData.set(WEAPON_TYPE, type);
}
@Override @Override
public ResourceLocation getVehicleIcon() { public ResourceLocation getVehicleIcon() {
return ModUtils.loc("textures/vehicle_icon/lav150_icon.png"); return ModUtils.loc("textures/vehicle_icon/lav150_icon.png");

View file

@ -5,4 +5,6 @@ public interface MultiWeaponVehicleEntity extends IArmedVehicleEntity {
void changeWeapon(int scroll); void changeWeapon(int scroll);
int getWeaponType(); int getWeaponType();
void setWeaponType(int type);
} }

View file

@ -203,8 +203,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
return AmmoType.HEAVY.get(stack) > 0; return AmmoType.HEAVY.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.HEAVY::get).sum() }).mapToInt(AmmoType.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get());
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum();
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);

View file

@ -376,17 +376,12 @@ public class VehicleEntity extends Entity {
} }
} }
if (this.getHealth() <= 0.25 * this.getMaxHealth()) { if (this.level() instanceof ServerLevel serverLevel) {
if (this.level() instanceof ServerLevel serverLevel) { if (this.getHealth() <= 0.25 * this.getMaxHealth()) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true); playLowHealthParticle(serverLevel);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
} }
} if (this.getHealth() <= 0.15 * this.getMaxHealth()) {
playLowHealthParticle(serverLevel);
if (this.getHealth() <= 0.15 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
} }
} }
@ -409,6 +404,11 @@ public class VehicleEntity extends Entity {
} }
} }
private void playLowHealthParticle(ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
}
public void destroy() { public void destroy() {
} }

View file

@ -7,7 +7,10 @@ import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -30,12 +33,13 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Item;
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.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
@ -110,14 +114,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public void addAdditionalSaveData(CompoundTag compound) { public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound); super.addAdditionalSaveData(compound);
compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO)); compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO));
compound.putInt("WeaponType", this.entityData.get(WEAPON_TYPE)); compound.putInt("WeaponType", getWeaponType());
} }
@Override @Override
public void readAdditionalSaveData(CompoundTag compound) { public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound); super.readAdditionalSaveData(compound);
this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo")); this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo"));
this.entityData.set(WEAPON_TYPE, compound.getInt("WeaponType")); setWeaponType(compound.getInt("WeaponType"));
} }
@Override @Override
@ -240,38 +244,32 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.refreshDimensions(); this.refreshDimensions();
} }
private Item getCurrentAmmoItem() {
return switch (getWeaponType()) {
case 0 -> ModItems.AP_5_INCHES.get();
case 1 -> ModItems.HE_5_INCHES.get();
default -> throw new IllegalStateException("Unexpected value: " + getWeaponType());
};
}
private void handleAmmo() { private void handleAmmo() {
if (!(this.getFirstPassenger() instanceof Player player)) return; if (!(this.getFirstPassenger() instanceof Player player)) return;
int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0;
}
return false;
}).mapToInt(AmmoType.RIFLE::get).sum()
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum();
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
if (hasCreativeAmmo) { if (hasCreativeAmmo) {
this.entityData.set(AMMO, 9999); this.entityData.set(AMMO, 9999);
} else if (this.getEntityData().get(WEAPON_TYPE) == 0) { } else {
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).mapToInt(ItemStack::getCount).sum()); this.entityData.set(AMMO, countItem(getCurrentAmmoItem()));
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) {
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).mapToInt(ItemStack::getCount).sum());
} }
if (this.getEntityData().get(LOADED_AMMO) == 0 && reloadCoolDown <= 0) { if (this.getEntityData().get(LOADED_AMMO) == 0
if (this.getEntityData().get(WEAPON_TYPE) == 0 && (this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).mapToInt(ItemStack::getCount).sum() > 0 || hasCreativeAmmo)) { && reloadCoolDown <= 0
this.entityData.set(LOADED_AMMO, 1); && (hasCreativeAmmo || countItem(getCurrentAmmoItem()) > 0)
if (!hasCreativeAmmo) { ) {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.entityData.set(LOADED_AMMO, 1);
} if (!hasCreativeAmmo) {
} else if (this.getEntityData().get(WEAPON_TYPE) == 1 && (this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).mapToInt(ItemStack::getCount).sum() > 0 || hasCreativeAmmo)) { consumeItem(getCurrentAmmoItem(), 1);
this.entityData.set(LOADED_AMMO, 1);
if (!hasCreativeAmmo) {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).findFirst().ifPresent(stack -> stack.shrink(1));
}
} }
} }
} }
@ -286,27 +284,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override @Override
public void vehicleShoot(Player player) { public void vehicleShoot(Player player) {
if (reloadCoolDown > 0) { if (reloadCoolDown > 0) return;
return;
}
Matrix4f transform = getBarrelTransform(); Matrix4f transform = getBarrelTransform();
float hitDamage = 0; float hitDamage, explosionRadius, explosionDamage, fireProbability;
float explosionRadius = 0; int fireTime, durability;
float explosionDamage = 0; float v;
float fireProbability = 0;
int fireTime = 0;
int durability = 0;
float v = 0;
if (entityData.get(WEAPON_TYPE) == 0) { if (getWeaponType() == 0) {
hitDamage = 500; hitDamage = 500;
explosionRadius = 4; explosionRadius = 4;
explosionDamage = 100; explosionDamage = 100;
fireProbability = 0; fireProbability = 0;
fireTime = 0;
durability = 60; durability = 60;
v = 40; v = 40;
} else if (entityData.get(WEAPON_TYPE) == 1) { } else if (getWeaponType() == 1) {
hitDamage = 100; hitDamage = 100;
explosionRadius = 10; explosionRadius = 10;
explosionDamage = 150; explosionDamage = 150;
@ -314,6 +307,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
fireTime = 2; fireTime = 2;
durability = 1; durability = 1;
v = 25; v = 25;
} else {
throw new IllegalStateException("Unexpected value: " + getWeaponType());
} }
Vector4f worldPosition = transformPosition(transform, 0, 0, 0); Vector4f worldPosition = transformPosition(transform, 0, 0, 0);
@ -350,7 +345,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
} }
} }
public final Vec3 getBarrelVector(float pPartialTicks) { public Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks)); return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
} }
@ -435,7 +430,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f); diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot()); diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -30f, 4f)); this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -30f, 4f));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -8, 8)); this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -8, 8));
} }
@ -579,7 +573,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
} }
@ -682,12 +676,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override @Override
public void changeWeapon(int scroll) { public void changeWeapon(int scroll) {
if (entityData.get(LOADED_AMMO) > 0) { if (entityData.get(LOADED_AMMO) > 0) {
if (entityData.get(WEAPON_TYPE) == 0) { this.insertItem(getCurrentAmmoItem(), 1);
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).findFirst().ifPresent(stack -> stack.grow(1));
} else if (entityData.get(WEAPON_TYPE) == 1) {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).findFirst().ifPresent(stack -> stack.grow(1));
}
entityData.set(LOADED_AMMO, 0); entityData.set(LOADED_AMMO, 0);
} }
@ -698,8 +687,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
player.connection.send(clientboundstopsoundpacket); player.connection.send(clientboundstopsoundpacket);
} }
var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; var type = (getWeaponType() + scroll + 2) % 2;
entityData.set(WEAPON_TYPE, type); setWeaponType(type);
var sound = switch (type) { var sound = switch (type) {
case 0 -> ModSounds.INTO_MISSILE.get(); case 0 -> ModSounds.INTO_MISSILE.get();
@ -714,6 +703,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
return entityData.get(WEAPON_TYPE); return entityData.get(WEAPON_TYPE);
} }
@Override
public void setWeaponType(int type) {
entityData.set(WEAPON_TYPE, type);
}
@Override @Override
public ResourceLocation getVehicleIcon() { public ResourceLocation getVehicleIcon() {
return ModUtils.loc("textures/vehicle_icon/bmp2_icon.png"); return ModUtils.loc("textures/vehicle_icon/bmp2_icon.png");

View file

@ -18,7 +18,6 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
@ -101,8 +100,7 @@ public class Yx100GunEntity extends VehicleEntity implements GeoEntity, ICannonE
return AmmoType.HEAVY.get(stack) > 0; return AmmoType.HEAVY.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.HEAVY::get).sum() }).mapToInt(AmmoType.HEAVY::get).sum() + yx100.countItem(ModItems.HEAVY_AMMO.get());
+ yx100.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum();
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);