优化部分冗余代码

This commit is contained in:
17146 2024-08-29 03:59:39 +08:00
parent 9b2e093a46
commit b3524d203a
9 changed files with 21 additions and 50 deletions

View file

@ -48,10 +48,6 @@ public class BocekArrowEntity extends AbstractArrow implements ItemSupplier {
super(type, world); super(type, world);
} }
public BocekArrowEntity(EntityType<? extends BocekArrowEntity> type, double x, double y, double z, Level world) {
super(type, x, y, z, world);
}
public BocekArrowEntity(LivingEntity entity, Level level, int monsterMultiplier) { public BocekArrowEntity(LivingEntity entity, Level level, int monsterMultiplier) {
super(ModEntities.BOCEK_ARROW.get(), entity, level); super(ModEntities.BOCEK_ARROW.get(), entity, level);
this.monsterMultiplier = monsterMultiplier; this.monsterMultiplier = monsterMultiplier;

View file

@ -39,8 +39,7 @@ import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class CannonShellEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity{ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(CannonShellEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(CannonShellEntity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -57,14 +56,6 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt
super(type, world); super(type, world);
} }
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, double x, double y, double z, Level world) {
super(type, x, y, z, world);
}
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, LivingEntity entity, Level world) {
super(type, entity, world);
}
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, LivingEntity entity, Level world, float damage, float explosionRadius, float explosionDamage, float fireProbability, int fireTime) { public CannonShellEntity(EntityType<? extends CannonShellEntity> type, LivingEntity entity, Level world, float damage, float explosionRadius, float explosionDamage, float fireProbability, int fireTime) {
super(type, entity, world); super(type, entity, world);
this.damage = damage; this.damage = damage;
@ -222,14 +213,14 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt
this.discard(); this.discard();
} }
private PlayState movementPredicate(AnimationState event) { private PlayState movementPredicate(AnimationState<CannonShellEntity> event) {
if (this.animationprocedure.equals("empty")) { if (this.animationprocedure.equals("empty")) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.cannon_shell.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.cannon_shell.idle"));
} }
return PlayState.STOP; return PlayState.STOP;
} }
private PlayState procedurePredicate(AnimationState event) { private PlayState procedurePredicate(AnimationState<CannonShellEntity> event) {
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) { if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure)); event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) { if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {

View file

@ -65,6 +65,7 @@ import javax.annotation.Nullable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
// TODO 重做无人机
public class DroneEntity extends PathfinderMob implements GeoEntity { public class DroneEntity extends PathfinderMob implements GeoEntity {
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
@ -464,7 +465,6 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
} }
@Override @Override
public EntityDimensions getDimensions(Pose p_33597_) { public EntityDimensions getDimensions(Pose p_33597_) {
return super.getDimensions(p_33597_).scale((float) 1); return super.getDimensions(p_33597_).scale((float) 1);

View file

@ -32,7 +32,6 @@ import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
public class GunGrenadeEntity extends ThrowableItemProjectile { public class GunGrenadeEntity extends ThrowableItemProjectile {
private int monsterMultiplier = 0; private int monsterMultiplier = 0;
private float damage = 5f; private float damage = 5f;
@ -101,7 +100,7 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
super.onHitBlock(blockHitResult); super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if(state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }
if (this.tickCount > 0) { if (this.tickCount > 0) {

View file

@ -40,10 +40,6 @@ public class HandGrenadeEntity extends ThrowableItemProjectile {
super(type, world); super(type, world);
} }
public HandGrenadeEntity(EntityType<? extends HandGrenadeEntity> type, LivingEntity entity, Level world) {
super(type, entity, world);
}
public HandGrenadeEntity(LivingEntity entity, Level level, int fuse) { public HandGrenadeEntity(LivingEntity entity, Level level, int fuse) {
super(ModEntities.HAND_GRENADE_ENTITY.get(), entity, level); super(ModEntities.HAND_GRENADE_ENTITY.get(), entity, level);
this.fuse = fuse; this.fuse = fuse;
@ -82,7 +78,7 @@ public class HandGrenadeEntity extends ThrowableItemProjectile {
} }
this.bounce(blockResult.getDirection()); this.bounce(blockResult.getDirection());
if(state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockResult.getDirection());
} }

View file

@ -31,10 +31,6 @@ public class MortarShellEntity extends ThrowableItemProjectile {
super(type, world); super(type, world);
} }
public MortarShellEntity(EntityType<? extends MortarShellEntity> type, double x, double y, double z, Level world) {
super(type, x, y, z, world);
}
public MortarShellEntity(EntityType<? extends MortarShellEntity> type, LivingEntity entity, Level world) { public MortarShellEntity(EntityType<? extends MortarShellEntity> type, LivingEntity entity, Level world) {
super(type, entity, world); super(type, entity, world);
} }

View file

@ -38,7 +38,7 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache
import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity{ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(RgoGrenadeEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(RgoGrenadeEntity.class, EntityDataSerializers.STRING);
private int fuse = 80; private int fuse = 80;
@ -49,10 +49,6 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
super(type, world); super(type, world);
} }
public RgoGrenadeEntity(EntityType<? extends RgoGrenadeEntity> type, LivingEntity entity, Level world) {
super(type, entity, world);
}
public RgoGrenadeEntity(LivingEntity entity, Level level, int fuse) { public RgoGrenadeEntity(LivingEntity entity, Level level, int fuse) {
super(ModEntities.RGO_GRENADE.get(), entity, level); super(ModEntities.RGO_GRENADE.get(), entity, level);
this.fuse = fuse; this.fuse = fuse;
@ -84,7 +80,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
BlockHitResult blockResult = (BlockHitResult) result; BlockHitResult blockResult = (BlockHitResult) result;
BlockPos resultPos = blockResult.getBlockPos(); BlockPos resultPos = blockResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if(state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockResult.getDirection());
} }
causeExplode(); causeExplode();
@ -102,7 +98,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
} }
} }
causeEntityhitExplode(entity); causeEntityHitExplode(entity);
break; break;
default: default:
break; break;
@ -126,7 +122,8 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
1, 0, 0, 0, 0.01, true); 1, 0, 0, 0, 0.01, true);
} }
} }
private void causeEntityhitExplode(Entity entity) {
private void causeEntityHitExplode(Entity entity) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 75, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 75,
entity.getX(), entity.getY(), entity.getZ(), 5.75f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); entity.getX(), entity.getY(), entity.getZ(), 5.75f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f);

