Add api for shear equippable logic

This commit is contained in:
Owen1212055
2025-06-06 23:36:48 -04:00
parent 1e44102532
commit adb5aefcbf
2 changed files with 63 additions and 3 deletions

View File

@@ -104,6 +104,22 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
@Contract(pure = true)
boolean equipOnInteract();
/**
* Checks if the item can be sheared off an entity.
*
* @return true if can be sheared of an entity, false otherwise
*/
@Contract(pure = true)
boolean canBeSheared();
/**
* Returns the sound that is played when shearing this equipment off an entity.
*
* @return shear sound
*/
@Contract(pure = true)
Key shearSound();
/**
* Builder for {@link Equippable}.
*/
@@ -182,5 +198,23 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
*/
@Contract(value = "_ -> this", mutates = "this")
Builder equipOnInteract(boolean equipOnInteract);
/**
* Sets whether the item can be sheared off an entity.
*
* @param canBeSheared true if can be sheared off an entity
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder canBeSheared(boolean canBeSheared);
/**
* Sets the sound that is played when shearing this equipment off an entity.
*
* @param shearSound the shear sound key
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder shearSound(Key shearSound);
}
}

View File

@@ -82,6 +82,16 @@ public record PaperEquippable(
return this.impl.equipOnInteract();
}
@Override
public boolean canBeSheared() {
return this.impl.canBeSheared();
}
@Override
public Key shearSound() {
return PaperAdventure.asAdventure(this.impl.equipSound().value().location());
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this.slot())
@@ -92,7 +102,9 @@ public record PaperEquippable(
.dispensable(this.dispensable())
.swappable(this.swappable())
.damageOnHurt(this.damageOnHurt())
.equipOnInteract(this.equipOnInteract());
.equipOnInteract(this.equipOnInteract())
.shearSound(this.shearSound())
.canBeSheared(this.canBeSheared());
}
@@ -107,6 +119,8 @@ public record PaperEquippable(
private boolean swappable = true;
private boolean damageOnHurt = true;
private boolean equipOnInteract;
private boolean canBeSheared = false;
private Holder<SoundEvent> shearSound = BuiltInRegistries.SOUND_EVENT.wrapAsHolder(SoundEvents.SHEARS_SNIP);
BuilderImpl(final EquipmentSlot equipmentSlot) {
this.equipmentSlot = CraftEquipmentSlot.getNMS(equipmentSlot);
@@ -165,6 +179,18 @@ public record PaperEquippable(
return this;
}
@Override
public Builder canBeSheared(final boolean canBeSheared) {
this.canBeSheared = canBeSheared;
return this;
}
@Override
public Builder shearSound(final Key shearSound) {
this.shearSound = PaperAdventure.resolveSound(shearSound);
return this;
}
@Override
public Equippable build() {
return new PaperEquippable(
@@ -178,8 +204,8 @@ public record PaperEquippable(
this.swappable,
this.damageOnHurt,
this.equipOnInteract,
false, // TODO
Holder.direct(SoundEvents.GOAT_SCREAMING_DEATH) // TODO
this.canBeSheared,
this.shearSound
)
);
}