Skip to content

Commit

Permalink
shriek worm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Nov 5, 2023
1 parent a3065b5 commit 41ff0bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
Expand All @@ -25,13 +23,14 @@

@SuppressWarnings("deprecation, NullableProblems")
public class ShriekWorm extends Monster {
private static final EntityDataAccessor<Integer> IDLE_TIMER = SynchedEntityData.defineId(ShriekWorm.class, EntityDataSerializers.INT);
public final AnimationState idleState = new AnimationState();
public final AnimationState attackState = new AnimationState();
public final AnimationState asleepState = new AnimationState();
public final AnimationState emergeState = new AnimationState();
public final AnimationState descendState = new AnimationState();
private int emerging;
private int emergingTime;
private int idleTime;
private boolean asleep;

public ShriekWorm(EntityType<? extends Monster> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
Expand Down Expand Up @@ -72,12 +71,6 @@ public MobType getMobType() {
return DDMobType.SCULK;
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(IDLE_TIMER, getRandom().nextInt(160, 300));
}

@Override
public boolean doHurtTarget(Entity pEntity) {
this.level().broadcastEntityEvent(this, (byte) 4);
Expand All @@ -88,40 +81,41 @@ public boolean doHurtTarget(Entity pEntity) {
public void tick() {
super.tick();

if(this.getPose() == Pose.EMERGING && ++emerging > 156) this.setPose(Pose.STANDING);
if(this.getPose() == Pose.EMERGING && ++emergingTime > 80) this.setPose(Pose.STANDING);

if(this.getPose() == Pose.STANDING && !this.asleep) {
this.idleTime++;
if(this.idleTime > 200) {
this.idleTime = 0;
this.asleep = true;
}
}

Player player = level().getNearestPlayer(this, 5);
if(player != null && !player.isDeadOrDying() && !player.isCreative()) {
this.asleep = false;
} else {
if(this.attackState.isStarted() && !this.idleState.isStarted()) {
this.attackState.stop();
this.idleState.start(this.tickCount);
}
}

if(level().isClientSide()) {
if(this.idleState.isStarted()) {
this.entityData.set(IDLE_TIMER, this.entityData.get(IDLE_TIMER) - 1);

if(this.entityData.get(IDLE_TIMER) <= 0) {
this.idleState.stop();
if(this.random.nextFloat() < 1f) {
this.asleepState.start(this.tickCount);
}
else this.descendState.start(this.tickCount); // chance for descend is 0 bc kill function is broken
}
} else if(!this.asleepState.isStarted() && !this.emergeState.isStarted() && !this.descendState.isStarted()) {
if(!this.attackState.isStarted()) {
this.idleState.start(this.tickCount);
} else if(this.entityData.get(IDLE_TIMER) < 160) {
this.entityData.set(IDLE_TIMER, getRandom().nextInt(160, 300));
}
if(this.asleep && !this.asleepState.isStarted()) {
this.idleState.stop();
this.asleepState.start(this.tickCount);
}
if(!this.asleep && !this.idleState.isStarted() && !this.emergeState.isStarted() && !this.descendState.isStarted()) {
this.asleepState.stop();
this.idleState.start(this.tickCount);
}

if(this.getPose() == Pose.EMERGING) {
double sX = this.random.nextGaussian() * 0.02;
double sY = this.random.nextGaussian() * 0.02;
double sZ = this.random.nextGaussian() * 0.02;
level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, this.getBlockStateOn()), this.getX() - this.random.nextDouble(), this.getY() + 1, this.getZ() - this.random.nextDouble(), sX, sY, sZ);
}
}

Player player = level().getNearestPlayer(this, 3);
if(player == null || player.isDeadOrDying() || player.isCreative()) {
if(this.attackState.isStarted()) {
this.attackState.stop();
this.idleState.start(this.tickCount);
level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, this.getBlockStateOn()), getRandomX(1), getY() + 1, getRandomZ(1), sX, sY, sZ);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public void tick() {
List<Player> players = level().getNearbyPlayers(TargetingConditions.forCombat().range(10), this, this.getBoundingBox().inflate(10, 8, 10));
if(!players.isEmpty()) {
this.rangedCooldown--;
System.out.println(level().isClientSide() + ": " + this.rangedCooldown);
if(this.rangedCooldown < -200) {
if(level().isClientSide()) this.ringAttackState.stop();
this.rangedCooldown = 440;
Expand Down Expand Up @@ -164,7 +163,7 @@ public void tick() {
double sX = this.random.nextGaussian() * 0.02;
double sY = this.random.nextGaussian() * 0.02;
double sZ = this.random.nextGaussian() * 0.02;
level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, this.getBlockStateOn()), this.getX() - this.random.nextDouble(), this.getY() + 1, this.getZ() - this.random.nextDouble(), sX, sY, sZ);
level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, this.getBlockStateOn()), getRandomX(1), getY(), getRandomZ(1), sX, sY, sZ);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public class ShriekWormAnimation {
new Keyframe(2f, KeyframeAnimations.degreeVec(-17.5f, 0f, 0f), AnimationChannel.Interpolations.LINEAR),
new Keyframe(4f, KeyframeAnimations.degreeVec(-15f, 0f, 0f), AnimationChannel.Interpolations.LINEAR))).build();

public static final AnimationDefinition EMERGE = AnimationDefinition.Builder.withLength(7.8f)
public static final AnimationDefinition EMERGE = AnimationDefinition.Builder.withLength(4f)
.addAnimation("base", new AnimationChannel(AnimationChannel.Targets.POSITION,
new Keyframe(0f, KeyframeAnimations.posVec(0f, -129f, 0f), AnimationChannel.Interpolations.LINEAR),
new Keyframe(4f, KeyframeAnimations.posVec(0f, 0f, 0f), AnimationChannel.Interpolations.LINEAR)))
Expand Down

0 comments on commit 41ff0bd

Please sign in to comment.