3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Reuse old chunk type instances, more type cleanup

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-10-20 12:30:03 +10:00
Ursprung 50e55529d9
Commit 8ebc8c34f3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
34 geänderte Dateien mit 116 neuen und 188 gelöschten Zeilen

Datei anzeigen

@ -22,25 +22,32 @@
*/
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Stored up until 1.14 to be used in chunk sending.
*/
public class ClientWorld extends StoredObject {
public class ClientWorld implements StorableObject {
private Environment environment;
@Deprecated/*(forRemoval = true)*/
public ClientWorld(final UserConnection connection) {
super(connection);
}
public ClientWorld() {
}
public ClientWorld(final Environment environment) {
this.environment = environment;
}
public @Nullable Environment getEnvironment() {
return environment;
}
public void setEnvironment(int environmentId) {
public void setEnvironment(final int environmentId) {
this.environment = Environment.getEnvironmentById(environmentId);
}
}

Datei anzeigen

@ -24,29 +24,23 @@ package com.viaversion.viaversion.api.type.types.chunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import io.netty.buffer.ByteBuf;
public class BulkChunkType1_8 extends PartialType<Chunk[], ClientWorld> {
public class BulkChunkType1_8 extends Type<Chunk[]> {
public static final Type<Chunk[]> TYPE = new BulkChunkType1_8();
private static final int BLOCKS_PER_SECTION = 16 * 16 * 16;
private static final int BLOCKS_BYTES = BLOCKS_PER_SECTION * 2;
private static final int LIGHT_BYTES = BLOCKS_PER_SECTION / 2;
private static final int BIOME_BYTES = 16 * 16;
public BulkChunkType1_8(final ClientWorld clientWorld) {
super(clientWorld, Chunk[].class);
public BulkChunkType1_8() {
super(Chunk[].class);
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkBulkType.class;
}
@Override
public Chunk[] read(ByteBuf input, ClientWorld world) throws Exception {
public Chunk[] read(ByteBuf input) throws Exception {
final boolean skyLight = input.readBoolean();
final int count = Type.VAR_INT.readPrimitive(input);
final Chunk[] chunks = new Chunk[count];
@ -67,11 +61,11 @@ public class BulkChunkType1_8 extends PartialType<Chunk[], ClientWorld> {
}
@Override
public void write(ByteBuf output, ClientWorld world, Chunk[] chunks) throws Exception {
public void write(ByteBuf output, Chunk[] chunks) throws Exception {
boolean skyLight = false;
loop1:
for (Chunk c : chunks) {
for (ChunkSection section : c.getSections()) {
for (Chunk chunk : chunks) {
for (ChunkSection section : chunk.getSections()) {
if (section != null && section.getLight().hasSkyLight()) {
skyLight = true;
break loop1;
@ -82,14 +76,14 @@ public class BulkChunkType1_8 extends PartialType<Chunk[], ClientWorld> {
Type.VAR_INT.writePrimitive(output, chunks.length);
// Write metadata
for (Chunk c : chunks) {
output.writeInt(c.getX());
output.writeInt(c.getZ());
output.writeShort(c.getBitmask());
for (Chunk chunk : chunks) {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeShort(chunk.getBitmask());
}
// Write data
for (Chunk c : chunks) {
output.writeBytes(ChunkType1_8.serialize(c));
for (Chunk chunk : chunks) {
output.writeBytes(ChunkType1_8.serialize(chunk));
}
}

Datei anzeigen

@ -24,15 +24,14 @@ package com.viaversion.viaversion.api.type.types.chunk;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.Arrays;
@ -41,8 +40,15 @@ import java.util.logging.Level;
public class ChunkType1_13 extends PartialType<Chunk, ClientWorld> {
public ChunkType1_13(ClientWorld param) {
super(param, Chunk.class);
private static final ChunkType1_13 WITH_SKYLIGHT = new ChunkType1_13(new ClientWorld(Environment.NORMAL));
private static final ChunkType1_13 WITHOUT_SKYLIGHT = new ChunkType1_13(new ClientWorld(Environment.NETHER));
public ChunkType1_13(ClientWorld clientWorld) {
super(clientWorld, Chunk.class);
}
public static ChunkType1_13 forEnvironment(Environment environment) {
return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT;
}
@Override

Datei anzeigen

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@ -37,6 +36,8 @@ import java.util.List;
public class ChunkType1_14 extends Type<Chunk> {
public static final Type<Chunk> TYPE = new ChunkType1_14();
public ChunkType1_14() {
super(Chunk.class);
}
@ -118,9 +119,4 @@ public class ChunkType1_14 extends Type<Chunk> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@ -119,9 +118,4 @@ public class ChunkType1_15 extends Type<Chunk> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@ -121,9 +120,4 @@ public class ChunkType1_16 extends Type<Chunk> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@ -115,9 +114,4 @@ public class ChunkType1_16_2 extends Type<Chunk> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@ -113,9 +112,4 @@ public final class ChunkType1_17 extends Type<Chunk> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -97,9 +97,4 @@ public final class ChunkType1_18 extends Type<Chunk> {
Type.BLOCK_ENTITY1_18.write(buffer, blockEntity);
}
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -29,8 +29,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.chunk.ChunkSectionType1_18;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
@ -96,9 +94,4 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
Type.BLOCK_ENTITY1_20_2.write(buffer, blockEntity);
}
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -22,28 +22,29 @@
*/
package com.viaversion.viaversion.api.type.types.chunk;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
public class ChunkType1_8 extends PartialType<Chunk, ClientWorld> {
public ChunkType1_8(ClientWorld param) {
super(param, Chunk.class);
private static final ChunkType1_8 WITH_SKYLIGHT = new ChunkType1_8(new ClientWorld(Environment.NORMAL));
private static final ChunkType1_8 WITHOUT_SKYLIGHT = new ChunkType1_8(new ClientWorld(Environment.NETHER));
public ChunkType1_8(ClientWorld clientWorld) {
super(clientWorld, Chunk.class);
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
public static ChunkType1_8 forEnvironment(Environment environment) {
return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT;
}
@Override

Datei anzeigen

@ -22,25 +22,31 @@
*/
package com.viaversion.viaversion.api.type.types.chunk;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.BitSet;
public class ChunkType1_9_1 extends PartialType<Chunk, ClientWorld> {
private static final ChunkType1_9_1 WITH_SKYLIGHT = new ChunkType1_9_1(new ClientWorld(Environment.NORMAL));
private static final ChunkType1_9_1 WITHOUT_SKYLIGHT = new ChunkType1_9_1(new ClientWorld(Environment.NETHER));
public ChunkType1_9_1(ClientWorld clientWorld) {
super(clientWorld, Chunk.class);
}
public static ChunkType1_9_1 forEnvironment(Environment environment) {
return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT;
}
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
int chunkX = input.readInt();
@ -115,9 +121,4 @@ public class ChunkType1_9_1 extends PartialType<Chunk, ClientWorld> {
}
}
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -24,15 +24,14 @@ package com.viaversion.viaversion.api.type.types.chunk;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.Arrays;
@ -40,8 +39,15 @@ import java.util.List;
public class ChunkType1_9_3 extends PartialType<Chunk, ClientWorld> {
public ChunkType1_9_3(ClientWorld param) {
super(param, Chunk.class);
private static final ChunkType1_9_3 WITH_SKYLIGHT = new ChunkType1_9_3(new ClientWorld(Environment.NORMAL));
private static final ChunkType1_9_3 WITHOUT_SKYLIGHT = new ChunkType1_9_3(new ClientWorld(Environment.NETHER));
public ChunkType1_9_3(ClientWorld clientWorld) {
super(clientWorld, Chunk.class);
}
public static ChunkType1_9_3 forEnvironment(Environment environment) {
return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT;
}
@Override
@ -122,9 +128,4 @@ public class ChunkType1_9_3 extends PartialType<Chunk, ClientWorld> {
// Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseChunkType.class;
}
}

Datei anzeigen

@ -1,42 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2023 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
abstract class BaseItemType extends Type<Item> {
protected BaseItemType() {
super(Item.class);
}
protected BaseItemType(String typeName) {
super(typeName, Item.class);
}
@Override
public Class<? extends Type> getBaseClass() {
return BaseItemType.class;
}
}

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_13_2 extends BaseItemArrayType {
@ -33,19 +34,19 @@ public class ItemShortArrayType1_13_2 extends BaseItemArrayType {
@Override
public Item[] read(ByteBuf buffer) throws Exception {
int amount = SHORT.readPrimitive(buffer);
int amount = Type.SHORT.readPrimitive(buffer);
Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) {
array[i] = ITEM1_13_2.read(buffer);
array[i] = Type.ITEM1_13_2.read(buffer);
}
return array;
}
@Override
public void write(ByteBuf buffer, Item[] object) throws Exception {
SHORT.writePrimitive(buffer, (short) object.length);
Type.SHORT.writePrimitive(buffer, (short) object.length);
for (Item o : object) {
ITEM1_13_2.write(buffer, o);
Type.ITEM1_13_2.write(buffer, o);
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_8 extends BaseItemArrayType {
@ -33,19 +34,19 @@ public class ItemShortArrayType1_8 extends BaseItemArrayType {
@Override
public Item[] read(ByteBuf buffer) throws Exception {
int amount = SHORT.readPrimitive(buffer);
int amount = Type.SHORT.readPrimitive(buffer);
Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) {
array[i] = ITEM1_8.read(buffer);
array[i] = Type.ITEM1_8.read(buffer);
}
return array;
}
@Override
public void write(ByteBuf buffer, Item[] object) throws Exception {
SHORT.writePrimitive(buffer, (short) object.length);
Type.SHORT.writePrimitive(buffer, (short) object.length);
for (Item o : object) {
ITEM1_8.write(buffer, o);
Type.ITEM1_8.write(buffer, o);
}
}
}

Datei anzeigen

@ -28,9 +28,9 @@ import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_13 extends BaseItemType {
public class ItemType1_13 extends Type<Item> {
public ItemType1_13() {
super("FlatItem");
super("FlatItem", Item.class);
}
@Override

Datei anzeigen

@ -24,12 +24,13 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_13_2 extends BaseItemType {
public class ItemType1_13_2 extends Type<Item> {
public ItemType1_13_2() {
super("FlatVarIntItem");
super("FlatVarIntItem", Item.class);
}
@Override
@ -39,9 +40,9 @@ public class ItemType1_13_2 extends BaseItemType {
return null;
} else {
Item item = new DataItem();
item.setIdentifier(VAR_INT.readPrimitive(buffer));
item.setIdentifier(Type.VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte());
item.setTag(NAMED_COMPOUND_TAG.read(buffer));
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer));
return item;
}
}
@ -52,9 +53,9 @@ public class ItemType1_13_2 extends BaseItemType {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
VAR_INT.writePrimitive(buffer, object.identifier());
Type.VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount());
NAMED_COMPOUND_TAG.write(buffer, object.tag());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag());
}
}
}

Datei anzeigen

@ -24,13 +24,14 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_20_2 extends BaseItemType {
public class ItemType1_20_2 extends Type<Item> {
public ItemType1_20_2() {
super("ItemType1_20_2");
super("ItemType1_20_2", Item.class);
}
@Override
@ -40,9 +41,9 @@ public class ItemType1_20_2 extends BaseItemType {
}
final Item item = new DataItem();
item.setIdentifier(VAR_INT.readPrimitive(buffer));
item.setIdentifier(Type.VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte());
item.setTag(COMPOUND_TAG.read(buffer));
item.setTag(Type.COMPOUND_TAG.read(buffer));
return item;
}
@ -52,9 +53,9 @@ public class ItemType1_20_2 extends BaseItemType {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
VAR_INT.writePrimitive(buffer, object.identifier());
Type.VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount());
COMPOUND_TAG.write(buffer, object.tag());
Type.COMPOUND_TAG.write(buffer, object.tag());
}
}
}

Datei anzeigen

@ -24,13 +24,14 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_8 extends BaseItemType {
public class ItemType1_8 extends Type<Item> {
public ItemType1_8() {
super("Item");
super("Item", Item.class);
}
@Override
@ -43,7 +44,7 @@ public class ItemType1_8 extends BaseItemType {
item.setIdentifier(id);
item.setAmount(buffer.readByte());
item.setData(buffer.readShort());
item.setTag(NAMED_COMPOUND_TAG.read(buffer));
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer));
return item;
}
}
@ -56,7 +57,7 @@ public class ItemType1_8 extends BaseItemType {
buffer.writeShort(object.identifier());
buffer.writeByte(object.amount());
buffer.writeShort(object.data());
NAMED_COMPOUND_TAG.write(buffer, object.tag());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag());
}
}
}

Datei anzeigen

@ -50,11 +50,6 @@ public class PositionType1_14 extends Type<Position> {
| ((((long) object.z()) & 0x3ffffff) << 12));
}
@Override
public Class<? extends Type> getBaseClass() {
return PositionType1_8.class;
}
public static final class OptionalPosition1_14Type extends OptionalType<Position> {
public OptionalPosition1_14Type() {

Datei anzeigen

@ -179,7 +179,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
// Chunk Data
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new ChunkType1_9_3(clientWorld));
Chunk chunk = wrapper.passthrough(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()));
if (Via.getConfig().isReplacePistons()) {
int replacementId = Via.getConfig().getPistonReplacementId();
@ -237,7 +237,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
userConnection.put(new ResourcePackTracker());
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
}

Datei anzeigen

@ -208,7 +208,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new ChunkType1_9_3(clientWorld));
Chunk chunk = wrapper.passthrough(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()));
if (chunk.getBlockEntities() == null) return;
for (CompoundTag tag : chunk.getBlockEntities()) {
@ -346,7 +346,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
userConnection.addEntityTracker(this.getClass(), new EntityTracker1_11(userConnection));
if (!userConnection.has(ClientWorld.class))
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
@Override

Datei anzeigen

@ -110,7 +110,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.passthrough(type);
for (int s = 0; s < chunk.getSections().length; s++) {
@ -245,7 +245,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
public void init(UserConnection userConnection) {
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, EntityTypes1_12.EntityType.PLAYER));
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
}

Datei anzeigen

@ -137,7 +137,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
public void init(UserConnection userConnection) {
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, EntityTypes1_13.EntityType.PLAYER));
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
}

Datei anzeigen

@ -36,7 +36,7 @@ public class WorldPackets {
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new ChunkType1_13(clientWorld));
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
for (ChunkSection section : chunk.getSections()) {
if (section == null) {

Datei anzeigen

@ -865,7 +865,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, EntityTypes1_13.EntityType.PLAYER));
userConnection.put(new TabCompleteTracker());
if (!userConnection.has(ClientWorld.class))
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
userConnection.put(new BlockStorage());
if (Via.getConfig().isServersideBlockConnections()) {
if (Via.getManager().getProviders().get(BlockConnectionProvider.class) instanceof PacketBlockConnectionProvider) {

Datei anzeigen

@ -331,8 +331,8 @@ public class WorldPackets {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
BlockStorage storage = wrapper.user().get(BlockStorage.class);
ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld);
ChunkType1_13 type1_13 = new ChunkType1_13(clientWorld);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
ChunkType1_13 type1_13 = ChunkType1_13.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.read(type);
wrapper.write(type1_13, chunk);

Datei anzeigen

@ -161,7 +161,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
public void init(UserConnection userConnection) {
userConnection.addEntityTracker(this.getClass(), new EntityTracker1_14(userConnection));
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
}

Datei anzeigen

@ -126,8 +126,8 @@ public class WorldPackets {
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.read(new ChunkType1_13(clientWorld));
wrapper.write(new ChunkType1_14(), chunk);
Chunk chunk = wrapper.read(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
wrapper.write(ChunkType1_14.TYPE, chunk);
int[] motionBlocking = new int[16 * 16];
int[] worldSurface = new int[16 * 16];

Datei anzeigen

@ -40,7 +40,7 @@ public final class WorldPackets {
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_14_4.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerClientbound(ClientboundPackets1_14_4.CHUNK_DATA, wrapper -> {
Chunk chunk = wrapper.read(new ChunkType1_14());
Chunk chunk = wrapper.read(ChunkType1_14.TYPE);
wrapper.write(new ChunkType1_15(), chunk);
if (chunk.isFullChunk()) {

Datei anzeigen

@ -87,8 +87,8 @@ public class Protocol1_9_3To1_9_1_2 extends AbstractProtocol<ClientboundPackets1
registerClientbound(ClientboundPackets1_9.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.read(new ChunkType1_9_1(clientWorld));
wrapper.write(new ChunkType1_9_3(clientWorld), chunk);
Chunk chunk = wrapper.read(ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()));
wrapper.write(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()), chunk);
List<CompoundTag> tags = chunk.getBlockEntities();
for (int s = 0; s < chunk.getSections().length; s++) {

Datei anzeigen

@ -148,7 +148,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
userConnection.put(new CommandBlockStorage());
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
userConnection.put(new ClientWorld());
}
}

Datei anzeigen

@ -122,7 +122,7 @@ public class WorldPackets {
protocol.registerClientbound(ClientboundPackets1_8.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk chunk = wrapper.read(new ChunkType1_8(clientWorld));
Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(clientWorld.getEnvironment()));
long chunkHash = ClientChunks.toLong(chunk.getX(), chunk.getZ());
@ -152,7 +152,7 @@ public class WorldPackets {
}
}
} else {
Type<Chunk> chunkType = new ChunkType1_9_1(clientWorld);
Type<Chunk> chunkType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment());
wrapper.write(chunkType, chunk);
clientChunks.getLoadedChunks().add(chunkHash);
@ -177,9 +177,9 @@ public class WorldPackets {
wrapper.cancel(); // Cancel the packet from being sent
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk[] chunks = wrapper.read(new BulkChunkType1_8(clientWorld));
Chunk[] chunks = wrapper.read(BulkChunkType1_8.TYPE);
Type<Chunk> chunkType = new ChunkType1_9_1(clientWorld);
Type<Chunk> chunkType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment());
// Split into multiple chunk packets
for (Chunk chunk : chunks) {
PacketWrapper chunkData = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);