|
5 | 5 | import com.google.gson.JsonObject; |
6 | 6 | import com.mojang.datafixers.Dynamic; |
7 | 7 | import io.github.cottonmc.libcd.api.CDSyntaxError; |
| 8 | +import io.github.cottonmc.libcd.api.tag.TagHelper; |
8 | 9 | import io.github.cottonmc.libcd.api.tweaker.util.TweakerUtils; |
9 | 10 | import io.github.cottonmc.libcd.api.util.GsonOps; |
10 | 11 | import io.github.cottonmc.libcd.api.util.NbtMatchType; |
@@ -110,31 +111,45 @@ public static ItemStack processItemStack(Object input) throws CDSyntaxError { |
110 | 111 | else if (input instanceof String) { |
111 | 112 | String in = (String)input; |
112 | 113 | int atIndex = in.lastIndexOf('@'); |
| 114 | + int nbtIndex = in.indexOf('{'); |
113 | 115 | int count = 1; |
114 | 116 | if (atIndex != -1 && atIndex > in.lastIndexOf('}')) { |
115 | 117 | count = Integer.parseInt(in.substring(atIndex + 1)); |
116 | 118 | in = in.substring(0, atIndex); |
117 | 119 | } |
118 | | - if (in.contains("->") && in.indexOf("->") < in.indexOf('{')) { |
| 120 | + Item item; |
| 121 | + String nbt = ""; |
| 122 | + if (in.indexOf('#') == 0) { |
| 123 | + if (nbtIndex != -1) { |
| 124 | + nbt = in.substring(nbtIndex); |
| 125 | + in = in.substring(0, nbtIndex); |
| 126 | + } |
| 127 | + String tag = in.substring(1); |
| 128 | + Tag<Item> itemTag = ItemTags.getContainer().get(new Identifier(tag)); |
| 129 | + if (itemTag == null) throw new CDSyntaxError("Failed to get item tag for output: " + in); |
| 130 | + item = TagHelper.ITEM.getDefaultEntry(itemTag); |
| 131 | + } else if (in.contains("->") && in.indexOf("->") < in.indexOf('{')) { |
119 | 132 | ItemStack stack = TweakerUtils.INSTANCE.getSpecialStack(in); |
120 | 133 | if (stack.isEmpty()) |
121 | | - throw new CDSyntaxError("Failed to get special stack for input: " + in); |
| 134 | + throw new CDSyntaxError("Failed to get special stack for output: " + in); |
122 | 135 | if (stack.isStackable()) { |
123 | 136 | stack.setCount(count); |
124 | 137 | } |
125 | 138 | return stack; |
126 | 139 | } else { |
127 | | - int nbtIndex = in.indexOf('{'); |
128 | 140 | if (nbtIndex != -1) { |
129 | | - String nbt = in.substring(nbtIndex); |
| 141 | + nbt = in.substring(nbtIndex); |
130 | 142 | in = in.substring(0, nbtIndex); |
131 | | - ItemStack stack = new ItemStack(TweakerUtils.INSTANCE.getItem(in), count); |
132 | | - TweakerUtils.INSTANCE.addNbtToStack(stack, nbt); |
133 | | - return stack; |
134 | | - } else { |
135 | | - return new ItemStack(TweakerUtils.INSTANCE.getItem(in), count); |
136 | 143 | } |
| 144 | + item = TweakerUtils.INSTANCE.getItem(in); |
| 145 | + } |
| 146 | + |
| 147 | + ItemStack stack = new ItemStack(item, count); |
| 148 | + if (!nbt.equals("")) { |
| 149 | + TweakerUtils.INSTANCE.addNbtToStack(stack, nbt); |
137 | 150 | } |
| 151 | + |
| 152 | + return stack; |
138 | 153 | } |
139 | 154 | else throw new CDSyntaxError("Illegal object passed to recipe parser of type " + input.getClass().getName()); |
140 | 155 | } |
|
0 commit comments