Skip to content

Commit

Permalink
minecraft:profile item component support
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed Apr 24, 2024
1 parent 89c69e3 commit 588b755
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.elytrium.limboapi.server.item.type.DyedColorItemComponent;
import net.elytrium.limboapi.server.item.type.EmptyItemComponent;
import net.elytrium.limboapi.server.item.type.EnchantmentsItemComponent;
import net.elytrium.limboapi.server.item.type.GameProfileItemComponent;
import net.elytrium.limboapi.server.item.type.IntItemComponent;
import net.elytrium.limboapi.server.item.type.StringItemComponent;
import net.elytrium.limboapi.server.item.type.StringsItemComponent;
Expand Down Expand Up @@ -84,9 +85,15 @@ public class SimpleItemComponentManager {
private final Map<String, Function<ProtocolVersion, WriteableItemComponent>> factory = new HashMap<>();

public SimpleItemComponentManager() {
// TODO: implement missing components
// TODO: implement missing components:
// trim, intangible_projectile, food, suspicious_stew_effects, lock, tool,
// can_break, writable_book_content, potion_contents, bees, banner_patterns,
// pot_decorations, map_decorations, debug_stick_state, can_place_on, lodestone_tracker,
// written_book_content, container_loot, container, block_state, attribute_modifiers,
// bundle_contents, firework_explosion, charged_projectiles, fireworks
this.register("minecraft:lore", version -> new ComponentsItemComponent("minecraft:lore"));
this.register("minecraft:dyed_color", version -> new DyedColorItemComponent("minecraft:dyed_color"));
this.register("minecraft:profile", version -> new GameProfileItemComponent("minecraft:profile"));

for (String type : new String[] { "minecraft:max_stack_size", "minecraft:max_damage",
"minecraft:damage", "minecraft:rarity", "minecraft:custom_model_data",
Expand Down Expand Up @@ -130,10 +137,6 @@ public SimpleItemComponentManager() {
}
}

public void registerVarInt(String name) {
this.register(name, version -> new VarIntItemComponent(name));
}

public <T> void register(String name, Function<ProtocolVersion, WriteableItemComponent> factory) {
this.factory.put(name, factory);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2021 - 2024 Elytrium
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.elytrium.limboapi.server.item.type;

import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import java.util.UUID;

public class GameProfileItemComponent extends WriteableItemComponent<GameProfile> {

private static final UUID ZERO = new UUID(0, 0);

public GameProfileItemComponent(String name) {
super(name);
}

@Override
public void write(ProtocolVersion version, ByteBuf buffer) {
buffer.writeBoolean(!this.getValue().getName().isEmpty());
if (!this.getValue().getName().isEmpty()) {
ProtocolUtils.writeString(buffer, this.getValue().getName());
}

buffer.writeBoolean(!this.getValue().getId().equals(ZERO));
if (!this.getValue().getId().equals(ZERO)) {
ProtocolUtils.writeUuid(buffer, this.getValue().getId());
}

ProtocolUtils.writeProperties(buffer, this.getValue().getProperties());
}
}

0 comments on commit 588b755

Please sign in to comment.