Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.5 & Velocity b379+ support #149

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/[email protected]
with:
distribution: adopt
java-version: 17
java-version: 21
- name: Build LimboAPI
run: ./gradlew build
- name: Upload LimboAPI
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/net/elytrium/limboapi/api/LimboFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.elytrium.limboapi.api.material.Item;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.protocol.PreparedPacket;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.elytrium.limboapi.api.protocol.packets.PacketFactory;
import net.kyori.adventure.nbt.CompoundBinaryTag;

Expand Down Expand Up @@ -237,6 +238,13 @@ public interface LimboFactory {
*/
VirtualItem getLegacyItem(int itemLegacyID);

/**
* Creates new item component map.
*
* @return new item component map
*/
ItemComponentMap createItemComponentMap();

VirtualBlockEntity getBlockEntity(String entityID);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum WorldVersion {
MINECRAFT_1_19_3(ProtocolVersion.MINECRAFT_1_19_3),
MINECRAFT_1_19_4(EnumSet.range(ProtocolVersion.MINECRAFT_1_19_4, ProtocolVersion.MINECRAFT_1_20)),
MINECRAFT_1_20(EnumSet.range(ProtocolVersion.MINECRAFT_1_20, ProtocolVersion.MINECRAFT_1_20_2)),
MINECRAFT_1_20_3(EnumSet.range(ProtocolVersion.MINECRAFT_1_20_3, ProtocolVersion.MAXIMUM_VERSION));
MINECRAFT_1_20_3(ProtocolVersion.MINECRAFT_1_20_3),
MINECRAFT_1_20_5(EnumSet.range(ProtocolVersion.MINECRAFT_1_20_5, ProtocolVersion.MAXIMUM_VERSION));

private static final EnumMap<ProtocolVersion, WorldVersion> MC_VERSION_TO_ITEM_VERSIONS = new EnumMap<>(ProtocolVersion.class);

Expand Down Expand Up @@ -70,6 +71,7 @@ public static WorldVersion parse(String from) {
case "1.19.4" -> MINECRAFT_1_19_4;
case "1.20" -> MINECRAFT_1_20;
case "1.20.3" -> MINECRAFT_1_20_3;
case "1.20.5" -> MINECRAFT_1_20_5;
default -> LEGACY;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.ScheduledExecutorService;
import net.elytrium.limboapi.api.Limbo;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.kyori.adventure.nbt.CompoundBinaryTag;

public interface LimboPlayer {
Expand Down Expand Up @@ -43,6 +44,8 @@ public interface LimboPlayer {

void setInventory(int slot, VirtualItem item, int count, int data, CompoundBinaryTag nbt);

void setInventory(int slot, VirtualItem item, int count, int data, ItemComponentMap map);

void setGameMode(GameMode gameMode);

void teleport(double posX, double posY, double posZ, float yaw, float pitch);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2021 - 2024 Elytrium
*
* The LimboAPI (excluding the LimboAPI plugin) is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/

package net.elytrium.limboapi.api.protocol.item;

public interface ItemComponent<T> {

String getName();

ItemComponent<T> setValue(T value);

T getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2021 - 2024 Elytrium
*
* The LimboAPI (excluding the LimboAPI plugin) is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/

package net.elytrium.limboapi.api.protocol.item;

import com.velocitypowered.api.network.ProtocolVersion;
import java.util.List;

public interface ItemComponentMap {

<T> ItemComponentMap add(ProtocolVersion version, String name, T value);

ItemComponentMap remove(ProtocolVersion version, String name);

List<ItemComponent> getAdded();

List<ItemComponent> getRemoved();

void read(ProtocolVersion version, Object buffer);

void write(ProtocolVersion version, Object buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.elytrium.limboapi.api.chunk.data.ChunkSnapshot;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.material.WorldVersion;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.elytrium.limboapi.api.protocol.packets.data.AbilityFlags;
import net.elytrium.limboapi.api.protocol.packets.data.MapData;
import net.kyori.adventure.nbt.CompoundBinaryTag;
Expand Down Expand Up @@ -48,6 +49,8 @@ Object createPositionRotationPacket(double posX, double posY, double posZ, float

Object createSetSlotPacket(int windowID, int slot, VirtualItem item, int count, int data, @Nullable CompoundBinaryTag nbt);

Object createSetSlotPacket(int windowID, int slot, VirtualItem item, int count, int data, @Nullable ItemComponentMap map);

Object createTimeUpdatePacket(long worldAge, long timeOfDay);

Object createUpdateViewPositionPacket(int posX, int posZ);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins() {
id("java")

id("checkstyle")
id("com.github.spotbugs").version("5.0.14").apply(false)
id("com.github.spotbugs").version("6.0.12").apply(false)
id("org.cadixdev.licenser").version("0.6.1").apply(false)
}

Expand Down
3 changes: 3 additions & 0 deletions config/spotbugs/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<Match>
<Bug pattern="THROWS_METHOD_THROWS_CLAUSE_THROWABLE"/>
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW"/>
</Match>
</FindBugsFilter>
22 changes: 18 additions & 4 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ enum MinecraftVersion {
MINECRAFT_1_19_4(762),
MINECRAFT_1_20(763),
MINECRAFT_1_20_2(764),
MINECRAFT_1_20_3(765)
MINECRAFT_1_20_3(765),
MINECRAFT_1_20_5(766)

public static final List<MinecraftVersion> WORLD_VERSIONS = List.of(
MINECRAFT_1_13,
Expand All @@ -140,7 +141,12 @@ enum MinecraftVersion {
MINECRAFT_1_19_3,
MINECRAFT_1_19_4,
MINECRAFT_1_20,
MINECRAFT_1_20_3
MINECRAFT_1_20_3,
MINECRAFT_1_20_5
)

public static final List<MinecraftVersion> COMPONENT_VERSIONS = List.of(
MINECRAFT_1_20_5
)

public static final MinecraftVersion MINIMUM_VERSION = MINECRAFT_1_7_2
Expand Down Expand Up @@ -213,7 +219,7 @@ File downloadVersionManifest(String version) {
this.println("> Downloading ${version} manifest...")

Object manifest = new JsonSlurper().parse(versionManifestFile)
def optional = manifest.versions.stream().filter({it.id == version}).findFirst()
def optional = manifest.versions.stream().filter({ it.id == version }).findFirst()
if (optional.empty()) {
throw new RuntimeException("Couldn't find version: ${version}")
}
Expand Down Expand Up @@ -529,7 +535,13 @@ void generateRegistryMapping(String target, File targetDir, Map<MinecraftVersion

Map<String, Map<String, String>> mapping = new JsonSlurper()
.parse(new File(this.getProjectDir(), "mapping/legacy_${target}s_mapping.json"))
.collectEntries({ key, value -> [modernIDs[key], value] })
.collectEntries({ key, value -> {
if (modernIDs[key] == null) {
throw new IllegalStateException("No modern id found for $key")
}

return [modernIDs[key], value]
} })

idMap.forEach({ version, ids ->
ids.forEach({ key, id ->
Expand All @@ -551,6 +563,8 @@ void generateRegistryMappings(File targetDir, Map<MinecraftVersion, Object> regi
this.generateRegistryMapping("item", targetDir, registriesReports
.findAll({ e -> MinecraftVersion.WORLD_VERSIONS.contains(e.getKey()) }))
this.generateRegistryMapping("block", targetDir, registriesReports)
this.generateRegistryMapping("data_component_type", targetDir, registriesReports
.findAll({ e -> MinecraftVersion.COMPONENT_VERSIONS.contains(e.getKey()) }))

File blockEntitiesMappingFile = new File(targetDir, "blockentities_mapping.json");

Expand Down
4 changes: 4 additions & 0 deletions plugin/mapping/fallbackdata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"MINECRAFT_1_20_3": {
"minecraft:vault": "minecraft:spawner",
"minecraft:heavy_core": "minecraft:wither_skeleton_skull"
},
"MINECRAFT_1_20_2": {
"minecraft:short_grass": "minecraft:grass",
"minecraft:trial_spawner": "minecraft:spawner",
Expand Down
1 change: 1 addition & 0 deletions plugin/mapping/legacy_data_component_types_mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion plugin/mapping/legacy_items_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@
"1.13": "229",
"1.13.2": "229"
},
"minecraft:scute": {
"minecraft:turtle_scute": {
"1.13": "466",
"1.13.2": "471"
},
Expand Down
11 changes: 10 additions & 1 deletion plugin/src/main/java/net/elytrium/limboapi/LimboAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import net.elytrium.limboapi.api.material.Item;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.protocol.PreparedPacket;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.elytrium.limboapi.api.protocol.packets.PacketFactory;
import net.elytrium.limboapi.file.WorldFileTypeRegistry;
import net.elytrium.limboapi.injection.disconnect.DisconnectListener;
Expand All @@ -95,6 +96,8 @@
import net.elytrium.limboapi.protocol.packets.PacketFactoryImpl;
import net.elytrium.limboapi.server.CachedPackets;
import net.elytrium.limboapi.server.LimboImpl;
import net.elytrium.limboapi.server.item.SimpleItemComponentManager;
import net.elytrium.limboapi.server.item.SimpleItemComponentMap;
import net.elytrium.limboapi.server.world.SimpleBlock;
import net.elytrium.limboapi.server.world.SimpleBlockEntity;
import net.elytrium.limboapi.server.world.SimpleItem;
Expand Down Expand Up @@ -122,7 +125,7 @@
@SuppressFBWarnings("MS_EXPOSE_REP")
public class LimboAPI implements LimboFactory {

private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 765;
private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 766;

@MonotonicNonNull
private static Logger LOGGER;
Expand All @@ -135,6 +138,7 @@ public class LimboAPI implements LimboFactory {
private final Set<Player> players;
private final CachedPackets packets;
private final PacketFactory packetFactory;
private final SimpleItemComponentManager itemComponentManager = new SimpleItemComponentManager();
private final HashMap<Player, LoginTasksQueue> loginQueue;
private final HashMap<Player, Function<KickedFromServerEvent, Boolean>> kickCallback;
private final HashMap<Player, RegisteredServer> nextServer;
Expand Down Expand Up @@ -510,6 +514,11 @@ public VirtualItem getLegacyItem(int itemLegacyID) {
return SimpleItem.fromLegacyID(itemLegacyID);
}

@Override
public ItemComponentMap createItemComponentMap() {
return new SimpleItemComponentMap(this.itemComponentManager);
}

@Override
public VirtualBlockEntity getBlockEntity(String entityID) {
return SimpleBlockEntity.fromModernID(entityID);
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/net/elytrium/limboapi/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static class MAIN {
"1_7_2, 1_7_6, 1_8, 1_9, 1_9_1, 1_9_2, 1_9_4, 1_10, 1_11, 1_11_1, 1_12, 1_12_1, 1_12_2,",
"1_13, 1_13_1, 1_13_2, 1_14, 1_14_1, 1_14_2, 1_14_3, 1_14_4, 1_15, 1_15_1, 1_15_2,",
"1_16, 1_16_1, 1_16_2, 1_16_3, 1_16_4, 1_17, 1_17_1, 1_18, 1_18_2, 1_19, 1_19_1, 1_19_3,",
"1_20, 1_20_2, 1_20_3, LATEST"
"1_20, 1_20_2, 1_20_3, 1_20_5, LATEST"
})
public String PREPARE_MIN_VERSION = "1_7_2";
public String PREPARE_MAX_VERSION = "LATEST";
Expand Down
Loading
Loading