Skip to content

Commit

Permalink
Merge branch 'master' into feat/attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBauHD committed Dec 2, 2023
2 parents a0fe1cf + ea8e955 commit 54ddc08
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: gradle/wrapper-validation-action@v1

- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.sculkpowered.server.world.Vector;
import io.github.sculkpowered.server.world.World;
import java.util.UUID;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -13,7 +14,7 @@
/**
* Represents an entity.
*/
public interface Entity extends Viewable {
public interface Entity extends Viewable, Sound.Emitter {

/**
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gson = "com.google.code.gson:gson:2.10.1"
guava = "com.google.guava:guava:32.1.3-jre"
brigadier = "com.mojang:brigadier:1.0.18"
velocity-native = "com.velocitypowered:velocity-native:3.2.0-SNAPSHOT"
zstd = "com.github.luben:zstd-jni:1.5.5-10"
zstd = "com.github.luben:zstd-jni:1.5.5-11"

junit = "org.junit.jupiter:junit-jupiter:5.10.1"

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.sculkpowered.server.container.SculkContainer;
import io.github.sculkpowered.server.container.item.ItemStack;
import io.github.sculkpowered.server.entity.AbstractLivingEntity;
import io.github.sculkpowered.server.entity.Entity;
import io.github.sculkpowered.server.entity.EntityType;
import io.github.sculkpowered.server.event.connection.PluginMessageEvent;
import io.github.sculkpowered.server.protocol.SculkConnection;
Expand All @@ -35,6 +36,10 @@
import io.github.sculkpowered.server.protocol.packet.play.chunk.CenterChunk;
import io.github.sculkpowered.server.protocol.packet.play.container.ContainerContent;
import io.github.sculkpowered.server.protocol.packet.play.container.OpenScreen;
import io.github.sculkpowered.server.protocol.packet.play.sound.EntitySoundEffect;
import io.github.sculkpowered.server.protocol.packet.play.sound.SoundEffect;
import io.github.sculkpowered.server.protocol.packet.play.sound.StopSound;
import io.github.sculkpowered.server.protocol.packet.play.title.ClearTitles;
import io.github.sculkpowered.server.protocol.packet.play.title.Subtitle;
import io.github.sculkpowered.server.protocol.packet.play.title.TitleAnimationTimes;
import io.github.sculkpowered.server.util.OneInt2ObjectMap;
Expand All @@ -52,6 +57,8 @@
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.permission.PermissionChecker;
import net.kyori.adventure.pointer.Pointers;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.sound.SoundStop;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.TitlePart;
Expand Down Expand Up @@ -314,6 +321,16 @@ public <T> void sendTitlePart(@NotNull TitlePart<T> part, @NotNull T value) {
}
}

@Override
public void clearTitle() {
this.send(new ClearTitles(false));
}

@Override
public void resetTitle() {
this.send(new ClearTitles(true));
}

@Override
public void showBossBar(@NotNull BossBar bar) {
@SuppressWarnings("UnstableApiUsage")
Expand All @@ -332,6 +349,28 @@ public void hideBossBar(@NotNull BossBar bar) {
}
}

@Override
public void playSound(@NotNull Sound sound) {
this.send(new EntitySoundEffect(sound, this.id));
}

@Override
public void playSound(@NotNull Sound sound, double x, double y, double z) {
this.send(new SoundEffect(sound, (int) (x * 8), (int) (y * 8), (int) (z * 8)));
}

@Override
public void playSound(@NotNull Sound sound, @NotNull Sound.Emitter emitter) {
if (emitter instanceof Entity entity) {
this.send(new EntitySoundEffect(sound, entity.id()));
}
}

@Override
public void stopSound(@NotNull SoundStop stop) {
this.send(new StopSound(stop));
}

@NotNull
@Override
public Pointers pointers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
import io.github.sculkpowered.server.protocol.packet.play.scoreboard.DisplayObjective;
import io.github.sculkpowered.server.protocol.packet.play.scoreboard.UpdateObjectives;
import io.github.sculkpowered.server.protocol.packet.play.scoreboard.UpdateScore;
import io.github.sculkpowered.server.protocol.packet.play.sound.EntitySoundEffect;
import io.github.sculkpowered.server.protocol.packet.play.sound.SoundEffect;
import io.github.sculkpowered.server.protocol.packet.play.sound.StopSound;
import io.github.sculkpowered.server.protocol.packet.play.title.ClearTitles;
import io.github.sculkpowered.server.protocol.packet.play.title.Subtitle;
import io.github.sculkpowered.server.protocol.packet.play.title.Title;
Expand Down Expand Up @@ -313,10 +316,10 @@ public enum State {
this.clientBound.skip(); // Update Time
this.clientBound.register(Title.class);
this.clientBound.register(TitleAnimationTimes.class);
this.clientBound.skip(); // Entity Sound Effect
this.clientBound.skip(); // Sound Effect
this.clientBound.register(EntitySoundEffect.class);
this.clientBound.register(SoundEffect.class);
this.clientBound.skip(); // Start Configuration
this.clientBound.skip(); // Stop Sound
this.clientBound.register(StopSound.class);
this.clientBound.register(SystemChatMessage.class);
this.clientBound.register(TabListHeaderFooter.class);
this.clientBound.skip(); // Tag Query Response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.sculkpowered.server.protocol.packet.play.sound;

import io.github.sculkpowered.server.protocol.Buffer;
import io.github.sculkpowered.server.protocol.packet.Packet;
import net.kyori.adventure.sound.Sound;

public final class EntitySoundEffect implements Packet {

private final Sound sound;
private final int entityId;

public EntitySoundEffect(final Sound sound, final int entityId) {
this.sound = sound;
this.entityId = entityId;
}

@Override
public void encode(Buffer buf) {
buf
.writeByte((byte) 0)
.writeString(this.sound.name().asString())
.writeBoolean(false)
.writeVarInt(0)
.writeVarInt(this.entityId)
.writeFloat(this.sound.volume())
.writeFloat(this.sound.pitch())
.writeLong(this.sound.seed().orElse(0));
}

@Override
public String toString() {
return "EntitySoundEffect{" +
"sound=" + this.sound +
", entityId=" + this.entityId +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.sculkpowered.server.protocol.packet.play.sound;

import io.github.sculkpowered.server.protocol.Buffer;
import io.github.sculkpowered.server.protocol.packet.Packet;
import net.kyori.adventure.sound.Sound;

public final class SoundEffect implements Packet {

private final Sound sound;
private final int x;
private final int y;
private final int z;

public SoundEffect(final Sound sound, final int x, final int y, final int z) {
this.sound = sound;
this.x = x;
this.y = y;
this.z = z;
}

@Override
public void encode(Buffer buf) {
buf.writeByte((byte) 0)
.writeString(this.sound.name().asString())
.writeBoolean(false)
.writeVarInt(this.sound.source().ordinal())
.writeInt(this.x)
.writeInt(this.y)
.writeInt(this.z)
.writeFloat(this.sound.volume())
.writeFloat(this.sound.pitch())
.writeLong(this.sound.seed().orElse(0));
}

@Override
public String toString() {
return "SoundEffect{" +
"sound=" + this.sound +
", x=" + this.x +
", y=" + this.y +
", z=" + this.z +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.sculkpowered.server.protocol.packet.play.sound;

import io.github.sculkpowered.server.protocol.Buffer;
import io.github.sculkpowered.server.protocol.packet.Packet;
import java.util.Objects;
import net.kyori.adventure.sound.SoundStop;

public final class StopSound implements Packet {

private final SoundStop stop;

public StopSound(SoundStop stop) {
this.stop = stop;
}

@Override
public void encode(Buffer buf) {
if (this.stop == SoundStop.all()) {
buf.writeByte((byte) 0);
return;
}
var flags = (byte) 0;
if (this.stop.source() != null) {
flags |= 1;
}
if (this.stop.sound() != null) {
flags |= 2;
}
buf.writeByte(flags);
if (this.stop.source() != null) {
buf.writeVarInt(Objects.requireNonNull(this.stop.source()).ordinal());
}
if (this.stop.sound() != null) {
buf.writeString(Objects.requireNonNull(this.stop.sound()).asString());
}
}

@Override
public String toString() {
return "StopSound{" +
"stop=" + this.stop +
'}';
}
}

0 comments on commit 54ddc08

Please sign in to comment.