Skip to content

Commit

Permalink
Deleted unused type instances and cleaned up some protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 20, 2023
1 parent d73c128 commit 47980bf
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ItemArrayType;

public class Typesb1_8_0_1 {

public static final Type<Item> CREATIVE_ITEM = new NbtLessItemType();
public static final Type<Item[]> CREATIVE_ITEM_ARRAY = new ItemArrayType<>(CREATIVE_ITEM);

}
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public void register() {

if (!load) {
final Chunk chunk = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>());
wrapper.write(ChunkType1_7_6.forEnvironment(wrapper.user().get(ClientWorld.class).getEnvironment()), chunk);
wrapper.write(Types1_7_6.getChunk(wrapper.user().get(ClientWorld.class).getEnvironment()), chunk);
} else {
wrapper.cancel();
}
Expand Down Expand Up @@ -496,7 +496,7 @@ public void register() {
}
}
}
wrapper.write(ChunkType1_7_6.forEnvironment(environment), chunk);
wrapper.write(Types1_7_6.getChunk(environment), chunk);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

public class ItemType extends Type<Item> {

private final boolean compressed;

public ItemType(boolean compressed) {
public ItemType() {
super(Item.class);
this.compressed = compressed;
}

public Item read(ByteBuf buffer) throws Exception {
Expand All @@ -43,7 +40,7 @@ public Item read(ByteBuf buffer) throws Exception {
item.setAmount(buffer.readByte());
item.setData(buffer.readShort());
if (NbtItemList.hasNbt(id)) {
item.setTag((this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).read(buffer));
item.setTag(Types1_7_6.COMPRESSED_NBT.read(buffer));
}
return item;
}
Expand All @@ -57,7 +54,7 @@ public void write(ByteBuf buffer, Item item) throws Exception {
buffer.writeByte(item.amount());
buffer.writeShort(item.data());
if (NbtItemList.hasNbt(item.identifier())) {
(this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).write(buffer, item.tag());
Types1_7_6.COMPRESSED_NBT.write(buffer, item.tag());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

public class Types1_2_4 {

public static final Type<Item> ITEM = new ItemType(false);
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType(true);

public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType<>(ITEM);
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_NBT_ITEM);

public static final Type<Chunk> CHUNK = new ChunkType1_2_4();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
public class Types1_3_1 {

public static final Type<Item> NBTLESS_ITEM = new NbtLessItemType();
public static final Type<Item[]> NBTLESS_ITEM_ARRAY = new ItemArrayType<>(NBTLESS_ITEM);

public static final Type<Metadata> METADATA = new MetadataType();
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
public class Types1_4_4 {

public static final BulkChunkType1_4_4 CHUNK_BULK = new BulkChunkType1_4_4();

}
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void register() {
@Override
public void register() {
handler(wrapper -> {
final Chunk chunk = wrapper.passthrough(ChunkType1_7_6.forEnvironment(wrapper.user().get(ClientWorld.class).getEnvironment()));
final Chunk chunk = wrapper.passthrough(Types1_7_6.getChunk(wrapper.user().get(ClientWorld.class).getEnvironment()));
wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk);
});
}
Expand Down Expand Up @@ -486,7 +486,7 @@ public void register() {
@Override
public void register() {
handler(wrapper -> {
final Chunk[] chunks = wrapper.passthrough(BulkChunkType1_7_6.TYPE);
final Chunk[] chunks = wrapper.passthrough(Types1_7_6.CHUNK_BULK);
for (Chunk chunk : chunks) {
wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@

public class ItemType extends Type<Item> {

private final boolean compressed;

public ItemType(boolean compressed) {
public ItemType() {
super(Item.class);
this.compressed = compressed;
}

@Override
Expand All @@ -42,7 +39,7 @@ public Item read(ByteBuf buffer) throws Exception {
item.setIdentifier(id);
item.setAmount(buffer.readByte());
item.setData(buffer.readShort());
item.setTag((this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).read(buffer));
item.setTag(Types1_7_6.COMPRESSED_NBT.read(buffer));
return item;
}

Expand All @@ -54,7 +51,7 @@ public void write(ByteBuf buffer, Item item) throws Exception {
buffer.writeShort(item.identifier());
buffer.writeByte(item.amount());
buffer.writeShort(item.data());
(this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).write(buffer, item.tag());
Types1_7_6.COMPRESSED_NBT.write(buffer, item.tag());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public class Types1_7_6 {
public static final Type<CompoundTag> NBT = new NBTType(false);
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType(true);

public static final Type<Item> ITEM = new ItemType(false);
public static final Type<Item> COMPRESSED_ITEM = new ItemType(true);

public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType<>(ITEM);
public static final Type<Item> COMPRESSED_ITEM = new ItemType();
public static final Type<Item[]> COMPRESSED_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_ITEM);

public static final Type<Metadata> METADATA = new MetadataType();
Expand All @@ -51,12 +48,13 @@ public class Types1_7_6 {
public static final Type<Position> POSITION_SHORT = new PositionVarYType<>(Type.SHORT, i -> (short) i);
public static final Type<Position> POSITION_INT = new PositionVarYType<>(Type.INT, i -> i);

public static final BulkChunkType1_7_6 CHUNK_BULK = new BulkChunkType1_7_6();

private static final ChunkType1_7_6 CHUNK_WITH_SKYLIGHT = new ChunkType1_7_6(true);
private static final ChunkType1_7_6 CHUNK_WITHOUT_SKYLIGHT = new ChunkType1_7_6(false);

public static final BulkChunkType1_7_6 CHUNK_BULK = new BulkChunkType1_7_6();

public static ChunkType1_7_6 getChunk(Environment environment) {
return environment == Environment.NORMAL ? CHUNK_WITH_SKYLIGHT : CHUNK_WITHOUT_SKYLIGHT;
}

}

0 comments on commit 47980bf

Please sign in to comment.