|
| 1 | +package com.gregtechceu.gtceu.integration.kjs.events; |
| 2 | + |
| 3 | +import com.gregtechceu.gtceu.GTCEu; |
| 4 | +import com.gregtechceu.gtceu.data.recipe.WoodTypeEntry; |
| 5 | + |
| 6 | +import net.minecraft.world.item.Item; |
| 7 | +import net.minecraft.world.item.Items; |
| 8 | + |
| 9 | +import dev.latvian.mods.kubejs.event.EventResult; |
| 10 | +import dev.latvian.mods.kubejs.event.KubeEvent; |
| 11 | +import dev.latvian.mods.rhino.util.HideFromJS; |
| 12 | + |
| 13 | +import java.util.ArrayList; |
| 14 | + |
| 15 | +public class RegisterWoodsKubeEvent implements KubeEvent { |
| 16 | + |
| 17 | + public RegisterWoodsKubeEvent() { |
| 18 | + this.woods = new ArrayList<>(); |
| 19 | + this.wrapped = new ArrayList<>(); |
| 20 | + } |
| 21 | + |
| 22 | + @HideFromJS |
| 23 | + public ArrayList<WoodTypeEntry> woods; |
| 24 | + @HideFromJS |
| 25 | + public ArrayList<Wrapped> wrapped; |
| 26 | + |
| 27 | + public class Wrapped { |
| 28 | + |
| 29 | + RegisterWoodsKubeEvent evt; |
| 30 | + String modId; |
| 31 | + String woodName; |
| 32 | + |
| 33 | + @HideFromJS |
| 34 | + Wrapped(String modId, String woodName) { |
| 35 | + this.modId = modId; |
| 36 | + this.woodName = woodName; |
| 37 | + } |
| 38 | + |
| 39 | + // public Wrapped id(KubeResourceLocation _id) { |
| 40 | + // String namespace = id.wrapped().getNamespace(); |
| 41 | + // // if (namespace.equals("kubejs")) { |
| 42 | + // // namespace = this.type.id.getNamespace(); |
| 43 | + // // } |
| 44 | + // var idWithoutType = ResourceLocation.fromNamespaceAndPath(namespace, |
| 45 | + // _id.wrapped().getPath()); |
| 46 | + // var id = idWithoutType.withPrefix(this.type.id.getPath() + "/"); |
| 47 | + // return this; |
| 48 | + // } |
| 49 | + |
| 50 | + private String _recipeId; |
| 51 | + private Item _plank; |
| 52 | + private Item _strippedLog; |
| 53 | + private Item _strippedWood; |
| 54 | + private Item _wood; |
| 55 | + private Item _log; |
| 56 | + private Item _door; |
| 57 | + private Item _trapdoor; |
| 58 | + private Item _slab; |
| 59 | + private Item _fence; |
| 60 | + private Item _fenceGate; |
| 61 | + private Item _stairs; |
| 62 | + private Item _boat; |
| 63 | + private Item _chestBoat; |
| 64 | + private Item _sign; |
| 65 | + private Item _hangingSign; |
| 66 | + private Item _button; |
| 67 | + private Item _pressurePlate; |
| 68 | + |
| 69 | + public Wrapped recipeId(String recipeId) { |
| 70 | + this._recipeId = recipeId; |
| 71 | + return this; |
| 72 | + } |
| 73 | + |
| 74 | + public Wrapped plank(Item plank) { |
| 75 | + this._plank = plank; |
| 76 | + return this; |
| 77 | + } |
| 78 | + |
| 79 | + public Wrapped strippedLog(Item strippedLog) { |
| 80 | + this._strippedLog = strippedLog; |
| 81 | + return this; |
| 82 | + } |
| 83 | + |
| 84 | + public Wrapped strippedWood(Item strippedWood) { |
| 85 | + this._strippedWood = strippedWood; |
| 86 | + return this; |
| 87 | + } |
| 88 | + |
| 89 | + public Wrapped wood(Item wood) { |
| 90 | + this._wood = wood; |
| 91 | + return this; |
| 92 | + } |
| 93 | + |
| 94 | + public Wrapped log(Item log) { |
| 95 | + this._log = log; |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + public Wrapped door(Item door) { |
| 100 | + this._door = door; |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + public Wrapped trapdoor(Item trapdoor) { |
| 105 | + this._trapdoor = trapdoor; |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + public Wrapped slab(Item slab) { |
| 110 | + this._slab = slab; |
| 111 | + return this; |
| 112 | + } |
| 113 | + |
| 114 | + public Wrapped fence(Item fence) { |
| 115 | + this._fence = fence; |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + public Wrapped fenceGate(Item fenceGate) { |
| 120 | + this._fenceGate = fenceGate; |
| 121 | + return this; |
| 122 | + } |
| 123 | + |
| 124 | + public Wrapped stairs(Item stairs) { |
| 125 | + this._stairs = stairs; |
| 126 | + return this; |
| 127 | + } |
| 128 | + |
| 129 | + public Wrapped boat(Item boat) { |
| 130 | + this._boat = boat; |
| 131 | + return this; |
| 132 | + } |
| 133 | + |
| 134 | + public Wrapped chestBoat(Item chestBoat) { |
| 135 | + this._chestBoat = chestBoat; |
| 136 | + return this; |
| 137 | + } |
| 138 | + |
| 139 | + public Wrapped sign(Item sign) { |
| 140 | + this._sign = sign; |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + public Wrapped hangingSign(Item hangingSign) { |
| 145 | + this._hangingSign = hangingSign; |
| 146 | + return this; |
| 147 | + } |
| 148 | + |
| 149 | + public Wrapped button(Item button) { |
| 150 | + this._button = button; |
| 151 | + return this; |
| 152 | + } |
| 153 | + |
| 154 | + public Wrapped pressurePlate(Item pressurePlate) { |
| 155 | + this._pressurePlate = pressurePlate; |
| 156 | + return this; |
| 157 | + } |
| 158 | + |
| 159 | + @HideFromJS |
| 160 | + public WoodTypeEntry toEntry() throws IllegalArgumentException { |
| 161 | + if (this.modId == null) { |
| 162 | + throw new IllegalArgumentException("Need a modId"); |
| 163 | + } |
| 164 | + if (this.woodName == null) { |
| 165 | + throw new IllegalArgumentException("Need a woodName"); |
| 166 | + } |
| 167 | + if (this._recipeId == null) { |
| 168 | + throw new IllegalArgumentException("Need a recipeId"); |
| 169 | + } |
| 170 | + |
| 171 | + if (this._plank == null) { |
| 172 | + throw new IllegalArgumentException("Need a plank"); |
| 173 | + } |
| 174 | + |
| 175 | + if (this._strippedLog == null) { |
| 176 | + throw new IllegalArgumentException("Need a strippedLog"); |
| 177 | + } |
| 178 | + |
| 179 | + if (this._strippedWood == null) { |
| 180 | + throw new IllegalArgumentException("Need a strippedWood"); |
| 181 | + } |
| 182 | + |
| 183 | + if (this._wood == null) { |
| 184 | + throw new IllegalArgumentException("Need a wood"); |
| 185 | + } |
| 186 | + |
| 187 | + if (this._log == null) { |
| 188 | + throw new IllegalArgumentException("Need a log"); |
| 189 | + } |
| 190 | + |
| 191 | + if (this._door == null) { |
| 192 | + throw new IllegalArgumentException("Need a door"); |
| 193 | + } |
| 194 | + |
| 195 | + if (this._trapdoor == null) { |
| 196 | + throw new IllegalArgumentException("Need a trapdoor"); |
| 197 | + } |
| 198 | + |
| 199 | + if (this._slab == null) { |
| 200 | + throw new IllegalArgumentException("Need a slab"); |
| 201 | + } |
| 202 | + |
| 203 | + if (this._fence == null) { |
| 204 | + throw new IllegalArgumentException("Need a fence"); |
| 205 | + } |
| 206 | + |
| 207 | + if (this._fenceGate == null) { |
| 208 | + throw new IllegalArgumentException("Need a fenceGate"); |
| 209 | + } |
| 210 | + |
| 211 | + if (this._stairs == null) { |
| 212 | + throw new IllegalArgumentException("Need a stairs"); |
| 213 | + } |
| 214 | + |
| 215 | + if (this._boat == null) { |
| 216 | + throw new IllegalArgumentException("Need a boat"); |
| 217 | + } |
| 218 | + |
| 219 | + if (this._chestBoat == null) { |
| 220 | + throw new IllegalArgumentException("Need a chestBoat"); |
| 221 | + } |
| 222 | + |
| 223 | + if (this._sign == null) { |
| 224 | + throw new IllegalArgumentException("Need a sign"); |
| 225 | + } |
| 226 | + |
| 227 | + if (this._hangingSign == null) { |
| 228 | + throw new IllegalArgumentException("Need a hangingSign"); |
| 229 | + } |
| 230 | + |
| 231 | + if (this._button == null) { |
| 232 | + throw new IllegalArgumentException("Need a button"); |
| 233 | + } |
| 234 | + |
| 235 | + if (this._pressurePlate == null) { |
| 236 | + throw new IllegalArgumentException("Need a pressurePlate"); |
| 237 | + } |
| 238 | + |
| 239 | + var builder = new WoodTypeEntry.Builder(this.modId, this.woodName) |
| 240 | + .planks(this._plank, this._recipeId + "_planks") |
| 241 | + .log(Items.OAK_LOG).removeCharcoalRecipe() |
| 242 | + .strippedLog(this._strippedLog) |
| 243 | + .wood(this._wood) |
| 244 | + .strippedWood(this._strippedWood) |
| 245 | + .door(this._door, this._recipeId + "_door") |
| 246 | + .trapdoor(this._trapdoor, this._recipeId + "_trapdoor") |
| 247 | + .slab(this._slab, this._recipeId + "_slab") |
| 248 | + .fence(this._fence, this._recipeId + "_fence") |
| 249 | + .fenceGate(this._fenceGate, this._recipeId + "_fence_gate") |
| 250 | + .stairs(this._stairs, this._recipeId + "_stairs") |
| 251 | + .boat(this._boat, this._recipeId + "_boat") |
| 252 | + .chestBoat(this._chestBoat, this._recipeId + "_chest_boat") |
| 253 | + .sign(this._sign, this._recipeId + "_sign") |
| 254 | + .hangingSign(this._hangingSign, this._recipeId + "_hanging_sign") |
| 255 | + .button(this._button, this._recipeId + "_button") |
| 256 | + .pressurePlate(this._pressurePlate, this._recipeId + "_pressure_plate") |
| 257 | + .registerAllMaterialInfo() |
| 258 | + .build(); |
| 259 | + return builder; |
| 260 | + } |
| 261 | + |
| 262 | + boolean wasRegisted = false; |
| 263 | + |
| 264 | + @HideFromJS |
| 265 | + public void register() { |
| 266 | + if (!this.wasRegisted) { |
| 267 | + try { |
| 268 | + woods.add(this.toEntry()); |
| 269 | + } catch (Exception e) { |
| 270 | + GTCEu.LOGGER.error(e); |
| 271 | + |
| 272 | + } |
| 273 | + } else |
| 274 | + GTCEu.LOGGER.warn("Tried registering a wood type twice!"); |
| 275 | + } |
| 276 | + }; |
| 277 | + |
| 278 | + public Wrapped register(String modId, String woodName) { |
| 279 | + var wrap = new Wrapped(modId, woodName); |
| 280 | + this.wrapped.add(wrap); |
| 281 | + return wrap; |
| 282 | + } |
| 283 | + |
| 284 | + @Override |
| 285 | + public void afterPosted(EventResult result) { |
| 286 | + for (var wrapped : this.wrapped) { |
| 287 | + wrapped.register(); |
| 288 | + } |
| 289 | + KubeEvent.super.afterPosted(result); |
| 290 | + } |
| 291 | +} |
0 commit comments