修改激光的淡出方法
This commit is contained in:
parent
59926f020f
commit
256b235fc0
4 changed files with 33 additions and 9 deletions
|
@ -26,6 +26,8 @@ public class LaserCapability {
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
void end();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LaserCapabilityImpl implements ILaserCapability {
|
public static class LaserCapabilityImpl implements ILaserCapability {
|
||||||
|
@ -53,6 +55,13 @@ public class LaserCapability {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void end() {
|
||||||
|
if (this.laserHandler != null) {
|
||||||
|
this.laserHandler.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag serializeNBT() {
|
public CompoundTag serializeNBT() {
|
||||||
CompoundTag tag = new CompoundTag();
|
CompoundTag tag = new CompoundTag();
|
||||||
|
|
|
@ -4,19 +4,16 @@ import com.atsuishio.superbwarfare.entity.projectile.AbstractLaserEntity;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
|
||||||
public class LaserHandler {
|
public class LaserHandler {
|
||||||
|
|
||||||
public final int coolingTick;
|
|
||||||
public boolean isUsing;
|
public boolean isUsing;
|
||||||
public final LivingEntity entity;
|
public final LivingEntity entity;
|
||||||
public final AbstractLaserEntity laserEntity;
|
public final AbstractLaserEntity laserEntity;
|
||||||
private int tick;
|
private int tick;
|
||||||
|
|
||||||
public LaserHandler(LivingEntity entity, AbstractLaserEntity laserEntity, int coolingTick) {
|
public LaserHandler(LivingEntity entity, AbstractLaserEntity laserEntity) {
|
||||||
this.coolingTick = coolingTick;
|
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.laserEntity = laserEntity;
|
this.laserEntity = laserEntity;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +25,6 @@ public class LaserHandler {
|
||||||
if (this.entity.level() instanceof ServerLevel level) {
|
if (this.entity.level() instanceof ServerLevel level) {
|
||||||
level.addFreshEntity(this.laserEntity);
|
level.addFreshEntity(this.laserEntity);
|
||||||
}
|
}
|
||||||
this.entity.swing(InteractionHand.MAIN_HAND, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
@ -41,9 +37,25 @@ public class LaserHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 终止光束,并带有淡出效果
|
||||||
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (!this.isUsing) return;
|
if (!this.isUsing) return;
|
||||||
|
|
||||||
|
this.isUsing = false;
|
||||||
|
this.tick = 0;
|
||||||
|
if (this.laserEntity != null) {
|
||||||
|
this.laserEntity.setDuration(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接终止光束
|
||||||
|
*/
|
||||||
|
public void end() {
|
||||||
|
if (!this.isUsing) return;
|
||||||
|
|
||||||
this.isUsing = false;
|
this.isUsing = false;
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
if (this.laserEntity != null) {
|
if (this.laserEntity != null) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public abstract class AbstractLaserEntity extends Entity implements TraceableEnt
|
||||||
|
|
||||||
this.beamTick();
|
this.beamTick();
|
||||||
|
|
||||||
if ((!this.on && this.ticker.isStopped()) || (this.caster != null && !caster.isAlive())) {
|
if ((!this.on && this.ticker.isStopped()) || (this.caster != null && !this.caster.isAlive())) {
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
this.ticker.changeTimer(this.on && this.isAccumulating());
|
this.ticker.changeTimer(this.on && this.isAccumulating());
|
||||||
|
|
|
@ -36,13 +36,12 @@ public class BeamTest extends Item {
|
||||||
float yHeadRotAngle = (float) Math.toRadians(player.yHeadRot + 90);
|
float yHeadRotAngle = (float) Math.toRadians(player.yHeadRot + 90);
|
||||||
float xHeadRotAngle = (float) (float) -Math.toRadians(player.getXRot());
|
float xHeadRotAngle = (float) (float) -Math.toRadians(player.getXRot());
|
||||||
LaserEntity laserEntity = new LaserEntity(player.level(), player, px, py, pz, yHeadRotAngle, xHeadRotAngle, 6000);
|
LaserEntity laserEntity = new LaserEntity(player.level(), player, px, py, pz, yHeadRotAngle, xHeadRotAngle, 6000);
|
||||||
capability.init(new LaserHandler(player, laserEntity, 0));
|
capability.init(new LaserHandler(player, laserEntity));
|
||||||
capability.start();
|
capability.start();
|
||||||
|
|
||||||
if (!stack.getOrCreateTag().getBoolean("LaserFiring") && !(player.getCooldowns().isOnCooldown(stack.getItem()))) {
|
if (!stack.getOrCreateTag().getBoolean("LaserFiring") && !(player.getCooldowns().isOnCooldown(stack.getItem()))) {
|
||||||
stack.getOrCreateTag().putBoolean("LaserFiring", true);
|
stack.getOrCreateTag().putBoolean("LaserFiring", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@ public class BeamTest extends Item {
|
||||||
stack.getOrCreateTag().putInt("FireTick", stack.getOrCreateTag().getInt("FireTick") + 1);
|
stack.getOrCreateTag().putInt("FireTick", stack.getOrCreateTag().getInt("FireTick") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (stack.getOrCreateTag().getInt("FireTick") >= 14) {
|
if (stack.getOrCreateTag().getInt("FireTick") >= 14) {
|
||||||
if (entity instanceof ServerPlayer serverPlayer) {
|
if (entity instanceof ServerPlayer serverPlayer) {
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.SENTINEL_CHARGE_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.SENTINEL_CHARGE_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
||||||
|
@ -91,4 +89,9 @@ public class BeamTest extends Item {
|
||||||
public int getUseDuration(ItemStack stack) {
|
public int getUseDuration(ItemStack stack) {
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||||
|
return slotChanged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue