优化载具相关代码
This commit is contained in:
parent
c668394659
commit
cd483aa9a9
9 changed files with 23 additions and 46 deletions
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue