Skip to content

Commit

Permalink
Enhance AdvancedItemSettings#hasBrokenState
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Oct 15, 2024
1 parent 1aa30ba commit 10222bb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public class AdvancedItemSettings extends QuiltItemSettings {

public static final CustomItemSetting<List<Formatting>> NAME_FORMATTINGS = CustomItemSetting.create(Collections::emptyList);
public static final CustomItemSetting<Text[]> DESCRIPTION_LINES = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<Function<ItemStack, Boolean>> GLINT = CustomItemSetting.create((stack) -> false);
public static final CustomItemSetting<Function<ItemStack, Boolean>> GLINT = CustomItemSetting.create(stack -> false);
public static final CustomItemSetting<GlintPackView> GLINT_PACK = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<Boolean> EATABLE = CustomItemSetting.create(Boolean.FALSE);
public static final CustomItemSetting<Boolean> DRINKABLE = CustomItemSetting.create(Boolean.FALSE);
public static final CustomItemSetting<Boolean> HAS_BROKEN_STATE = CustomItemSetting.create(Boolean.FALSE);
public static final CustomItemSetting<Predicate<ItemStack>> HAS_BROKEN_STATE = CustomItemSetting.create(stack -> false);
public static final CustomItemSetting<ItemUse> ITEM_USE = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<ItemFinishUsing> ITEM_FINISH_USING = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<ItemUseOnBlock> ITEM_USE_ON_BLOCK = CustomItemSetting.create(() -> null);
Expand Down Expand Up @@ -65,7 +66,11 @@ public AdvancedItemSettings drinkable() {
}

public AdvancedItemSettings hasBrokenState() {
return this.customSetting(HAS_BROKEN_STATE, true);
return this.hasBrokenState(stack -> true);
}

public AdvancedItemSettings hasBrokenState(Predicate<ItemStack> hasBrokenState) {
return this.customSetting(HAS_BROKEN_STATE, hasBrokenState);
}

public AdvancedItemSettings itemUse(ItemUse itemUseSetting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void getUseAction(ItemStack stack, CallbackInfoReturnable<UseAction> cir

@Unique
protected boolean isBroken(ItemStack stack) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject())) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject()).test(stack)) {
return stack.getDamage() >= stack.getMaxDamage();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void cancelIfBroken(ItemStack stack, BlockState state, CallbackInfoRetur

@WrapOperation(method = "postHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
private void cancelHitStackDamageIfBroken(ItemStack instance, int amount, LivingEntity entity, Consumer<LivingEntity> breakCallback, Operation<Void> original) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject())) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject()).test(instance)) {
instance.setDamage(Math.min(instance.getDamage() + amount, instance.getMaxDamage()));
}
else {
Expand All @@ -46,7 +46,7 @@ private void postHit(ItemStack stack, LivingEntity target, LivingEntity attacker

@WrapOperation(method = "postMine", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
private void cancelMineStackDamageIfBroken(ItemStack instance, int amount, LivingEntity entity, Consumer<LivingEntity> breakCallback, Operation<Void> original) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject())) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject()).test(instance)) {
instance.setDamage(Math.min(instance.getDamage() + amount, instance.getMaxDamage()));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void cancelIfBroken(ItemStack stack, BlockState state, CallbackInfoRetur

@WrapOperation(method = "postHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
private void cancelHitStackDamageIfBroken(ItemStack instance, int amount, LivingEntity entity, Consumer<LivingEntity> breakCallback, Operation<Void> original) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject())) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject()).test(instance)) {
instance.setDamage(Math.min(instance.getDamage() + amount, instance.getMaxDamage()));
}
else {
Expand All @@ -51,7 +51,7 @@ private void postHit(ItemStack stack, LivingEntity target, LivingEntity attacker

@WrapOperation(method = "postMine", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
private void cancelMineStackDamageIfBroken(ItemStack instance, int amount, LivingEntity entity, Consumer<LivingEntity> breakCallback, Operation<Void> original) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject())) {
if (AdvancedItemSettings.HAS_BROKEN_STATE.get(this.getObject()).test(instance)) {
instance.setDamage(Math.min(instance.getDamage() + amount, instance.getMaxDamage()));
}
else {
Expand Down

0 comments on commit 10222bb

Please sign in to comment.