ApplyForceInteraction.java
package com.hypixel.hytale.protocol;
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.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ApplyForceInteraction extends SimpleInteraction {
public static final int NULLABLE_BIT_FIELD_SIZE = 1;
public static final int FIXED_BLOCK_SIZE = 80;
public static final int VARIABLE_FIELD_COUNT = 6;
public static final int VARIABLE_BLOCK_START ;
;
VelocityConfig velocityConfig;
ChangeVelocityType changeVelocityType;
AppliedForce[] forces;
duration;
FloatRange verticalClamp;
waitForGround;
waitForCollision;
groundCheckDelay;
collisionCheckDelay;
groundNext;
collisionNext;
raycastDistance;
raycastHeightOffset;
RaycastMode raycastMode;
{
.changeVelocityType = ChangeVelocityType.Add;
.raycastMode = RaycastMode.FollowMotion;
}
{
.changeVelocityType = ChangeVelocityType.Add;
.raycastMode = RaycastMode.FollowMotion;
.waitForDataFrom = waitForDataFrom;
.effects = effects;
.horizontalSpeedMultiplier = horizontalSpeedMultiplier;
.runTime = runTime;
.cancelOnItemChange = cancelOnItemChange;
.settings = settings;
.rules = rules;
.tags = tags;
.camera = camera;
.next = next;
.failed = failed;
.velocityConfig = velocityConfig;
.changeVelocityType = changeVelocityType;
.forces = forces;
.duration = duration;
.verticalClamp = verticalClamp;
.waitForGround = waitForGround;
.waitForCollision = waitForCollision;
.groundCheckDelay = groundCheckDelay;
.collisionCheckDelay = collisionCheckDelay;
.groundNext = groundNext;
.collisionNext = collisionNext;
.raycastDistance = raycastDistance;
.raycastHeightOffset = raycastHeightOffset;
.raycastMode = raycastMode;
}
{
.changeVelocityType = ChangeVelocityType.Add;
.raycastMode = RaycastMode.FollowMotion;
.waitForDataFrom = other.waitForDataFrom;
.effects = other.effects;
.horizontalSpeedMultiplier = other.horizontalSpeedMultiplier;
.runTime = other.runTime;
.cancelOnItemChange = other.cancelOnItemChange;
.settings = other.settings;
.rules = other.rules;
.tags = other.tags;
.camera = other.camera;
.next = other.next;
.failed = other.failed;
.velocityConfig = other.velocityConfig;
.changeVelocityType = other.changeVelocityType;
.forces = other.forces;
.duration = other.duration;
.verticalClamp = other.verticalClamp;
.waitForGround = other.waitForGround;
.waitForCollision = other.waitForCollision;
.groundCheckDelay = other.groundCheckDelay;
.collisionCheckDelay = other.collisionCheckDelay;
.groundNext = other.groundNext;
.collisionNext = other.collisionNext;
.raycastDistance = other.raycastDistance;
.raycastHeightOffset = other.raycastHeightOffset;
.raycastMode = other.raycastMode;
}
ApplyForceInteraction {
();
buf.getByte(offset);
obj.waitForDataFrom = WaitForDataFrom.fromValue(buf.getByte(offset + ));
obj.horizontalSpeedMultiplier = buf.getFloatLE(offset + );
obj.runTime = buf.getFloatLE(offset + );
obj.cancelOnItemChange = buf.getByte(offset + ) != ;
obj.next = buf.getIntLE(offset + );
obj.failed = buf.getIntLE(offset + );
((nullBits & ) != ) {
obj.velocityConfig = VelocityConfig.deserialize(buf, offset + );
}
obj.changeVelocityType = ChangeVelocityType.fromValue(buf.getByte(offset + ));
obj.duration = buf.getFloatLE(offset + );
((nullBits & ) != ) {
obj.verticalClamp = FloatRange.deserialize(buf, offset + );
}
obj.waitForGround = buf.getByte(offset + ) != ;
obj.waitForCollision = buf.getByte(offset + ) != ;
obj.groundCheckDelay = buf.getFloatLE(offset + );
obj.collisionCheckDelay = buf.getFloatLE(offset + );
obj.groundNext = buf.getIntLE(offset + );
obj.collisionNext = buf.getIntLE(offset + );
obj.raycastDistance = buf.getFloatLE(offset + );
obj.raycastHeightOffset = buf.getFloatLE(offset + );
obj.raycastMode = RaycastMode.fromValue(buf.getByte(offset + ));
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
obj.effects = InteractionEffects.deserialize(buf, varPos0);
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
VarInt.peek(buf, varPos1);
(settingsCount < ) {
ProtocolException.negativeLength(, settingsCount);
}
(settingsCount > ) {
ProtocolException.dictionaryTooLarge(, settingsCount, );
}
VarInt.length(buf, varPos1);
obj.settings = (settingsCount);
varPos1 + varIntLen;
( ; i < settingsCount; ++i) {
GameMode.fromValue(buf.getByte(dictPos));
++dictPos;
InteractionSettings.deserialize(buf, dictPos);
dictPos += InteractionSettings.computeBytesConsumed(buf, dictPos);
(obj.settings.put(key, val) != ) {
ProtocolException.duplicateKey(, key);
}
}
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
obj.rules = InteractionRules.deserialize(buf, varPos2);
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
VarInt.peek(buf, varPos3);
(tagsCount < ) {
ProtocolException.negativeLength(, tagsCount);
}
(tagsCount > ) {
ProtocolException.arrayTooLong(, tagsCount, );
}
VarInt.length(buf, varPos3);
(()(varPos3 + varIntLen) + ()tagsCount * > ()buf.readableBytes()) {
ProtocolException.bufferTooSmall(, varPos3 + varIntLen + tagsCount * , buf.readableBytes());
}
obj.tags = [tagsCount];
( ; i < tagsCount; ++i) {
obj.tags[i] = buf.getIntLE(varPos3 + varIntLen + i * );
}
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
obj.camera = InteractionCameraSettings.deserialize(buf, varPos4);
}
((nullBits & ) != ) {
offset + + buf.getIntLE(offset + );
VarInt.peek(buf, varPos5);
(forcesCount < ) {
ProtocolException.negativeLength(, forcesCount);
}
(forcesCount > ) {
ProtocolException.arrayTooLong(, forcesCount, );
}
VarInt.length(buf, varPos5);
(()(varPos5 + varIntLen) + ()forcesCount * > ()buf.readableBytes()) {
ProtocolException.bufferTooSmall(, varPos5 + varIntLen + forcesCount * , buf.readableBytes());
}
obj.forces = [forcesCount];
varPos5 + varIntLen;
( ; i < forcesCount; ++i) {
obj.forces[i] = AppliedForce.deserialize(buf, elemPos);
elemPos += AppliedForce.computeBytesConsumed(buf, elemPos);
}
}
obj;
}
{
buf.getByte(offset);
;
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset0;
pos0 += InteractionEffects.computeBytesConsumed(buf, pos0);
(pos0 - offset > maxEnd) {
maxEnd = pos0 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset1;
VarInt.peek(buf, pos1);
pos1 += VarInt.length(buf, pos1);
( ; i < dictLen; ++i) {
++pos1;
pos1 += InteractionSettings.computeBytesConsumed(buf, pos1);
}
(pos1 - offset > maxEnd) {
maxEnd = pos1 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset2;
pos2 += InteractionRules.computeBytesConsumed(buf, pos2);
(pos2 - offset > maxEnd) {
maxEnd = pos2 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset3;
VarInt.peek(buf, pos3);
pos3 += VarInt.length(buf, pos3) + arrLen * ;
(pos3 - offset > maxEnd) {
maxEnd = pos3 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset4;
pos4 += InteractionCameraSettings.computeBytesConsumed(buf, pos4);
(pos4 - offset > maxEnd) {
maxEnd = pos4 - offset;
}
}
((nullBits & ) != ) {
buf.getIntLE(offset + );
offset + + fieldOffset5;
VarInt.peek(buf, pos5);
pos5 += VarInt.length(buf, pos5);
( ; i < arrLen; ++i) {
pos5 += AppliedForce.computeBytesConsumed(buf, pos5);
}
(pos5 - offset > maxEnd) {
maxEnd = pos5 - offset;
}
}
maxEnd;
}
{
buf.writerIndex();
;
(.effects != ) {
nullBits = ()(nullBits | );
}
(.settings != ) {
nullBits = ()(nullBits | );
}
(.rules != ) {
nullBits = ()(nullBits | );
}
(.tags != ) {
nullBits = ()(nullBits | );
}
(.camera != ) {
nullBits = ()(nullBits | );
}
(.velocityConfig != ) {
nullBits = ()(nullBits | );
}
(.forces != ) {
nullBits = ()(nullBits | );
}
(.verticalClamp != ) {
nullBits = ()(nullBits | );
}
buf.writeByte(nullBits);
buf.writeByte(.waitForDataFrom.getValue());
buf.writeFloatLE(.horizontalSpeedMultiplier);
buf.writeFloatLE(.runTime);
buf.writeByte(.cancelOnItemChange ? : );
buf.writeIntLE(.next);
buf.writeIntLE(.failed);
(.velocityConfig != ) {
.velocityConfig.serialize(buf);
} {
buf.writeZero();
}
buf.writeByte(.changeVelocityType.getValue());
buf.writeFloatLE(.duration);
(.verticalClamp != ) {
.verticalClamp.serialize(buf);
} {
buf.writeZero();
}
buf.writeByte(.waitForGround ? : );
buf.writeByte(.waitForCollision ? : );
buf.writeFloatLE(.groundCheckDelay);
buf.writeFloatLE(.collisionCheckDelay);
buf.writeIntLE(.groundNext);
buf.writeIntLE(.collisionNext);
buf.writeFloatLE(.raycastDistance);
buf.writeFloatLE(.raycastHeightOffset);
buf.writeByte(.raycastMode.getValue());
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
buf.writeIntLE();
buf.writerIndex();
(.effects != ) {
buf.setIntLE(effectsOffsetSlot, buf.writerIndex() - varBlockStart);
.effects.serialize(buf);
} {
buf.setIntLE(effectsOffsetSlot, -);
}
(.settings != ) {
buf.setIntLE(settingsOffsetSlot, buf.writerIndex() - varBlockStart);
(.settings.size() > ) {
ProtocolException.dictionaryTooLarge(, .settings.size(), );
}
VarInt.write(buf, .settings.size());
(Map.Entry<GameMode, InteractionSettings> e : .settings.entrySet()) {
buf.writeByte(((GameMode)e.getKey()).getValue());
((InteractionSettings)e.getValue()).serialize(buf);
}
} {
buf.setIntLE(settingsOffsetSlot, -);
}
(.rules != ) {
buf.setIntLE(rulesOffsetSlot, buf.writerIndex() - varBlockStart);
.rules.serialize(buf);
} {
buf.setIntLE(rulesOffsetSlot, -);
}
(.tags != ) {
buf.setIntLE(tagsOffsetSlot, buf.writerIndex() - varBlockStart);
(.tags.length > ) {
ProtocolException.arrayTooLong(, .tags.length, );
}
VarInt.write(buf, .tags.length);
( item : .tags) {
buf.writeIntLE(item);
}
} {
buf.setIntLE(tagsOffsetSlot, -);
}
(.camera != ) {
buf.setIntLE(cameraOffsetSlot, buf.writerIndex() - varBlockStart);
.camera.serialize(buf);
} {
buf.setIntLE(cameraOffsetSlot, -);
}
(.forces != ) {
buf.setIntLE(forcesOffsetSlot, buf.writerIndex() - varBlockStart);
(.forces.length > ) {
ProtocolException.arrayTooLong(, .forces.length, );
}
VarInt.write(buf, .forces.length);
(AppliedForce item : .forces) {
item.serialize(buf);
}
} {
buf.setIntLE(forcesOffsetSlot, -);
}
buf.writerIndex() - startPos;
}
{
;
(.effects != ) {
size += .effects.computeSize();
}
(.settings != ) {
size += VarInt.size(.settings.size()) + .settings.size() * ;
}
(.rules != ) {
size += .rules.computeSize();
}
(.tags != ) {
size += VarInt.size(.tags.length) + .tags.length * ;
}
(.camera != ) {
size += .camera.computeSize();
}
(.forces != ) {
size += VarInt.size(.forces.length) + .forces.length * ;
}
size;
}
ValidationResult {
(buffer.readableBytes() - offset < ) {
ValidationResult.error();
} {
buffer.getByte(offset);
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(effectsOffset < ) {
ValidationResult.error();
}
offset + + effectsOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
InteractionEffects.validateStructure(buffer, pos);
(!effectsResult.isValid()) {
ValidationResult.error( + effectsResult.error());
}
pos += InteractionEffects.computeBytesConsumed(buffer, pos);
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(settingsOffset < ) {
ValidationResult.error();
}
offset + + settingsOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
VarInt.peek(buffer, pos);
(settingsCount < ) {
ValidationResult.error();
}
(settingsCount > ) {
ValidationResult.error();
}
pos += VarInt.length(buffer, pos);
( ; i < settingsCount; ++i) {
++pos;
++pos;
}
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(rulesOffset < ) {
ValidationResult.error();
}
offset + + rulesOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
InteractionRules.validateStructure(buffer, pos);
(!rulesResult.isValid()) {
ValidationResult.error( + rulesResult.error());
}
pos += InteractionRules.computeBytesConsumed(buffer, pos);
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(tagsOffset < ) {
ValidationResult.error();
}
offset + + tagsOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
VarInt.peek(buffer, pos);
(tagsCount < ) {
ValidationResult.error();
}
(tagsCount > ) {
ValidationResult.error();
}
pos += VarInt.length(buffer, pos);
pos += tagsCount * ;
(pos > buffer.writerIndex()) {
ValidationResult.error();
}
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(cameraOffset < ) {
ValidationResult.error();
}
offset + + cameraOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
InteractionCameraSettings.validateStructure(buffer, pos);
(!cameraResult.isValid()) {
ValidationResult.error( + cameraResult.error());
}
pos += InteractionCameraSettings.computeBytesConsumed(buffer, pos);
}
((nullBits & ) != ) {
buffer.getIntLE(offset + );
(forcesOffset < ) {
ValidationResult.error();
}
offset + + forcesOffset;
(pos >= buffer.writerIndex()) {
ValidationResult.error();
}
VarInt.peek(buffer, pos);
(forcesCount < ) {
ValidationResult.error();
}
(forcesCount > ) {
ValidationResult.error();
}
pos += VarInt.length(buffer, pos);
pos += forcesCount * ;
(pos > buffer.writerIndex()) {
ValidationResult.error();
}
}
ValidationResult.OK;
}
}
ApplyForceInteraction {
();
copy.waitForDataFrom = .waitForDataFrom;
copy.effects = .effects != ? .effects.clone() : ;
copy.horizontalSpeedMultiplier = .horizontalSpeedMultiplier;
copy.runTime = .runTime;
copy.cancelOnItemChange = .cancelOnItemChange;
(.settings != ) {
Map<GameMode, InteractionSettings> m = ();
(Map.Entry<GameMode, InteractionSettings> e : .settings.entrySet()) {
m.put((GameMode)e.getKey(), ((InteractionSettings)e.getValue()).clone());
}
copy.settings = m;
}
copy.rules = .rules != ? .rules.clone() : ;
copy.tags = .tags != ? Arrays.copyOf(.tags, .tags.length) : ;
copy.camera = .camera != ? .camera.clone() : ;
copy.next = .next;
copy.failed = .failed;
copy.velocityConfig = .velocityConfig != ? .velocityConfig.clone() : ;
copy.changeVelocityType = .changeVelocityType;
copy.forces = .forces != ? (AppliedForce[])Arrays.stream(.forces).map((ex) -> ex.clone()).toArray((x$) -> [x$]) : ;
copy.duration = .duration;
copy.verticalClamp = .verticalClamp != ? .verticalClamp.clone() : ;
copy.waitForGround = .waitForGround;
copy.waitForCollision = .waitForCollision;
copy.groundCheckDelay = .groundCheckDelay;
copy.collisionCheckDelay = .collisionCheckDelay;
copy.groundNext = .groundNext;
copy.collisionNext = .collisionNext;
copy.raycastDistance = .raycastDistance;
copy.raycastHeightOffset = .raycastHeightOffset;
copy.raycastMode = .raycastMode;
copy;
}
{
( == obj) {
;
} (!(obj ApplyForceInteraction)) {
;
} {
(ApplyForceInteraction)obj;
Objects.equals(.waitForDataFrom, other.waitForDataFrom) && Objects.equals(.effects, other.effects) && .horizontalSpeedMultiplier == other.horizontalSpeedMultiplier && .runTime == other.runTime && .cancelOnItemChange == other.cancelOnItemChange && Objects.equals(.settings, other.settings) && Objects.equals(.rules, other.rules) && Arrays.equals(.tags, other.tags) && Objects.equals(.camera, other.camera) && .next == other.next && .failed == other.failed && Objects.equals(.velocityConfig, other.velocityConfig) && Objects.equals(.changeVelocityType, other.changeVelocityType) && Arrays.equals(.forces, other.forces) && .duration == other.duration && Objects.equals(.verticalClamp, other.verticalClamp) && .waitForGround == other.waitForGround && .waitForCollision == other.waitForCollision && .groundCheckDelay == other.groundCheckDelay && .collisionCheckDelay == other.collisionCheckDelay && .groundNext == other.groundNext && .collisionNext == other.collisionNext && .raycastDistance == other.raycastDistance && .raycastHeightOffset == other.raycastHeightOffset && Objects.equals(.raycastMode, other.raycastMode);
}
}
{
;
result = * result + Objects.hashCode(.waitForDataFrom);
result = * result + Objects.hashCode(.effects);
result = * result + Float.hashCode(.horizontalSpeedMultiplier);
result = * result + Float.hashCode(.runTime);
result = * result + Boolean.hashCode(.cancelOnItemChange);
result = * result + Objects.hashCode(.settings);
result = * result + Objects.hashCode(.rules);
result = * result + Arrays.hashCode(.tags);
result = * result + Objects.hashCode(.camera);
result = * result + Integer.hashCode(.next);
result = * result + Integer.hashCode(.failed);
result = * result + Objects.hashCode(.velocityConfig);
result = * result + Objects.hashCode(.changeVelocityType);
result = * result + Arrays.hashCode(.forces);
result = * result + Float.hashCode(.duration);
result = * result + Objects.hashCode(.verticalClamp);
result = * result + Boolean.hashCode(.waitForGround);
result = * result + Boolean.hashCode(.waitForCollision);
result = * result + Float.hashCode(.groundCheckDelay);
result = * result + Float.hashCode(.collisionCheckDelay);
result = * result + Integer.hashCode(.groundNext);
result = * result + Integer.hashCode(.collisionNext);
result = * result + Float.hashCode(.raycastDistance);
result = * result + Float.hashCode(.raycastHeightOffset);
result = * result + Objects.hashCode(.raycastMode);
result;
}
}