Skip to content

Commit

Permalink
Merge pull request #884 from pietro-lopes/main
Browse files Browse the repository at this point in the history
fixed jukebox and added disableRepair
  • Loading branch information
LatvianModder authored Aug 18, 2024
2 parents 23977a9 + 13ea323 commit 7578f05
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/dev/latvian/mods/kubejs/item/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import dev.latvian.mods.kubejs.script.ConsoleJS;
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -79,6 +79,7 @@ public record HurtEnemyContext(ItemStack getItem, LivingEntity getTarget, Living

public transient Tool tool;
public transient ItemAttributeModifiers itemAttributeModifiers;
public transient boolean canRepair;

public ItemBuilder(ResourceLocation i) {
super(i);
Expand All @@ -104,6 +105,7 @@ public ItemBuilder(ResourceLocation i) {

tool = null;
itemAttributeModifiers = null;
canRepair = true;
}

@Override
Expand Down Expand Up @@ -377,15 +379,20 @@ public ItemBuilder hurtEnemy(Predicate<HurtEnemyContext> context) {
return this;
}

public ItemBuilder jukeboxPlayable(Holder<JukeboxSong> song, boolean showInTooltip) {
public ItemBuilder jukeboxPlayable(ResourceKey<JukeboxSong> song, boolean showInTooltip) {
this.jukeboxPlayable = new JukeboxPlayable(new EitherHolder<>(song), showInTooltip);
return this;
}

public ItemBuilder jukeboxPlayable(Holder<JukeboxSong> song) {
public ItemBuilder jukeboxPlayable(ResourceKey<JukeboxSong> song) {
return jukeboxPlayable(song, true);
}

public ItemBuilder disableRepair() {
this.canRepair = false;
return this;
}

@FunctionalInterface
public interface UseCallback {
boolean use(Level level, Player player, InteractionHand interactionHand);
Expand Down Expand Up @@ -457,6 +464,10 @@ public Item.Properties createItemProperties() {
properties.component(DataComponents.JUKEBOX_PLAYABLE, jukeboxPlayable);
}

if (!canRepair) {
properties.setNoRepair();
}

return properties;
}
}

0 comments on commit 7578f05

Please sign in to comment.