Skip to content

Commit

Permalink
Port to upstream changes (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed May 14, 2024
1 parent 0cb70b0 commit 6728a8a
Show file tree
Hide file tree
Showing 76 changed files with 3,004 additions and 3,037 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Building
After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out
of the `universal/build/libs` directory.

You need JDK 17 or newer to build ViaRewind.

License
-
This project is licensed under the [GNU General Public License Version 3](LICENSE).
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ base {
description = "ViaBackwards addon to allow 1.8.x and 1.7.x clients on newer server versions."
}

java.sourceCompatibility = JavaVersion.VERSION_1_8
java.sourceCompatibility = JavaVersion.VERSION_17

tasks {
// Variable replacements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public class ViaRewindConfig extends Config implements com.viaversion.viarewind.api.ViaRewindConfig {

Expand All @@ -39,8 +40,8 @@ public class ViaRewindConfig extends Config implements com.viaversion.viarewind.
private boolean enableOffhand;
private String offhandCommand;

public ViaRewindConfig(File configFile) {
super(configFile);
public ViaRewindConfig(File configFile, Logger logger) {
super(configFile, logger);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface ViaRewindPlatform {
* Initialize ViaRewind
*/
default void init(final File configFile) {
ViaRewindConfig config = new ViaRewindConfig(configFile);
ViaRewindConfig config = new ViaRewindConfig(configFile, getLogger());
config.reload();
Via.getManager().getConfigurationProvider().register(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
package com.viaversion.viarewind.api.data;

import com.viaversion.viabackwards.api.data.BackwardsMappings;
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viarewind.ViaRewind;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.nbt.tag.CompoundTag;

import java.util.logging.Logger;

public class RewindMappings extends BackwardsMappings {
public class RewindMappingData extends BackwardsMappingData {

public RewindMappings(String unmappedVersion, String mappedVersion) {
public RewindMappingData(String unmappedVersion, String mappedVersion) {
super(unmappedVersion, mappedVersion);
}

Expand All @@ -36,6 +36,6 @@ protected Logger getLogger() {

@Override
protected CompoundTag readMappingsFile(String name) {
return VRMappingDataLoader.INSTANCE.loadNBTFromDir(name);
return RewindMappingDataLoader.INSTANCE.loadNBTFromDir(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.io.File;
import java.util.logging.Logger;

public class VRMappingDataLoader extends BackwardsMappingDataLoader {
public class RewindMappingDataLoader extends BackwardsMappingDataLoader {

public static final VRMappingDataLoader INSTANCE = new VRMappingDataLoader();
public static final RewindMappingDataLoader INSTANCE = new RewindMappingDataLoader();

public VRMappingDataLoader() {
super(VRMappingDataLoader.class, "assets/viarewind/data/");
public RewindMappingDataLoader() {
super(RewindMappingDataLoader.class, "assets/viarewind/data/");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils;
package com.viaversion.viarewind.api.minecraft;

import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@
* 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.type.metadata;
package com.viaversion.viarewind.api.minecraft.entitydata;

import com.viaversion.viarewind.api.type.Types1_7_6_10;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viarewind.api.type.RewindTypes;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;

public enum MetaType1_7_6_10 implements MetaType {
Byte(0, Type.BYTE),
Short(1, Type.SHORT),
Int(2, Type.INT),
Float(3, Type.FLOAT),
String(4, Type.STRING),
Slot(5, Types1_7_6_10.COMPRESSED_NBT_ITEM),
Position(6, Type.VECTOR);
public enum EntityDataTypes1_7_6_10 implements EntityDataType {
BYTE(0, Types.BYTE),
SHORT(1, Types.SHORT),
INT(2, Types.INT),
FLOAT(3, Types.FLOAT),
STRING(4, Types.STRING),
ITEM(5, RewindTypes.COMPRESSED_NBT_ITEM),
POSITION(6, Types.VECTOR);

private final int typeID;
private final Type<?> type;

MetaType1_7_6_10(int typeID, Type<?> type) {
EntityDataTypes1_7_6_10(int typeID, Type<?> type) {
this.typeID = typeID;
this.type = type;
}

public static MetaType1_7_6_10 byId(int id) {
public static EntityDataTypes1_7_6_10 byId(int id) {
return values()[id];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils.math;
package com.viaversion.viarewind.api.minecraft.math;

public class AABB {
Vector3d min;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils.math;
package com.viaversion.viarewind.api.minecraft.math;

public class Ray3d {
Vector3d start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils.math;
package com.viaversion.viarewind.api.minecraft.math;

public class RayTracing {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils.math;
package com.viaversion.viarewind.api.minecraft.math;

import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.EntityTracker1_9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.utils.math;
package com.viaversion.viarewind.api.minecraft.math;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.netty;
package com.viaversion.viarewind.api.minecraft.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.netty;
package com.viaversion.viarewind.api.minecraft.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viarewind.api.data.VRMappingDataLoader;
import com.viaversion.viarewind.api.data.RewindMappingDataLoader;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.libs.gson.JsonObject;
Expand All @@ -32,7 +32,7 @@ protected VRBlockItemRewriter(T protocol, String name) {

@Override
protected JsonObject readMappingsFile(String name) {
return VRMappingDataLoader.INSTANCE.loadFromDataDir(name);
return RewindMappingDataLoader.INSTANCE.loadFromDataDir(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@
import com.viaversion.viarewind.ViaRewind;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;

public abstract class VREntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends LegacyEntityRewriter<C, T> {

public VREntityRewriter(T protocol) {
super(protocol, MetaType1_8.String, MetaType1_8.Byte);
super(protocol, EntityDataTypes1_8.STRING, EntityDataTypes1_8.BYTE);
}

public VREntityRewriter(T protocol, MetaType displayType, MetaType displayVisibilityType) {
public VREntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
super(protocol, displayType, displayVisibilityType);
}

protected void registerJoinGame1_8(final C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
protected void register() {
map(Type.INT); // Entity id
map(Type.UNSIGNED_BYTE); // Game mode
map(Type.BYTE); // Dimension
map(Types.INT); // Entity id
map(Types.UNSIGNED_BYTE); // Game mode
map(Types.BYTE); // Dimension
handler(playerTrackerHandler());
handler(wrapper -> wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.BYTE, 0)));
handler(wrapper -> wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Types.BYTE, 0)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* 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.type.primitive;
package com.viaversion.viarewind.api.type;

import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;

public class ByteIntArrayType extends Type<int[]> {
public class IntArrayType extends Type<int[]> {

public ByteIntArrayType() {
public IntArrayType() {
super(int[].class);
}

@Override
public int[] read(ByteBuf byteBuf) throws Exception {
public int[] read(ByteBuf byteBuf) {
byte size = byteBuf.readByte();
int[] array = new int[size];
for (byte i = 0; i < size; i++) {
Expand All @@ -37,7 +37,7 @@ public int[] read(ByteBuf byteBuf) throws Exception {
}

@Override
public void write(ByteBuf byteBuf, int[] array) throws Exception {
public void write(ByteBuf byteBuf, int[] array) {
byteBuf.writeByte(array.length);
for (int i : array) byteBuf.writeInt(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
* 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.type.primitive;
package com.viaversion.viarewind.api.type;

import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;

import java.util.function.IntFunction;

public class PositionUYType<T extends Number> extends Type<Position> {
public class PositionVarYType<T extends Number> extends Type<Position> {

private final Type<T> yType;
private final IntFunction<T> toY;

public PositionUYType(final Type<T> yType, final IntFunction<T> toY) {
public PositionVarYType(final Type<T> yType, final IntFunction<T> toY) {
super(Position.class);

this.yType = yType;
this.toY = toY;
}

@Override
public Position read(ByteBuf buffer) throws Exception {
public Position read(ByteBuf buffer) {
final int x = buffer.readInt();
final int y = yType.read(buffer).intValue();
final int z = buffer.readInt();
Expand All @@ -45,7 +45,7 @@ public Position read(ByteBuf buffer) throws Exception {
}

@Override
public void write(ByteBuf buffer, Position value) throws Exception {
public void write(ByteBuf buffer, Position value) {
buffer.writeInt(value.x());
yType.write(buffer, this.toY.apply(value.y()));
buffer.writeInt(value.z());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,28 @@
import com.viaversion.viarewind.api.type.item.NBTType;
import com.viaversion.viarewind.api.type.item.ItemArrayType;
import com.viaversion.viarewind.api.type.item.ItemType;
import com.viaversion.viarewind.api.type.metadata.MetadataListType;
import com.viaversion.viarewind.api.type.metadata.MetadataType;
import com.viaversion.viarewind.api.type.primitive.ByteIntArrayType;
import com.viaversion.viarewind.api.type.primitive.PositionUYType;
import com.viaversion.viarewind.api.type.entitydata.EntityDataListType;
import com.viaversion.viarewind.api.type.entitydata.EntityDataType;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.nbt.tag.CompoundTag;

import java.util.List;

public class Types1_7_6_10 {
public class RewindTypes {

// Primitives
public static final Type<int[]> BYTE_INT_ARRAY = new ByteIntArrayType(); // Integer array with byte as length indicator
public static final Type<int[]> INT_ARRAY = new IntArrayType(); // Integer array with byte as length indicator

// Positions /shrug
public static final Type<Position> SHORT_POSITION = new PositionUYType<>(Type.SHORT, value -> (short) value);
public static final Type<Position> INT_POSITION = new PositionUYType<>(Type.INT, value -> value);
public static final Type<Position> BYTE_POSITION = new PositionUYType<>(Type.BYTE, value -> (byte) value);
public static final Type<Position> U_BYTE_POSITION = new PositionUYType<>(Type.UNSIGNED_BYTE, value -> (short) value);
public static final Type<Position> SHORT_POSITION = new PositionVarYType<>(Types.SHORT, value -> (short) value);
public static final Type<Position> INT_POSITION = new PositionVarYType<>(Types.INT, value -> value);
public static final Type<Position> BYTE_POSITION = new PositionVarYType<>(Types.BYTE, value -> (byte) value);
public static final Type<Position> U_BYTE_POSITION = new PositionVarYType<>(Types.UNSIGNED_BYTE, value -> (short) value);

// Items
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType();
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType();

// Metadata
public static final Type<Metadata> METADATA = new MetadataType();
public static final Type<List<Metadata>> METADATA_LIST = new MetadataListType();

}
Loading

0 comments on commit 6728a8a

Please sign in to comment.