mirror of
https://github.com/ViaVersion/ViaRewind.git
synced 2026-11-04 17:00:20 -05:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
667493a671 |
No files matched your search
@@ -55,8 +55,8 @@ public class ViaRewindConfig extends Config implements com.viaversion.viarewind.
|
||||
cooldownIndicator = CooldownIndicator.valueOf(getString("cooldown-indicator", "TITLE").toUpperCase());
|
||||
replaceAdventureMode = getBoolean("replace-adventure", false);
|
||||
replaceParticles = getBoolean("replace-particles", false);
|
||||
maxBookPages = getInt("max-book-pages", 100);
|
||||
maxBookPageSize = getInt("max-book-page-length", 5000);
|
||||
maxBookPages = getInt("end-book-pages", 100);
|
||||
maxBookPageSize = getInt("end-book-page-length", 5000);
|
||||
emulateWorldBorder = getBoolean("emulate-world-border", true);
|
||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||
worldBorderParticle = getString("world-border-particle", "fireworksSpark");
|
||||
|
||||
@@ -54,14 +54,14 @@ public interface ViaRewindConfig extends Config {
|
||||
/**
|
||||
* Max amount of pages for written books before a client gets kicked
|
||||
*
|
||||
* @return the max amount of pages
|
||||
* @return the end amount of pages
|
||||
*/
|
||||
int getMaxBookPages();
|
||||
|
||||
/**
|
||||
* Max amount of characters in the json (!) string of a book page before a client gets kicked
|
||||
*
|
||||
* @return the max amount of characters
|
||||
* @return the end amount of characters
|
||||
*/
|
||||
int getMaxBookPageSize();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RewindMappingData extends BackwardsMappingData {
|
||||
public final class RewindMappingData extends BackwardsMappingData {
|
||||
|
||||
public RewindMappingData(String unmappedVersion, String mappedVersion) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
@@ -37,4 +37,5 @@ public class RewindMappingData extends BackwardsMappingData {
|
||||
protected CompoundTag readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadNBTFromDir(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import com.viaversion.viarewind.ViaRewind;
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
public final class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
|
||||
public static final RewindMappingDataLoader INSTANCE = new RewindMappingDataLoader();
|
||||
|
||||
@@ -30,7 +30,6 @@ public class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
super(RewindMappingDataLoader.class, "assets/viarewind/data/");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
@@ -40,4 +39,5 @@ public class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
public File getDataFolder() {
|
||||
return ViaRewind.getPlatform().getDataFolder();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
public enum EntityDataTypes1_7_6_10 implements EntityDataType {
|
||||
|
||||
BYTE(0, Types.BYTE),
|
||||
SHORT(1, Types.SHORT),
|
||||
INT(2, Types.INT),
|
||||
@@ -34,12 +35,12 @@ public enum EntityDataTypes1_7_6_10 implements EntityDataType {
|
||||
private final int typeID;
|
||||
private final Type<?> type;
|
||||
|
||||
EntityDataTypes1_7_6_10(int typeID, Type<?> type) {
|
||||
EntityDataTypes1_7_6_10(final int typeID, final Type<?> type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static EntityDataTypes1_7_6_10 byId(int id) {
|
||||
public static EntityDataTypes1_7_6_10 byId(final int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@@ -52,4 +53,5 @@ public enum EntityDataTypes1_7_6_10 implements EntityDataType {
|
||||
public Type<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
+2
-14
@@ -17,20 +17,8 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class AABB {
|
||||
Vector3d min;
|
||||
Vector3d max;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3d;
|
||||
|
||||
public AABB(Vector3d min, Vector3d max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
public record Box(Vector3d start, Vector3d end) {
|
||||
|
||||
public Vector3d getMin() {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public Vector3d getMax() {
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class Ray3d {
|
||||
Vector3d start;
|
||||
Vector3d dir;
|
||||
|
||||
public Ray3d(Vector3d start, Vector3d dir) {
|
||||
this.start = start;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public Vector3d getStart() {
|
||||
return this.start;
|
||||
}
|
||||
|
||||
public Vector3d getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
}
|
||||
@@ -17,42 +17,58 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class RayTracing {
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3d;
|
||||
|
||||
public static Vector3d trace(Ray3d ray, AABB aabb, double distance) {
|
||||
Vector3d invDir = new Vector3d(1f / ray.dir.x, 1f / ray.dir.y, 1f / ray.dir.z);
|
||||
public final class RayTracing {
|
||||
|
||||
boolean signDirX = invDir.x < 0;
|
||||
boolean signDirY = invDir.y < 0;
|
||||
boolean signDirZ = invDir.z < 0;
|
||||
public static Vector3d trace(final Box ray, final Box box, final double distance) {
|
||||
final Vector3d invDir = new Vector3d(1f / ray.end().x(), 1f / ray.end().y(), 1f / ray.end().z());
|
||||
|
||||
Vector3d bbox = signDirX ? aabb.max : aabb.min;
|
||||
double tmin = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirX ? aabb.min : aabb.max;
|
||||
double tmax = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirY ? aabb.max : aabb.min;
|
||||
double tymin = (bbox.y - ray.start.y) * invDir.y;
|
||||
bbox = signDirY ? aabb.min : aabb.max;
|
||||
double tymax = (bbox.y - ray.start.y) * invDir.y;
|
||||
final boolean signDirX = invDir.x() < 0;
|
||||
final boolean signDirY = invDir.y() < 0;
|
||||
final boolean signDirZ = invDir.z() < 0;
|
||||
|
||||
if (tmin > tymax || tymin > tmax) return null;
|
||||
Vector3d boundingBox = signDirX ? box.end() : box.start();
|
||||
double tmin = (boundingBox.x() - ray.start().x()) * invDir.x();
|
||||
boundingBox = signDirX ? box.start() : box.end();
|
||||
double tmax = (boundingBox.x() - ray.start().x()) * invDir.x();
|
||||
boundingBox = signDirY ? box.end() : box.start();
|
||||
final double tymin = (boundingBox.y() - ray.start().y()) * invDir.y();
|
||||
boundingBox = signDirY ? box.start() : box.end();
|
||||
final double tymax = (boundingBox.y() - ray.start().y()) * invDir.y();
|
||||
|
||||
if (tymin > tmin) tmin = tymin;
|
||||
if (tmin > tymax || tymin > tmax) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (tymax < tmax) tmax = tymax;
|
||||
if (tymin > tmin) {
|
||||
tmin = tymin;
|
||||
}
|
||||
if (tymax < tmax) {
|
||||
tmax = tymax;
|
||||
}
|
||||
|
||||
bbox = signDirZ ? aabb.max : aabb.min;
|
||||
double tzmin = (bbox.z - ray.start.z) * invDir.z;
|
||||
bbox = signDirZ ? aabb.min : aabb.max;
|
||||
double tzmax = (bbox.z - ray.start.z) * invDir.z;
|
||||
boundingBox = signDirZ ? box.end() : box.start();
|
||||
double tzmin = (boundingBox.z() - ray.start().z()) * invDir.z();
|
||||
boundingBox = signDirZ ? box.start() : box.end();
|
||||
double tzmax = (boundingBox.z() - ray.start().z()) * invDir.z();
|
||||
|
||||
if (tmin > tzmax || tzmin > tmax) return null;
|
||||
if (tmin > tzmax || tzmin > tmax) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (tzmin > tmin) tmin = tzmin;
|
||||
if (tzmin > tmin) {
|
||||
tmin = tzmin;
|
||||
}
|
||||
if (tzmax < tmax) {
|
||||
tmax = tzmax;
|
||||
}
|
||||
|
||||
if (tzmax < tmax) tmax = tzmax;
|
||||
if (tmin <= distance && tmax > 0) {
|
||||
// ray.start().clone().add(ray.dir().clone().normalize().multiply(tmin))
|
||||
}
|
||||
|
||||
return tmin <= distance && tmax > 0 ? ray.start.clone().add(ray.dir.clone().normalize().multiply(tmin)) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Vector3d {
|
||||
double x, y, z;
|
||||
|
||||
public Vector3d(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3d() {
|
||||
}
|
||||
|
||||
public void set(Vector3d vec) {
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
this.z = vec.z;
|
||||
}
|
||||
|
||||
public Vector3d set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d multiply(double a) {
|
||||
this.x *= a;
|
||||
this.y *= a;
|
||||
this.z *= a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d add(Vector3d vec) {
|
||||
this.x += vec.x;
|
||||
this.y += vec.y;
|
||||
this.z += vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d substract(Vector3d vec) {
|
||||
this.x -= vec.x;
|
||||
this.y -= vec.y;
|
||||
this.z -= vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
public double lengthSquared() {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public Vector3d normalize() {
|
||||
double length = length();
|
||||
multiply(1.0 / length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3d clone() {
|
||||
return new Vector3d(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Vector3d vector3d = (Vector3d) o;
|
||||
return Double.compare(vector3d.x, x) == 0 && Double.compare(vector3d.y, y) == 0 && Double.compare(vector3d.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector3d{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
-1
@@ -130,7 +130,6 @@ public class Protocol1_8To1_7_6_10 extends BackwardsProtocol<ClientboundPackets1
|
||||
connection.put(new GameProfileStorage(connection));
|
||||
connection.put(new ScoreboardTracker(connection));
|
||||
connection.put(new CompressionStatusTracker(connection));
|
||||
connection.put(new WorldBorderEmulator(connection));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -18,14 +18,14 @@
|
||||
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.data;
|
||||
|
||||
import com.viaversion.viarewind.api.minecraft.entitydata.EntityDataTypes1_7_6_10;
|
||||
import com.viaversion.viarewind.api.minecraft.math.AABB;
|
||||
import com.viaversion.viarewind.api.minecraft.math.Vector3d;
|
||||
import com.viaversion.viarewind.api.minecraft.math.Box;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.EntityPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.EntityTracker1_8;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3d;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
|
||||
@@ -328,14 +328,14 @@ public class VirtualHologramEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public AABB getBoundingBox() {
|
||||
public Box getBoundingBox() {
|
||||
final double width = this.small ? 0.25 : 0.5;
|
||||
final double height = this.small ? 0.9875 : 1.975;
|
||||
|
||||
final Vector3d min = new Vector3d(this.locX - width / 2, this.locY, this.locZ - width / 2);
|
||||
final Vector3d max = new Vector3d(this.locX + width / 2, this.locY + height, this.locZ + width / 2);
|
||||
|
||||
return new AABB(min, max);
|
||||
return new Box(min, max);
|
||||
}
|
||||
|
||||
private int additionalEntityId() {
|
||||
|
||||
+6
-8
@@ -21,10 +21,8 @@ import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.minecraft.math.AABB;
|
||||
import com.viaversion.viarewind.api.minecraft.math.Ray3d;
|
||||
import com.viaversion.viarewind.api.minecraft.math.Box;
|
||||
import com.viaversion.viarewind.api.minecraft.math.RayTracing;
|
||||
import com.viaversion.viarewind.api.minecraft.math.Vector3d;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ServerboundPackets1_7_2_5;
|
||||
@@ -146,8 +144,8 @@ public class PlayerPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10>
|
||||
return;
|
||||
}
|
||||
|
||||
// On 1.8 clients when the player respawns it keeps all metadata and sets player back to max HP
|
||||
// 1.7 clients do not copy the metadata but do set the health to max HP
|
||||
// On 1.8 clients when the player respawns it keeps all metadata and sets player back to end HP
|
||||
// 1.7 clients do not copy the metadata but do set the health to end HP
|
||||
// to match the same client logic we remove the HP metadata as otherwise the client would be set to their old HP before respawning
|
||||
final List<EntityData> entityDataList = new ArrayList<>(tracker.getEntityData());
|
||||
entityDataList.removeIf(entityData -> entityData.id() == 6);
|
||||
@@ -541,20 +539,20 @@ public class PlayerPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10>
|
||||
}
|
||||
|
||||
wrapper.set(Types.VAR_INT, 0, entityId);
|
||||
final AABB boundingBox = tracker.getHolograms().get(entityId).getBoundingBox();
|
||||
final Box boundingBox = tracker.getHolograms().get(entityId).getBoundingBox();
|
||||
|
||||
Vector3d pos = new Vector3d(position.getPosX(), position.getPosY() + 1.8, position.getPosZ());
|
||||
double yaw = Math.toRadians(position.yaw);
|
||||
double pitch = Math.toRadians(position.pitch);
|
||||
|
||||
Vector3d dir = new Vector3d(-Math.cos(pitch) * Math.sin(yaw), -Math.sin(pitch), Math.cos(pitch) * Math.cos(yaw));
|
||||
Ray3d ray = new Ray3d(pos, dir);
|
||||
Rotation ray = new Rotation(pos, dir);
|
||||
Vector3d intersection = RayTracing.trace(ray, boundingBox, 5.0);
|
||||
|
||||
if (intersection == null) {
|
||||
return;
|
||||
}
|
||||
intersection.substract(boundingBox.getMin());
|
||||
intersection.substract(boundingBox.start());
|
||||
|
||||
wrapper.set(Types.VAR_INT, 1, 2);
|
||||
wrapper.write(Types.FLOAT, (float) intersection.getX());
|
||||
|
||||
+42
-31
@@ -24,6 +24,7 @@ import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.data.Particles1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
@@ -224,12 +225,7 @@ public class WorldPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10>
|
||||
columnData[i + 3] = data[column + i * columns];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) columnData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(columnData.length), columnData); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
sendMapItemData(wrapper.user(), id, columnData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,12 +238,7 @@ public class WorldPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10>
|
||||
iconData[i * 3 + 3] = icons[i * 4 + 2];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) iconData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(iconData.length), iconData); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
sendMapItemData(wrapper.user(), id, iconData);
|
||||
}
|
||||
|
||||
// Update scale
|
||||
@@ -259,35 +250,55 @@ public class WorldPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10>
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // position
|
||||
map(Types.UNSIGNED_BYTE); // action
|
||||
map(Types.NAMED_COMPOUND_TAG, RewindTypes.COMPRESSED_NBT); // nbt
|
||||
}
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, wrapper -> {
|
||||
wrapper.passthroughAndMap(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // Position
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Action
|
||||
wrapper.passthroughAndMap(Types.NAMED_COMPOUND_TAG, RewindTypes.COMPRESSED_NBT); // Tag
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.CHANGE_DIFFICULTY);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_BORDER, null, wrapper -> {
|
||||
final WorldBorderEmulator emulator = wrapper.user().get(WorldBorderEmulator.class);
|
||||
wrapper.cancel();
|
||||
|
||||
final int action = wrapper.read(Types.VAR_INT);
|
||||
if (action == 3) { // initialize
|
||||
final double x = wrapper.read(Types.DOUBLE);
|
||||
final double z = wrapper.read(Types.DOUBLE);
|
||||
final double oldRadius = wrapper.read(Types.DOUBLE);
|
||||
final double newRadius = wrapper.read(Types.DOUBLE);
|
||||
final long speed = wrapper.read(Types.VAR_LONG);
|
||||
|
||||
wrapper.user().put(new WorldBorderEmulator(wrapper.user(), x, z, oldRadius, newRadius, speed));
|
||||
}
|
||||
|
||||
final WorldBorderEmulator emulator = wrapper.user().get(WorldBorderEmulator.class);
|
||||
if (emulator == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == 0) { // set size
|
||||
emulator.setSize(wrapper.read(Types.DOUBLE)); // radius
|
||||
} else if (action == 1) { // lerp size
|
||||
emulator.lerpSize(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), wrapper.read(Types.VAR_LONG)); // old radius, new radius, speed
|
||||
final double radius = wrapper.read(Types.DOUBLE);
|
||||
emulator.setSize(radius);
|
||||
} else if (action == 1) { // delta size
|
||||
final double oldRadius = wrapper.read(Types.DOUBLE);
|
||||
final double newRadius = wrapper.read(Types.DOUBLE);
|
||||
final long speed = wrapper.read(Types.VAR_LONG);
|
||||
emulator.updateDeltaTime(oldRadius, newRadius, speed);
|
||||
} else if (action == 2) { // set center
|
||||
emulator.setCenter(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE)); // x, z
|
||||
} else if (action == 3) { // initialize
|
||||
emulator.init(
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // x, z
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // old radius, new radius
|
||||
wrapper.read(Types.VAR_LONG) // speed
|
||||
);
|
||||
final double x = wrapper.read(Types.DOUBLE);
|
||||
final double z = wrapper.read(Types.DOUBLE);
|
||||
emulator.setCenter(x, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendMapItemData(final UserConnection connection, final int id, final byte[] columnData) {
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, connection);
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) columnData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(columnData.length), columnData); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
|
||||
}
|
||||
+57
-56
@@ -30,7 +30,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ScoreboardTracker extends StoredObject {
|
||||
public final class ScoreboardTracker extends StoredObject {
|
||||
|
||||
private final HashMap<String, List<String>> teams = new HashMap<>();
|
||||
private final HashSet<String> objectives = new HashSet<>();
|
||||
private final HashMap<String, ScoreTeam> scoreTeams = new HashMap<>();
|
||||
@@ -40,76 +41,74 @@ public class ScoreboardTracker extends StoredObject {
|
||||
private final HashMap<String, String> teamNameTagVisibilities = new HashMap<>();
|
||||
private String colorIndependentSidebar;
|
||||
|
||||
public ScoreboardTracker(UserConnection user) {
|
||||
public ScoreboardTracker(final UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void addPlayerToTeam(String player, String team) {
|
||||
public void addPlayerToTeam(final String player, final String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>()).add(player);
|
||||
}
|
||||
|
||||
public void setTeamColor(String team, Byte color) {
|
||||
public void setTeamColor(final String team, final Byte color) {
|
||||
teamColors.put(team, color);
|
||||
}
|
||||
|
||||
public Optional<Byte> getTeamColor(String team) {
|
||||
public Optional<Byte> getTeamColor(final String team) {
|
||||
return Optional.ofNullable(teamColors.get(team));
|
||||
}
|
||||
|
||||
public void addTeam(String team) {
|
||||
public void addTeam(final String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>());
|
||||
}
|
||||
|
||||
public void removeTeam(String team) {
|
||||
public void removeTeam(final String team) {
|
||||
teams.remove(team);
|
||||
scoreTeams.remove(team);
|
||||
teamColors.remove(team);
|
||||
teamNameTagVisibilities.remove(team);
|
||||
}
|
||||
|
||||
public boolean teamExists(String team) {
|
||||
public boolean teamExists(final String team) {
|
||||
return teams.containsKey(team);
|
||||
}
|
||||
|
||||
public void removePlayerFromTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
if (teamPlayers != null) teamPlayers.remove(player);
|
||||
final List<String> teamPlayers = teams.get(team);
|
||||
if (teamPlayers != null) {
|
||||
teamPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
public boolean isPlayerInTeam(final String player, final String team) {
|
||||
final List<String> teamPlayers = teams.get(team);
|
||||
return teamPlayers != null && teamPlayers.contains(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player) {
|
||||
for (List<String> teamPlayers : teams.values()) {
|
||||
if (teamPlayers.contains(player)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
public Optional<Byte> getPlayerTeamColor(final String player) {
|
||||
final Optional<String> team = getTeam(player);
|
||||
return team.flatMap(this::getTeamColor);
|
||||
}
|
||||
|
||||
public Optional<Byte> getPlayerTeamColor(String player) {
|
||||
Optional<String> team = getTeam(player);
|
||||
return team.isPresent() ? getTeamColor(team.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<String> getTeam(String player) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet())
|
||||
if (entry.getValue().contains(player))
|
||||
public Optional<String> getTeam(final String player) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet()) {
|
||||
if (entry.getValue().contains(player)) {
|
||||
return Optional.of(entry.getKey());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void setTeamNameTagVisibility(String team, String visibility) {
|
||||
public void setTeamNameTagVisibility(final String team, final String visibility) {
|
||||
teamNameTagVisibilities.put(team, visibility);
|
||||
}
|
||||
|
||||
public String getTeamNameTagVisibility(String team) {
|
||||
public String getTeamNameTagVisibility(final String team) {
|
||||
return teamNameTagVisibilities.getOrDefault(team, "always");
|
||||
}
|
||||
|
||||
public boolean isNametagHidden(String username) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet()) {
|
||||
public boolean isNametagHidden(final String username) {
|
||||
for (final Map.Entry<String, List<String>> entry : teams.entrySet()) {
|
||||
if (entry.getValue().contains(username)) {
|
||||
return "never".equalsIgnoreCase(teamNameTagVisibilities.getOrDefault(entry.getKey(), "always"));
|
||||
}
|
||||
@@ -117,15 +116,15 @@ public class ScoreboardTracker extends StoredObject {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getTeamMembers(String team) {
|
||||
public List<String> getTeamMembers(final String team) {
|
||||
return teams.getOrDefault(team, new ArrayList<>());
|
||||
}
|
||||
|
||||
public void addObjective(String name) {
|
||||
public void addObjective(final String name) {
|
||||
objectives.add(name);
|
||||
}
|
||||
|
||||
public void removeObjective(String name) {
|
||||
public void removeObjective(final String name) {
|
||||
objectives.remove(name);
|
||||
colorDependentSidebar.values().remove(name);
|
||||
if (name.equals(colorIndependentSidebar)) {
|
||||
@@ -133,13 +132,19 @@ public class ScoreboardTracker extends StoredObject {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean objectiveExists(String name) {
|
||||
public boolean objectiveExists(final String name) {
|
||||
return objectives.contains(name);
|
||||
}
|
||||
|
||||
public String sendTeamForScore(String score) {
|
||||
if (score.length() <= 16) return score;
|
||||
if (scoreTeams.containsKey(score)) return scoreTeams.get(score).name;
|
||||
public String sendTeamForScore(final String score) {
|
||||
if (score.length() <= 16) {
|
||||
return score;
|
||||
}
|
||||
|
||||
if (scoreTeams.containsKey(score)) {
|
||||
return scoreTeams.get(score).name;
|
||||
}
|
||||
|
||||
int l = 16;
|
||||
int i = Math.min(16, score.length() - 16);
|
||||
String name = score.substring(i, i + l);
|
||||
@@ -147,19 +152,21 @@ public class ScoreboardTracker extends StoredObject {
|
||||
i--;
|
||||
while (score.length() - l - i > 16) {
|
||||
l--;
|
||||
if (l < 1) return score;
|
||||
if (l < 1) {
|
||||
return score;
|
||||
}
|
||||
i = Math.min(16, score.length() - l);
|
||||
}
|
||||
name = score.substring(i, i + l);
|
||||
}
|
||||
String prefix = score.substring(0, i);
|
||||
String suffix = i + l >= score.length() ? "" : score.substring(i + l);
|
||||
final String prefix = score.substring(0, i);
|
||||
final String suffix = i + l >= score.length() ? "" : score.substring(i + l);
|
||||
|
||||
ScoreTeam scoreTeam = new ScoreTeam(name, prefix, suffix);
|
||||
final ScoreTeam scoreTeam = new ScoreTeam(name, prefix, suffix);
|
||||
scoreTeams.put(score, scoreTeam);
|
||||
scoreTeamNames.add(name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, user());
|
||||
teamPacket.write(Types.STRING, name);
|
||||
teamPacket.write(Types.BYTE, (byte) 0);
|
||||
teamPacket.write(Types.STRING, "ViaRewind");
|
||||
@@ -173,12 +180,15 @@ public class ScoreboardTracker extends StoredObject {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String removeTeamForScore(String score) {
|
||||
ScoreTeam scoreTeam = scoreTeams.remove(score);
|
||||
if (scoreTeam == null) return score;
|
||||
public String removeTeamForScore(final String score) {
|
||||
final ScoreTeam scoreTeam = scoreTeams.remove(score);
|
||||
if (scoreTeam == null) {
|
||||
return score;
|
||||
}
|
||||
|
||||
scoreTeamNames.remove(scoreTeam.name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
final PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, user());
|
||||
teamPacket.write(Types.STRING, scoreTeam.name);
|
||||
teamPacket.write(Types.BYTE, (byte) 1);
|
||||
teamPacket.send(Protocol1_8To1_7_6_10.class);
|
||||
@@ -190,7 +200,7 @@ public class ScoreboardTracker extends StoredObject {
|
||||
return this.colorIndependentSidebar;
|
||||
}
|
||||
|
||||
public void setColorIndependentSidebar(String colorIndependentSidebar) {
|
||||
public void setColorIndependentSidebar(final String colorIndependentSidebar) {
|
||||
this.colorIndependentSidebar = colorIndependentSidebar;
|
||||
}
|
||||
|
||||
@@ -198,15 +208,6 @@ public class ScoreboardTracker extends StoredObject {
|
||||
return this.colorDependentSidebar;
|
||||
}
|
||||
|
||||
private static class ScoreTeam {
|
||||
private final String prefix;
|
||||
private final String suffix;
|
||||
private final String name;
|
||||
|
||||
public ScoreTeam(String name, String prefix, String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.name = name;
|
||||
}
|
||||
private record ScoreTeam(String name, String prefix, String suffix) {
|
||||
}
|
||||
}
|
||||
+17
-29
@@ -19,63 +19,54 @@ package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
|
||||
public final class WorldBorderEmulator extends StoredObject {
|
||||
|
||||
public class WorldBorderEmulator extends StoredObject {
|
||||
private double x, z;
|
||||
private double oldDiameter, newDiameter;
|
||||
|
||||
private long lerpTime;
|
||||
private long lerpStartTime;
|
||||
private long deltaTime;
|
||||
private long deltaStartTime;
|
||||
|
||||
private boolean init = false;
|
||||
|
||||
public WorldBorderEmulator(UserConnection user) {
|
||||
public WorldBorderEmulator(UserConnection user, final double x, final double z, final double oldDiameter, final double newDiameter, final long deltaTime) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void init(double x, double z, double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
|
||||
this.lerpTime = lerpTime;
|
||||
|
||||
init = true;
|
||||
this.deltaTime = deltaTime;
|
||||
}
|
||||
|
||||
public void setCenter(double x, double z) {
|
||||
public void setCenter(final double x, final double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void lerpSize(double oldDiameter, double newDiameter, long lerpTime) {
|
||||
public void updateDeltaTime(final double oldDiameter, final double newDiameter, final long deltaTime) {
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
this.lerpTime = lerpTime;
|
||||
this.lerpStartTime = System.currentTimeMillis();
|
||||
this.deltaTime = deltaTime;
|
||||
this.deltaStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public double getSize() {
|
||||
if (lerpTime == 0) {
|
||||
if (deltaTime == 0) {
|
||||
return newDiameter;
|
||||
}
|
||||
|
||||
double percent = ((double) (System.currentTimeMillis() - lerpStartTime) / (double) (lerpTime));
|
||||
|
||||
// Clamp value
|
||||
if (percent > 1.0D) percent = 1.0d;
|
||||
else if (percent < 0.0D) percent = 0.0d;
|
||||
|
||||
return oldDiameter + (newDiameter - oldDiameter) * percent;
|
||||
final double percent = ((double) (System.currentTimeMillis() - deltaStartTime) / (double) (deltaTime));
|
||||
return oldDiameter + (newDiameter - oldDiameter) * MathUtil.clamp(percent, 0D, 1D);
|
||||
}
|
||||
|
||||
public void setSize(double size) {
|
||||
public void setSize(final double size) {
|
||||
this.oldDiameter = size;
|
||||
this.newDiameter = size;
|
||||
|
||||
this.lerpTime = 0;
|
||||
this.deltaTime = 0;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
@@ -86,10 +77,6 @@ public class WorldBorderEmulator extends StoredObject {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public enum Side {
|
||||
NORTH(0, -1),
|
||||
EAST(1, 0),
|
||||
@@ -105,3 +92,4 @@ public class WorldBorderEmulator extends StoredObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user