调整部分代码
This commit is contained in:
parent
adc202a288
commit
48439a2d6c
5 changed files with 38 additions and 99 deletions
|
@ -22,7 +22,6 @@ import net.minecraft.world.entity.item.ItemEntity;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import software.bernie.geckolib.animatable.GeoEntity;
|
||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.core.animation.AnimatableManager;
|
||||
|
@ -38,10 +37,8 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
protected static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID);
|
||||
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING);
|
||||
protected static final EntityDataAccessor<Optional<UUID>> TARGET_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID);
|
||||
protected static final EntityDataAccessor<Float> REL_X = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT);
|
||||
protected static final EntityDataAccessor<Float> REL_Y = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT);
|
||||
protected static final EntityDataAccessor<Float> REL_Z = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
public C4Entity(EntityType<C4Entity> type, Level world) {
|
||||
|
@ -52,12 +49,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
public C4Entity(LivingEntity owner, Level level) {
|
||||
super(ModEntities.C_4.get(), level);
|
||||
this.setOwnerUUID(owner.getUUID());
|
||||
ModUtils.queueServerWork(1, () -> {
|
||||
if (this.level().isClientSide()) return;
|
||||
CompoundTag compoundTag = owner.serializeNBT();
|
||||
compoundTag.putUUID("C4UUID", this.getUUID());
|
||||
this.getOwner().deserializeNBT(compoundTag);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,9 +57,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
this.entityData.define(LAST_ATTACKER_UUID, "undefined");
|
||||
this.entityData.define(HEALTH, 10f);
|
||||
this.entityData.define(TARGET_UUID, Optional.empty());
|
||||
this.entityData.define(REL_X, 0.0f);
|
||||
this.entityData.define(REL_Y, 0.0f);
|
||||
this.entityData.define(REL_Z, 0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,9 +97,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
|
||||
if (this.getTargetUUID() != null) {
|
||||
compound.putUUID("Target", this.getTargetUUID());
|
||||
compound.putFloat("RelativeX", this.entityData.get(REL_X));
|
||||
compound.putFloat("RelativeY", this.entityData.get(REL_Y));
|
||||
compound.putFloat("RelativeZ", this.entityData.get(REL_Z));
|
||||
}
|
||||
if (this.getOwnerUUID() != null) {
|
||||
compound.putUUID("Owner", this.getOwnerUUID());
|
||||
|
@ -141,12 +126,11 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
if (uuid != null) {
|
||||
try {
|
||||
this.setOwnerUUID(uuid);
|
||||
} catch (Throwable ignored){}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Target
|
||||
**/
|
||||
// Target
|
||||
if (compound.hasUUID("Target")) {
|
||||
uuid = compound.getUUID("Target");
|
||||
} else {
|
||||
|
@ -159,11 +143,8 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
if (uuid != null) {
|
||||
try {
|
||||
this.setTargetUUID(uuid);
|
||||
|
||||
this.entityData.set(REL_X, compound.getFloat("RelativeX"));
|
||||
this.entityData.set(REL_Y, compound.getFloat("RelativeY"));
|
||||
this.entityData.set(REL_Z, compound.getFloat("RelativeZ"));
|
||||
} catch (Throwable ignored){}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,14 +152,10 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
return this.onGround() || this.getTargetUUID() != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
var level = this.level();
|
||||
var x = this.getX();
|
||||
var y = this.getY();
|
||||
var z = this.getZ();
|
||||
Level level = this.level();
|
||||
|
||||
if (this.tickCount >= ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get()) {
|
||||
this.explode();
|
||||
|
@ -193,7 +170,7 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
if (this.getUUID() == target.getUUID() || this.getOwnerUUID() == target.getUUID() || !(target instanceof LivingEntity || target instanceof VehicleEntity)) {
|
||||
continue;
|
||||
}
|
||||
this.setTargetUUID(target.getUUID());;
|
||||
this.setTargetUUID(target.getUUID());
|
||||
|
||||
// var relpos = this.calcRelativePos(target);
|
||||
// this.setRelativePos(((float) relpos.x), ((float) relpos.y), ((float) relpos.z));
|
||||
|
@ -206,7 +183,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
this.destroy();
|
||||
}
|
||||
} else {
|
||||
ModUtils.queueServerWork(1, () -> {
|
||||
if (level.isClientSide()) return;
|
||||
if (this.getTargetUUID() == null) {
|
||||
this.destroy();
|
||||
|
@ -221,11 +197,8 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
this.setInvisible(true);
|
||||
}
|
||||
this.setPos(target.position().x, target.position().y + target.getBoundingBox().getYsize(), target.position().z);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
|
@ -243,23 +216,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab
|
|||
this.discard();
|
||||
}
|
||||
|
||||
public Vec3 getRelativePos() {
|
||||
if (this.isPlaced()) {
|
||||
return new Vec3(this.entityData.get(REL_X), this.entityData.get(REL_Y), this.entityData.get(REL_Z));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vec3 calcRelativePos(Entity target) {
|
||||
return this.position().subtract(target.position());
|
||||
}
|
||||
|
||||
public void setRelativePos(float x, float y, float z) {
|
||||
this.entityData.set(REL_X, x);
|
||||
this.entityData.set(REL_X, y);
|
||||
this.entityData.set(REL_X, z);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (this.level() instanceof ServerLevel && this.tickCount < ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get()) {
|
||||
ItemEntity c4 = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), new ItemStack(ModItems.C4_BOMB.get()));
|
||||
|
|
|
@ -69,6 +69,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> PROPELLER_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
public static final float MAX_HEALTH = 5;
|
||||
|
||||
|
|
|
@ -63,13 +63,14 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
|
|||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
public static final float MAX_HEALTH = VehicleConfig.AH_6_HP.get();
|
||||
public static final int MAX_ENERGY = VehicleConfig.AH_6_MAX_ENERGY.get();
|
||||
|
||||
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
|
||||
|
||||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Integer> DECOY_COUNT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Integer> LOADED_ROCKET = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
|
||||
|
||||
public boolean engineStart;
|
||||
public boolean engineStartOver;
|
||||
public float propellerRot;
|
||||
|
@ -106,16 +107,16 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
|
|||
public void addAdditionalSaveData(CompoundTag compound) {
|
||||
super.addAdditionalSaveData(compound);
|
||||
compound.putInt("LoadedRocket", this.entityData.get(LOADED_ROCKET));
|
||||
compound.putFloat("propellerRot", this.entityData.get(PROPELLER_ROT));
|
||||
compound.putInt("decoyCount", this.entityData.get(DECOY_COUNT));
|
||||
compound.putFloat("PropellerRot", this.entityData.get(PROPELLER_ROT));
|
||||
compound.putInt("DecoyCount", this.entityData.get(DECOY_COUNT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag compound) {
|
||||
super.readAdditionalSaveData(compound);
|
||||
this.entityData.set(LOADED_ROCKET, compound.getInt("LoadedRocket"));
|
||||
this.entityData.set(PROPELLER_ROT, compound.getFloat("propellerRot"));
|
||||
this.entityData.set(DECOY_COUNT, compound.getInt("decoyCount"));
|
||||
this.entityData.set(PROPELLER_ROT, compound.getFloat("PropellerRot"));
|
||||
this.entityData.set(DECOY_COUNT, compound.getInt("DecoyCount"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -244,11 +245,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
|
|||
this.level().playSound(null, this, ModSounds.DECOY_RELOAD.get(), this.getSoundSource(), 1, 1);
|
||||
decoyReloadCoolDown = 300;
|
||||
}
|
||||
// Player player = (Player) this.getFirstPassenger();
|
||||
//
|
||||
// if (player != null) {
|
||||
// player.displayClientMessage(Component.literal( new DecimalFormat("##").format(this.getEntityData().get(DECOY_COUNT))), true);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,7 +262,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
|
|||
this.setXRot(this.getXRot() * 0.8f);
|
||||
this.entityData.set(POWER, this.entityData.get(POWER) * 0.98f);
|
||||
} else if (passenger instanceof Player) {
|
||||
|
||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
||||
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
|
||||
|
||||
|
|
|
@ -67,10 +67,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
|||
if (player.getVehicle() == this) return InteractionResult.PASS;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModItems.C4_BOMB.get())) {
|
||||
stack.use(player.level(), player, hand);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if (player.isShiftKeyDown() && stack.is(ModItems.CROWBAR.get())) {
|
||||
ItemStack container = ContainerBlockItem.createInstance(this);
|
||||
if (!player.addItem(container)) {
|
||||
|
@ -132,13 +128,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
|||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Player player = (Player) this.getFirstPassenger();
|
||||
|
||||
// if (player != null) {
|
||||
// player.displayClientMessage(Component.literal( new DecimalFormat("##.#").format(this.getEnergy())), true);
|
||||
// }
|
||||
|
||||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.atsuishio.superbwarfare.entity.vehicle;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.C4Entity;
|
||||
import com.atsuishio.superbwarfare.entity.DroneEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
|
@ -56,6 +54,7 @@ public class VehicleEntity extends Entity {
|
|||
public float prevRoll;
|
||||
public int lastHurtTick;
|
||||
public boolean crash;
|
||||
|
||||
public float getRoll() {
|
||||
return roll;
|
||||
}
|
||||
|
@ -224,8 +223,7 @@ public class VehicleEntity extends Entity {
|
|||
|
||||
@Override
|
||||
protected boolean canAddPassenger(Entity pPassenger) {
|
||||
ModUtils.LOGGER.info(pPassenger.getClass().toString());
|
||||
return this.getPassengers().size() < this.getMaxPassengers() || pPassenger instanceof C4Entity;
|
||||
return this.getPassengers().size() < this.getMaxPassengers();
|
||||
}
|
||||
|
||||
public int getMaxPassengers() {
|
||||
|
@ -236,9 +234,9 @@ public class VehicleEntity extends Entity {
|
|||
public void baseTick() {
|
||||
super.baseTick();
|
||||
|
||||
lastHurtTick ++;
|
||||
this.lastHurtTick++;
|
||||
|
||||
prevRoll = this.getRoll();
|
||||
this.prevRoll = this.getRoll();
|
||||
|
||||
float delta = Math.abs(getYRot() - yRotO);
|
||||
while (getYRot() > 180F) {
|
||||
|
|
Loading…
Add table
Reference in a new issue