Skip to content

Commit

Permalink
fix: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jan 5, 2025
1 parent 843f044 commit 33c988d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class SliderSignalAttachment {
@Nullable
protected Direction overrideDirection = null;

protected boolean hasOverriden = false;

@Nullable
protected Entity target = null;

Expand All @@ -34,7 +36,10 @@ public void onUpdate(Slider slider) {
protected void tickSignal(Slider slider) {
if (this.signalTick > 0 && slider.level().isClientSide()) {
if (this.signalTick == 2) playSound(slider);
else if (this.signalTick == 1) this.overrideDirection = null;
else if (this.signalTick == 1) {
this.overrideDirection = null;
this.hasOverriden = false;
}
this.signalTick--;
}
}
Expand All @@ -53,7 +58,7 @@ public static void sendSignal(Slider slider) {
}

public static void syncDirection(Slider slider, Direction direction) {
if (!slider.level().isClientSide()) PacketDistributor.sendToPlayersNear(
if (!slider.level().isClientSide() && direction != null) PacketDistributor.sendToPlayersNear(
(ServerLevel) slider.level(), null,
slider.getX(), slider.getY(), slider.getZ(), 50D,
new SliderSignalPacket.DirectionOverride(
Expand Down Expand Up @@ -97,7 +102,9 @@ public void setSignalTick(int signalTick) {
}

public void setOverrideDirection(Slider entity, Direction direction) {
if ((direction == null && !this.hasOverriden) || this.signalTick == 0) return;
this.overrideDirection = direction;
this.hasOverriden = true;
}

public Direction getOverrideDirection(Slider entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ public static RenderType renderType(Slider slider) {
Redux.LOGGER.debug("Slider has no target! Using all-side signal texture...");
return NORMAL;
} else {
Direction toTarget = Slider.calculateDirection(target.getX(), target.getY(), target.getZ());
double x = target.getX() - slider.getX();
double y = target.getY() - slider.getY();
double z = target.getZ() - slider.getZ();
Direction toTarget = Slider.calculateDirection(x, y, z);
return DIRECTIONAL[toTarget.ordinal()];
}
} else return DIRECTIONAL[d.ordinal()];
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public abstract class SliderMixin extends MobMixin {

@Shadow private Direction moveDirection;

@Shadow public abstract int getMoveDelay();

@Inject(method = "getAmbientSound", at = @At("RETURN"), cancellable = true)
protected void redux$getAmbientSound(CallbackInfoReturnable<SoundEvent> cir) {
if (((Slider) (Object) this).isAwake()) {
Expand All @@ -43,7 +45,7 @@ public abstract class SliderMixin extends MobMixin {

@Inject(method = "setMoveDirection", at = @At("HEAD"))
protected void redux$setMoveDirection(Direction moveDirection, CallbackInfo ci) {
if (moveDirection != null && !((Slider) (Object) this).isCritical()) {
if (moveDirection != null && !((Slider) (Object) this).isCritical() && this.getMoveDelay() > 0) {
SliderSignalAttachment.syncDirection((Slider) (Object) this, moveDirection);
}
}
Expand Down

0 comments on commit 33c988d

Please sign in to comment.