View file

@ -43,9 +43,8 @@ import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity{ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(RpgRocketEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(CannonShellEntity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public String animationprocedure = "empty"; public String animationprocedure = "empty";
@ -57,10 +56,6 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
super(type, world); super(type, world);
} }
public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, LivingEntity entity, Level world) {
super(type, entity, world);
}
public RpgRocketEntity(LivingEntity entity, Level level, float damage, int monsterMultiplier) { public RpgRocketEntity(LivingEntity entity, Level level, float damage, int monsterMultiplier) {
super(ModEntities.RPG_ROCKET.get(), entity, level); super(ModEntities.RPG_ROCKET.get(), entity, level);
this.damage = damage; this.damage = damage;
@ -105,7 +100,7 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
if (this.tickCount > 1) { if (this.tickCount > 1) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
causeEntityhitExplode(entity); causeEntityHitExplode(entity);
} }
} }
@ -122,9 +117,11 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
super.onHitBlock(blockHitResult); super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if(state.getBlock() instanceof BellBlock bell) {
if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }
if (this.tickCount > 1) { if (this.tickCount > 1) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
causeExplode(); causeExplode();
@ -171,7 +168,7 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
} }
private void causeEntityhitExplode(Entity entity) { private void causeEntityHitExplode(Entity entity) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), (float) 2 / 3 * this.damage, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), (float) 2 / 3 * this.damage,
entity.getX(), entity.getY(), entity.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(this.monsterMultiplier); entity.getX(), entity.getY(), entity.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(this.monsterMultiplier);
@ -182,14 +179,14 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
this.discard(); this.discard();
} }
private PlayState movementPredicate(AnimationState event) { private PlayState movementPredicate(AnimationState<RpgRocketEntity> event) {
if (this.animationprocedure.equals("empty")) { if (this.animationprocedure.equals("empty")) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.rpg.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.rpg.idle"));
} }
return PlayState.STOP; return PlayState.STOP;
} }
private PlayState procedurePredicate(AnimationState event) { private PlayState procedurePredicate(AnimationState<RpgRocketEntity> event) {
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) { if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure)); event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) { if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {

View file

@ -1,4 +1,3 @@
package net.mcreator.superbwarfare.entity; package net.mcreator.superbwarfare.entity;
import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.ModUtils;
@ -106,7 +105,7 @@ public class TaserBulletProjectileEntity extends AbstractArrow implements ItemSu
super.onHitBlock(blockHitResult); super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if(state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }
} }