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; 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 T value;
private final int id; private final int id;
@ -39,27 +39,28 @@ public final class Holder<T> implements Either<Integer, T> {
this.id = -1; 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() { 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; return id != -1;
} }
@Override public T value() {
public boolean isLeft() { Preconditions.checkArgument(isDirect(), "Holder is not direct");
return value != null;
}
@Override
public boolean isRight() {
return value == null;
}
@Override
public Integer left() {
return id;
}
@Override
public T right() {
return value; return value;
} }

Datei anzeigen

@ -26,19 +26,23 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class SoundEvent { public final class SoundEvent {
private final String resourceLocation; private final String identifier;
private final Float fixedRange; private final Float fixedRange;
public SoundEvent(final String resourceLocation, @Nullable final Float fixedRange) { public SoundEvent(final String identifier, @Nullable final Float fixedRange) {
this.resourceLocation = resourceLocation; this.identifier = identifier;
this.fixedRange = fixedRange; this.fixedRange = fixedRange;
} }
public String resourceLocation() { public String identifier() {
return resourceLocation; return identifier;
} }
public @Nullable Float fixedRange() { public @Nullable Float fixedRange() {
return 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 @Override
public void write(final ByteBuf buffer, final Holder<T> object) throws Exception { 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 Type.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id
} else { } else {
Type.VAR_INT.writePrimitive(buffer, 0); 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 @Override
public void writeDirect(final ByteBuf buffer, final SoundEvent value) throws Exception { 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()); Type.OPTIONAL_FLOAT.write(buffer, value.fixedRange());
} }
} }