优化代码
This commit is contained in:
parent
8910859785
commit
6ebd1be672
9 changed files with 31 additions and 44 deletions
|
@ -386,7 +386,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cannonShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
if (this.entityData.get(COOL_DOWN) > 0) {
|
if (this.entityData.get(COOL_DOWN) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -541,11 +541,6 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
||||||
return (int) MAX_ENERGY;
|
return (int) MAX_ENERGY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void vehicleShoot(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getHealth() {
|
public float getHealth() {
|
||||||
return this.entityData.get(HEALTH).intValue();
|
return this.entityData.get(HEALTH).intValue();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.atsuishio.superbwarfare.entity;
|
package com.atsuishio.superbwarfare.entity;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
|
|
||||||
public interface ICannonEntity extends IVehicleEntity {
|
public interface ICannonEntity extends IVehicleEntity {
|
||||||
void cannonShoot(Player player);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,18 @@ package com.atsuishio.superbwarfare.entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
public interface IVehicleEntity {
|
public interface IVehicleEntity {
|
||||||
|
|
||||||
void vehicleShoot(Player player);
|
void vehicleShoot(Player player);
|
||||||
|
|
||||||
float getHealth();
|
float getHealth();
|
||||||
|
|
||||||
float getMaxHealth();
|
float getMaxHealth();
|
||||||
|
|
||||||
boolean isDriver(Player player);
|
boolean isDriver(Player player);
|
||||||
|
|
||||||
int mainGunRpm();
|
int mainGunRpm();
|
||||||
|
|
||||||
boolean canShoot(Player player);
|
boolean canShoot(Player player);
|
||||||
|
|
||||||
int getAmmoCount();
|
int getAmmoCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cannonShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
if (this.entityData.get(COOL_DOWN) > 0) {
|
if (this.entityData.get(COOL_DOWN) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -421,11 +421,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void vehicleShoot(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getHealth() {
|
public float getHealth() {
|
||||||
return this.entityData.get(HEALTH).intValue();
|
return this.entityData.get(HEALTH).intValue();
|
||||||
|
|
|
@ -277,7 +277,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cannonShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
if (this.entityData.get(COOL_DOWN) > 0) {
|
if (this.entityData.get(COOL_DOWN) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -516,11 +516,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void vehicleShoot(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getHealth() {
|
public float getHealth() {
|
||||||
return this.entityData.get(HEALTH).intValue();
|
return this.entityData.get(HEALTH).intValue();
|
||||||
|
|
|
@ -84,6 +84,7 @@ import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
|
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
|
||||||
|
|
||||||
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
|
@ -310,9 +311,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
cannotFire = false;
|
cannotFire = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 获取弹药数量
|
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum());
|
||||||
|
|
||||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).count());
|
|
||||||
|
|
||||||
turretYRotO = this.getTurretYRot();
|
turretYRotO = this.getTurretYRot();
|
||||||
turretXRotO = this.getTurretXRot();
|
turretXRotO = this.getTurretXRot();
|
||||||
|
|
|
@ -64,14 +64,7 @@ public class LivingEventHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getEntity().getVehicle() != null && event.getEntity().getVehicle() instanceof IVehicleEntity) {
|
handleVehicleHurt(event);
|
||||||
event.setAmount(0.3f * event.getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getEntity().getVehicle() != null && event.getEntity().getVehicle() instanceof ICannonEntity) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleGunPerksWhenHurt(event);
|
handleGunPerksWhenHurt(event);
|
||||||
renderDamageIndicator(event);
|
renderDamageIndicator(event);
|
||||||
reduceBulletDamage(event);
|
reduceBulletDamage(event);
|
||||||
|
@ -96,6 +89,17 @@ public class LivingEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleVehicleHurt(LivingHurtEvent event) {
|
||||||
|
var vehicle = event.getEntity().getVehicle();
|
||||||
|
if (vehicle != null) {
|
||||||
|
if (vehicle instanceof ICannonEntity) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
} else if (vehicle instanceof IVehicleEntity) {
|
||||||
|
event.setAmount(0.3f * event.getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算子弹伤害衰减
|
* 计算子弹伤害衰减
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,7 +63,6 @@ public class MouseHandlerMixin {
|
||||||
double zoom = 1.25 + stack.getOrCreateTag().getDouble("CustomZoom");
|
double zoom = 1.25 + stack.getOrCreateTag().getDouble("CustomZoom");
|
||||||
float customSens = (float) stack.getOrCreateTag().getInt("sensitivity");
|
float customSens = (float) stack.getOrCreateTag().getInt("sensitivity");
|
||||||
|
|
||||||
|
|
||||||
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||||
return original / Math.max((1 + (0.2 * (zoom - (0.3 * customSens)) * ClientEventHandler.zoomTime)), 0.1);
|
return original / Math.max((1 + (0.2 * (zoom - (0.3 * customSens)) * ClientEventHandler.zoomTime)), 0.1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.atsuishio.superbwarfare.network.message;
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
|
||||||
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
@ -35,11 +34,7 @@ public class VehicleFireMessage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getVehicle() instanceof ICannonEntity entity) {
|
if (player.getVehicle() instanceof IVehicleEntity iVehicle) {
|
||||||
entity.cannonShoot(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.getVehicle() instanceof IVehicleEntity iVehicle && !(player.getVehicle() instanceof ICannonEntity)) {
|
|
||||||
iVehicle.vehicleShoot(player);
|
iVehicle.vehicleShoot(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue