Skip to content

Commit 1ca86dc

Browse files
committed
1.0.1: Ability to set item data value on legacy versions
1 parent 646fc93 commit 1ca86dc

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.1

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
setGroup("net.elytrium")
12-
setVersion("1.0.1-SNAPSHOT")
12+
setVersion("1.0.1")
1313

1414
compileJava {
1515
getOptions().setEncoding("UTF-8")

src/main/java/net/elytrium/limbohub/LimboHub.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void reload() {
248248
.map(line -> buildResetComponent().append(getSerializer().deserialize(line)))
249249
.collect(Collectors.toList());
250250

251-
return new ItemStack(virtualItem, fallbackItems, item.COUNT, 0, new StaticItemMeta(
251+
return new ItemStack(virtualItem, fallbackItems, item.COUNT, item.DATA, new StaticItemMeta(
252252
nameComponent, loreComponents, item.HAS_COLOR, item.COLOR, item.ENCHANTED, item.SKULL_OWNER));
253253
}
254254
));
@@ -272,6 +272,10 @@ public void reload() {
272272
for (int column = 0; column < columns; column++) {
273273
String itemId = format.substring(column, column + 1);
274274
ItemStack item = " ".equals(itemId) ? ItemStack.EMPTY : items.get(itemId);
275+
if (item == null) {
276+
throw new IllegalArgumentException("Item with id '" + itemId + "' is not defined.");
277+
}
278+
275279
container.setItem(column, row, item);
276280
}
277281
}

src/main/java/net/elytrium/limbohub/Settings.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ public static class COMMAND {
176176
"menu",
177177
"Menu",
178178
List.of(
179-
Settings.createNodeSequence(MENU.ITEM_DATA.class, ".", "minecraft:black_stained_glass_pane", List.of("minecraft:glass_pane"), 1, false, 0, false, "", "", List.of()),
180-
Settings.createNodeSequence(MENU.ITEM_DATA.class, "1", "minecraft:leather_helmet", List.of(), 1, true, 12544467, false, "", "&fOpen another menu", List.of()),
181-
Settings.createNodeSequence(MENU.ITEM_DATA.class, "2", "minecraft:stone", List.of(), 2, false, 0, true, "", "&fServer1", List.of("&r&7This is a server.")),
182-
Settings.createNodeSequence(MENU.ITEM_DATA.class, "3", "minecraft:player_head", List.of("minecraft:experience_bottle"), 1, false, 0, false, "f051234a-8c3d-45d5-8e78-df729dd0da8c;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0=", "&fWhat is this?", List.of())
179+
Settings.createNodeSequence(MENU.ITEM_DATA.class, ".", "minecraft:black_stained_glass_pane", List.of("minecraft:white_stained_glass_pane"), 1, 15, false, 0, false, "", "", List.of()),
180+
Settings.createNodeSequence(MENU.ITEM_DATA.class, "1", "minecraft:leather_helmet", List.of(), 1, 0, true, 12544467, false, "", "&fOpen another menu", List.of()),
181+
Settings.createNodeSequence(MENU.ITEM_DATA.class, "2", "minecraft:stone", List.of(), 2, 0, false, 0, true, "", "&fServer1", List.of("&r&7This is a server.")),
182+
Settings.createNodeSequence(MENU.ITEM_DATA.class, "3", "minecraft:player_head", List.of("minecraft:experience_bottle"), 1, 0, false, 0, false, "f051234a-8c3d-45d5-8e78-df729dd0da8c;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0=", "&fWhat is this?", List.of())
183183
),
184184
List.of(
185185
".........",
@@ -196,9 +196,9 @@ public static class COMMAND {
196196
"menu2",
197197
"Another Menu",
198198
List.of(
199-
Settings.createNodeSequence(MENU.ITEM_DATA.class, ".", "minecraft:black_stained_glass_pane", List.of("minecraft:glass_pane"), 1, false, 0, false, "", "", List.of()),
200-
Settings.createNodeSequence(MENU.ITEM_DATA.class, "1", "minecraft:barrier", List.of(), 1, false, 0, false, "", "&fClose menu", List.of()),
201-
Settings.createNodeSequence(MENU.ITEM_DATA.class, "2", "minecraft:bedrock", List.of(), 1, false, 0, false, "", "&fGo back", List.of())
199+
Settings.createNodeSequence(MENU.ITEM_DATA.class, ".", "minecraft:black_stained_glass_pane", List.of("minecraft:white_stained_glass_pane"), 1, 15, false, 0, false, "", "", List.of()),
200+
Settings.createNodeSequence(MENU.ITEM_DATA.class, "1", "minecraft:barrier", List.of(), 1, 0, false, 0, false, "", "&fClose menu", List.of()),
201+
Settings.createNodeSequence(MENU.ITEM_DATA.class, "2", "minecraft:bedrock", List.of(), 1, 0, false, 0, false, "", "&fGo back", List.of())
202202
),
203203
List.of(
204204
".........",
@@ -230,6 +230,8 @@ public static class ITEM_DATA {
230230
public String ITEM = "";
231231
public List<String> FALLBACK_ITEMS = List.of();
232232
public int COUNT = 1;
233+
@Comment("Only used on legacy versions (1.12.2 and lower).")
234+
public int DATA = 0;
233235
public boolean HAS_COLOR = false;
234236
@Comment("You can get color value at https://notwoods.github.io/minecraft-tools/armorcolor/.")
235237
public int COLOR = 0;

src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
6868
if (this.present) {
6969
VirtualItem item = this.items.stream()
7070
.dropWhile(i -> !i.isSupportedOn(protocolVersion))
71-
.findFirst().orElseThrow();
71+
.findFirst().orElseThrow(() ->
72+
new IllegalArgumentException("Item " + this.items.get(0).getModernID() + " is not supported on " + protocolVersion));
7273

7374
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13_2) < 0) {
7475
buf.writeShort(item.getID(protocolVersion));

src/main/java/net/elytrium/limbohub/protocol/packets/SetContainerContent.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.velocitypowered.proxy.protocol.MinecraftPacket;
2323
import com.velocitypowered.proxy.protocol.ProtocolUtils;
2424
import io.netty.buffer.ByteBuf;
25+
import java.util.Objects;
2526
import net.elytrium.limbohub.protocol.container.Container;
2627
import net.elytrium.limbohub.protocol.item.ItemStack;
2728

@@ -55,7 +56,8 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
5556
buf.writeShort(this.container.getContents().length);
5657
}
5758
for (ItemStack item : this.container.getContents()) {
58-
item.encode(buf, protocolVersion);
59+
Objects.requireNonNullElse(item, ItemStack.EMPTY)
60+
.encode(buf, protocolVersion);
5961
}
6062
} else {
6163
int slots = 45;

0 commit comments

Comments
 (0)