SoundEvent.java
package com.hypixel.hytale.protocol;
import com.hypixel.hytale.protocol.io.PacketIO;
import com.hypixel.hytale.protocol.io.ProtocolException;
import com.hypixel.hytale.protocol.io.ValidationResult;
import com.hypixel.hytale.protocol.io.VarInt;
import io.netty.buffer.ByteBuf;
import java.util.Arrays;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class SoundEvent {
public static final int NULLABLE_BIT_FIELD_SIZE = 1;
public static final int FIXED_BLOCK_SIZE = 34;
public static final int VARIABLE_FIELD_COUNT = 2;
public static final int VARIABLE_BLOCK_START = 42;
public static ;
String id;
volume;
pitch;
musicDuckingVolume;
ambientDuckingVolume;
maxInstance;
preventSoundInterruption;
startAttenuationDistance;
maxDistance;
SoundEventLayer[] layers;
audioCategory;
{
}
{
.id = id;
.volume = volume;
.pitch = pitch;
.musicDuckingVolume = musicDuckingVolume;
.ambientDuckingVolume = ambientDuckingVolume;
.maxInstance = maxInstance;
.preventSoundInterruption = preventSoundInterruption;
.startAttenuationDistance = startAttenuationDistance;
.maxDistance = maxDistance;
.layers = layers;
.audioCategory = audioCategory;
}
{
.id = other.id;
.volume = other.volume;
.pitch = other.pitch;
.musicDuckingVolume = other.musicDuckingVolume;
.ambientDuckingVolume = other.ambientDuckingVolume;
.maxInstance = other.maxInstance;
.preventSoundInterruption = other.preventSoundInterruption;
.startAttenuationDistance = other.startAttenuationDistance;
.maxDistance = other.maxDistance;
.layers = other.layers;
.audioCategory = other.audioCategory;
}
SoundEvent {
();
buf.getByte(offset);
obj.volume = buf.getFloatLE(offset + );
obj.pitch = buf.getFloatLE(offset + );
obj.musicDuckingVolume = buf.getFloatLE(offset + );
obj.ambientDuckingVolume = buf.getFloatLE(offset + );
obj.maxInstance = buf.getIntLE(offset + );
obj.preventSoundInterruption = buf.getByte(offset + ) != ;
obj.startAttenuationDistance = buf.getFloatLE(offset + );
obj.maxDistance = buf.getFloatLE(offset + );
obj.audioCategory = buf.getIntLE(offset + );
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
VarInt.peek(buf, varPos0);
(idLen < ) {
ProtocolException.negativeLength(, idLen);
}
(idLen > ) {
ProtocolException.stringTooLong(, idLen, );
}
obj.id = PacketIO.readVarString(buf, varPos0, PacketIO.UTF8);
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
VarInt.peek(buf, varPos1);
(layersCount < ) {
ProtocolException.negativeLength(, layersCount);
}
(layersCount > ) {
ProtocolException.arrayTooLong(, layersCount, );
}
VarInt.length(buf, varPos1);
(()(varPos1 + varIntLen) + ()layersCount * > ()buf.readableBytes()) {
ProtocolException.bufferTooSmall(, varPos1 + varIntLen + layersCount * , buf.readableBytes());
}
obj.layers = [layersCount];
varPos1 + varIntLen;
( ; i < layersCount; ++i) {
obj.layers[i] = SoundEventLayer.deserialize(buf, elemPos);
elemPos += SoundEventLayer.computeBytesConsumed(buf, elemPos);
}
}
obj;
}
{
buf.getByte(offset);
;
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset0;
VarInt.peek(buf, pos0);
pos0 += VarInt.length(buf, pos0) + sl;
(pos0 - offset > maxEnd) {
maxEnd = pos0 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset1;
VarInt.peek(buf, pos1);
pos1 += VarInt.length(buf, pos1);
( ; i < arrLen; ++i) {
pos1 += SoundEventLayer.computeBytesConsumed(buf, pos1);
}
(pos1 - offset > maxEnd) {
maxEnd = pos1 - offset;
}
}
maxEnd;
}
{
buf.writerIndex();
;
(.id != ) {
nullBits = ()(nullBits | );
}
(.layers != ) {
nullBits = ()(nullBits | );
}
buf.writeByte(nullBits);
buf.writeFloatLE(.volume);
buf.writeFloatLE(.pitch);
buf.writeFloatLE(.musicDuckingVolume);
buf.writeFloatLE(.ambientDuckingVolume);
buf.writeIntLE(.maxInstance);
buf.writeByte(.preventSoundInterruption ? : );
buf.writeFloatLE(.startAttenuationDistance);
buf.writeFloatLE(.maxDistance);
buf.writeIntLE(.audioCategory);
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
(.id != ) {
buf.setIntLE(idOffsetSlot, buf.writerIndex() - varBlockStart);
PacketIO.writeVarString(buf, .id, );
} {
buf.setIntLE(idOffsetSlot, -);
}
(.layers != ) {
buf.setIntLE(layersOffsetSlot, buf.writerIndex() - varBlockStart);
(.layers.length > ) {
ProtocolException.arrayTooLong(, .layers.length, );
}
VarInt.write(buf, .layers.length);
(SoundEventLayer item : .layers) {
item.serialize(buf);
}
} {
buf.setIntLE(layersOffsetSlot, -);
}
}
{
;
(.id != ) {
size += PacketIO.stringSize(.id);
}
(.layers != ) {
;
(SoundEventLayer elem : .layers) {
layersSize += elem.computeSize();
}
size += VarInt.size(.layers.length) + layersSize;
}
size;
}
ValidationResult {
(buffer.readableBytes() - offset < ) {
ValidationResult.error();
} {
buffer.getByte(offset);
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(idOffset < ) {
ValidationResult.error();
}
offset + + idOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
VarInt.peek(buffer, pos);
(idLen < ) {
ValidationResult.error();
}
(idLen > ) {
ValidationResult.error();
}
pos += VarInt.length(buffer, pos);
pos += idLen;
(pos > buffer.writerIndex()) {
ValidationResult.error();
}
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(layersOffset < ) {
ValidationResult.error();
}
offset + + layersOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
VarInt.peek(buffer, pos);
(layersCount < ) {
ValidationResult.error();
}
(layersCount > ) {
ValidationResult.error();
}
pos += VarInt.length(buffer, pos);
( ; i < layersCount; ++i) {
SoundEventLayer.validateStructure(buffer, pos);
(!structResult.isValid()) {
ValidationResult.error( + i + + structResult.error());
}
pos += SoundEventLayer.computeBytesConsumed(buffer, pos);
}
}
ValidationResult.OK;
}
}
SoundEvent {
();
copy.id = .id;
copy.volume = .volume;
copy.pitch = .pitch;
copy.musicDuckingVolume = .musicDuckingVolume;
copy.ambientDuckingVolume = .ambientDuckingVolume;
copy.maxInstance = .maxInstance;
copy.preventSoundInterruption = .preventSoundInterruption;
copy.startAttenuationDistance = .startAttenuationDistance;
copy.maxDistance = .maxDistance;
copy.layers = .layers != ? (SoundEventLayer[])Arrays.stream(.layers).map((e) -> e.clone()).toArray((x$) -> [x$]) : ;
copy.audioCategory = .audioCategory;
copy;
}
{
( == obj) {
;
} (!(obj SoundEvent)) {
;
} {
(SoundEvent)obj;
Objects.equals(.id, other.id) && .volume == other.volume && .pitch == other.pitch && .musicDuckingVolume == other.musicDuckingVolume && .ambientDuckingVolume == other.ambientDuckingVolume && .maxInstance == other.maxInstance && .preventSoundInterruption == other.preventSoundInterruption && .startAttenuationDistance == other.startAttenuationDistance && .maxDistance == other.maxDistance && Arrays.equals(.layers, other.layers) && .audioCategory == other.audioCategory;
}
}
{
;
result = * result + Objects.hashCode(.id);
result = * result + Float.hashCode(.volume);
result = * result + Float.hashCode(.pitch);
result = * result + Float.hashCode(.musicDuckingVolume);
result = * result + Float.hashCode(.ambientDuckingVolume);
result = * result + Integer.hashCode(.maxInstance);
result = * result + Boolean.hashCode(.preventSoundInterruption);
result = * result + Float.hashCode(.startAttenuationDistance);
result = * result + Float.hashCode(.maxDistance);
result = * result + Arrays.hashCode(.layers);
result = * result + Integer.hashCode(.audioCategory);
result;
}
}