diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index d6948e665..d379e5df5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -327,7 +327,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli this.entityData.set(PROPELLER_ROT, this.entityData.get(PROPELLER_ROT) * 0.9995f); if (engineStart) { - this.extraEnergy((int) (VehicleConfig.AH_6_MIN_ENERGY_COST.get() + this.entityData.get(POWER) * ((VehicleConfig.AH_6_MAX_ENERGY_COST.get() - VehicleConfig.AH_6_MIN_ENERGY_COST.get()) / 0.12))); + this.consumeEnergy((int) (VehicleConfig.AH_6_MIN_ENERGY_COST.get() + this.entityData.get(POWER) * ((VehicleConfig.AH_6_MAX_ENERGY_COST.get() - VehicleConfig.AH_6_MIN_ENERGY_COST.get()) / 0.12))); } setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(PROPELLER_ROT), 0.0f)); @@ -622,7 +622,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli public Vec3 getDismountLocationForPassenger(LivingEntity passenger) { Vec3 vec3d = getDismountOffset(getBbWidth() * Mth.SQRT_OF_TWO, passenger.getBbWidth() * Mth.SQRT_OF_TWO); double ox = getX() + vec3d.x; - ; int i = this.getPassengers().indexOf(passenger); if (i == 0 || i == 2) { ox = getX() - vec3d.x; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index f5da8573d..a293c8ef8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -345,7 +345,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, return; } - if (this.getEnergy() < SHOOT_COST) { + if (!this.canConsume(SHOOT_COST)) { player.displayClientMessage(Component.translatable("tips.superbwarfare.annihilator.energy_not_enough").withStyle(ChatFormatting.RED), true); return; } @@ -360,7 +360,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, } this.entityData.set(COOL_DOWN, 100); - this.extraEnergy(SHOOT_COST); + this.consumeEnergy(SHOOT_COST); final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(20), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { if (target instanceof ServerPlayer serverPlayer) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index b217e93ea..2321d614d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -444,7 +444,7 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha } if (this.forwardInputDown || this.backInputDown) { - this.extraEnergy(VehicleConfig.BMP_2_ENERGY_COST.get()); + this.consumeEnergy(VehicleConfig.BMP_2_ENERGY_COST.get()); } this.entityData.set(POWER, this.entityData.get(POWER) * (upInputDown ? 0.5f : (rightInputDown || leftInputDown) ? 0.947f : 0.96f)); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java index 115af7e83..90f349af5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java @@ -1,13 +1,11 @@ package com.atsuishio.superbwarfare.entity.vehicle; import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.menu.VehicleMenu; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvents; import net.minecraft.world.ContainerHelper; import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; @@ -20,7 +18,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.HopperBlockEntity; import net.minecraft.world.level.gameevent.GameEvent; @@ -67,40 +64,12 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus if (player.getVehicle() == this) return InteractionResult.PASS; ItemStack stack = player.getMainHandItem(); - if (player.isShiftKeyDown() && stack.is(ModItems.CROWBAR.get())) { - ItemStack container = ContainerBlockItem.createInstance(this); - if (!player.addItem(container)) { - player.drop(container, false); - } - this.remove(RemovalReason.DISCARDED); - this.discard(); - return InteractionResult.SUCCESS; - } else if (player.isShiftKeyDown()) { + if (player.isShiftKeyDown() && !stack.is(ModItems.CROWBAR.get())) { player.openMenu(this); return !player.level().isClientSide ? InteractionResult.CONSUME : InteractionResult.SUCCESS; - } else if (this.getHealth() < this.getMaxHealth() && stack.is(Items.IRON_INGOT)) { - this.heal(Math.min(50, this.getMaxHealth())); - stack.shrink(1); - if (!this.level().isClientSide) { - this.level().playSound(null, this, SoundEvents.IRON_GOLEM_REPAIR, this.getSoundSource(), 0.5f, 1); - } - return InteractionResult.SUCCESS; - } else if (!player.isShiftKeyDown()) { - if (this.getFirstPassenger() == null) { - player.setXRot(this.getXRot()); - player.setYRot(this.getYRot()); - return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS; - } else if (!(this.getFirstPassenger() instanceof Player)) { - this.getFirstPassenger().stopRiding(); - player.setXRot(this.getXRot()); - player.setYRot(this.getYRot()); - return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS; - } - if (this.canAddPassenger(player)) { - return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS; - } } - return InteractionResult.PASS; + + return super.interact(player, hand); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/EnergyVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/EnergyVehicleEntity.java index 945fcfb50..214d0bd70 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/EnergyVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/EnergyVehicleEntity.java @@ -36,8 +36,17 @@ public class EnergyVehicleEntity extends VehicleEntity implements IChargeEntity compound.putInt("Energy", this.entityData.get(ENERGY)); } - public void extraEnergy(int extraAmount) { - this.setEnergy(this.getEnergy() - extraAmount); + /** + * 消耗指定电量 + * + * @param amount 要消耗的电量 + */ + public void consumeEnergy(int amount) { + this.setEnergy(Math.max(0, this.getEnergy() - amount)); + } + + public boolean canConsume(int amount) { + return this.getEnergy() >= amount; } public int getEnergy() { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index afd094801..6f35b3ced 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -469,7 +469,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC } if (this.forwardInputDown || this.backInputDown) { - this.extraEnergy(VehicleConfig.SPEEDBOAT_ENERGY_COST.get()); + this.consumeEnergy(VehicleConfig.LAV_150_ENERGY_COST.get()); } this.entityData.set(POWER, this.entityData.get(POWER) * (upInputDown ? 0.5f : (rightInputDown || leftInputDown) ? 0.977f : 0.99f)); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index 64a3a9fca..388ee09f0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -307,7 +307,7 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity, } if (this.forwardInputDown || this.backInputDown) { - this.extraEnergy(VehicleConfig.SPEEDBOAT_ENERGY_COST.get()); + this.consumeEnergy(VehicleConfig.SPEEDBOAT_ENERGY_COST.get()); } if (level().isClientSide) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java index 99adf04db..ed1f31368 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java @@ -150,7 +150,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { } if (forwardInputDown && getEnergy() > 0) { - this.extraEnergy(VehicleConfig.TOM_6_ENERGY_COST.get()); + this.consumeEnergy(VehicleConfig.TOM_6_ENERGY_COST.get()); this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + (entityData.get(MELON) ? 0.003f : 0.0022f), entityData.get(MELON) ? 0.12f : 0.15f)); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java index 35fda5311..4ad11cd44 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java @@ -180,13 +180,13 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity { if (passenger instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.WHEEL_CHAIR_JUMP.get(), SoundSource.PLAYERS, 1, 1); } - this.extraEnergy(400); + this.consumeEnergy(400); this.setDeltaMovement(this.getDeltaMovement().add(0, 0.6, 0)); jumpCoolDown = 3; } if (this.forwardInputDown || this.backInputDown) { - this.extraEnergy(1); + this.consumeEnergy(1); } if (passenger instanceof Player player && player.level().isClientSide && this.handBusyTime > 0) {