3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-03-01 14:10:44 +01:00
Ursprung 92878a39ef
Commit 2d03110f08
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 32 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -22,9 +22,9 @@
*/
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.util.Either;
import com.google.common.base.Preconditions;
public final class Holder<T> implements Either<Integer, T> {
public final class Holder<T> {
private final T value;
private final int id;
@ -39,27 +39,28 @@ public final class Holder<T> implements Either<Integer, T> {
this.id = -1;
}
/**
* Returns true if this holder is backed by a direct value.
*
* @return true if the holder is direct
* @see #hasId()
*/
public boolean isDirect() {
return id == -1;
}
/**
* Returns true if this holder has an id.
*
* @return true if this holder has an id
* @see #isDirect()
*/
public boolean hasId() {
return id != -1;
}
@Override
public boolean isLeft() {
return value != null;
}
@Override
public boolean isRight() {
return value == null;
}
@Override
public Integer left() {
return id;
}
@Override
public T right() {
public T value() {
Preconditions.checkArgument(isDirect(), "Holder is not direct");
return value;
}

Datei anzeigen

@ -26,19 +26,23 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class SoundEvent {
private final String resourceLocation;
private final String identifier;
private final Float fixedRange;
public SoundEvent(final String resourceLocation, @Nullable final Float fixedRange) {
this.resourceLocation = resourceLocation;
public SoundEvent(final String identifier, @Nullable final Float fixedRange) {
this.identifier = identifier;
this.fixedRange = fixedRange;
}
public String resourceLocation() {
return resourceLocation;
public String identifier() {
return identifier;
}
public @Nullable Float fixedRange() {
return fixedRange;
}
public SoundEvent withIdentifier(final String identifier) {
return new SoundEvent(identifier, this.fixedRange);
}
}

Datei anzeigen

@ -43,11 +43,11 @@ public abstract class HolderType<T> extends Type<Holder<T>> {
@Override
public void write(final ByteBuf buffer, final Holder<T> object) throws Exception {
if (object.isLeft()) {
if (object.hasId()) {
Type.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id
} else {
Type.VAR_INT.writePrimitive(buffer, 0);
writeDirect(buffer, object.right());
writeDirect(buffer, object.value());
}
}

Datei anzeigen

@ -37,7 +37,7 @@ public final class SoundEventType extends HolderType<SoundEvent> {
@Override
public void writeDirect(final ByteBuf buffer, final SoundEvent value) throws Exception {
Type.STRING.write(buffer, value.resourceLocation());
Type.STRING.write(buffer, value.identifier());
Type.OPTIONAL_FLOAT.write(buffer, value.fixedRange());
}
}