Skip to content

Commit

Permalink
Added ItemBuilder#component(type, value)
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed May 31, 2024
1 parent b9bcabc commit 7e1814a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import dev.latvian.mods.kubejs.util.ID;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -63,6 +64,7 @@ public static Tier toolTierOf(Object o) {
return ItemBuilder.TOOL_TIERS.getOrDefault(ID.kjsString(asString), Tiers.IRON);
}

public transient Map<DataComponentType<?>, Object> components;
public transient int maxStackSize;
public transient int maxDamage;
public transient int burnTime;
Expand Down Expand Up @@ -162,6 +164,15 @@ public void generateAssetJsons(AssetJsonGenerator generator) {
});
}

public <T> ItemBuilder component(DataComponentType<T> type, T value) {
if (components == null) {
components = new HashMap<>();
}

components.put(type, value);
return this;
}

@Info("Sets the item's max stack size. Default is 64.")
public ItemBuilder maxStackSize(int v) {
maxStackSize = v;
Expand Down Expand Up @@ -319,6 +330,12 @@ public ItemBuilder fireResistant() {
public Item.Properties createItemProperties() {
var properties = new KubeJSItemProperties(this);

if (components != null) {
for (var entry : components.entrySet()) {
properties.component((DataComponentType) entry.getKey(), entry.getValue());
}
}

if (maxDamage > 0) {
properties.durability(maxDamage);
} else {
Expand Down

0 comments on commit 7e1814a

Please sign in to comment.