Skip to content

Commit c861c64

Browse files
committed
Made Omni-breaker enchantable with unbreaking
1 parent 2400ebd commit c861c64

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/net/neganote/gtutilities/common/item/OmniBreakerItem.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import net.minecraft.world.item.Item;
1313
import net.minecraft.world.item.ItemStack;
1414
import net.minecraft.world.item.TooltipFlag;
15+
import net.minecraft.world.item.enchantment.Enchantment;
16+
import net.minecraft.world.item.enchantment.Enchantments;
1517
import net.minecraft.world.level.Level;
1618
import net.minecraft.world.level.block.state.BlockState;
1719

@@ -66,15 +68,37 @@ public boolean mineBlock(@NotNull ItemStack pStack, @NotNull Level pLevel, @NotN
6668

6769
var electricItem = Objects.requireNonNull(GTCapabilityHelper.getElectricItem(pStack));
6870

71+
var unbreaking = getAllEnchantments(pStack).getOrDefault(Enchantments.UNBREAKING, 0);
72+
double chance = 1.0f / (unbreaking + 1);
73+
74+
double rand = Math.random();
75+
6976
if (electricItem.getCharge() >= GTValues.VEX[tier]) {
70-
// Only discharge if possible to discharge the full amount
71-
electricItem.discharge(GTValues.VEX[tier], tier, true, false, false);
77+
// Only discharge if possible to discharge the full amount and unbreaking chance doesn't proc
78+
if (rand <= chance) {
79+
electricItem.discharge(GTValues.VEX[tier], tier, true, false, false);
80+
}
7281
return true;
7382
} else {
7483
return false;
7584
}
7685
}
7786

87+
@Override
88+
public int getEnchantmentValue(ItemStack stack) {
89+
return 22;
90+
}
91+
92+
@Override
93+
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
94+
return enchantment == Enchantments.UNBREAKING;
95+
}
96+
97+
@Override
98+
public boolean isEnchantable(ItemStack stack) {
99+
return true;
100+
}
101+
78102
@Override
79103
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level,
80104
@NotNull List<Component> tooltipComponents, @NotNull TooltipFlag isAdvanced) {

src/main/java/net/neganote/gtutilities/common/item/PrecisionBreakBehavior.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.core.BlockPos;
88
import net.minecraft.world.InteractionResult;
99
import net.minecraft.world.item.context.UseOnContext;
10+
import net.minecraft.world.item.enchantment.Enchantments;
1011
import net.minecraft.world.level.Level;
1112
import net.minecraft.world.level.block.state.BlockState;
1213

@@ -29,11 +30,18 @@ public InteractionResult useOn(UseOnContext context) {
2930
return InteractionResult.PASS;
3031
}
3132

33+
int unbreaking = context.getItemInHand().getItem().getAllEnchantments(context.getItemInHand())
34+
.getOrDefault(Enchantments.UNBREAKING, 0);
35+
double chance = 1.0f / (unbreaking + 1);
36+
double rand = Math.random();
37+
3238
var electricItem = GTCapabilityHelper.getElectricItem(context.getItemInHand());
3339

3440
if (electricItem != null) {
3541
if (electricItem.getCharge() >= GTValues.VEX[tier]) {
36-
electricItem.discharge(GTValues.VEX[tier], tier, true, false, false);
42+
if (rand >= chance) {
43+
electricItem.discharge(GTValues.VEX[tier], tier, true, false, false);
44+
}
3745
} else {
3846
return InteractionResult.PASS;
3947
}

0 commit comments

Comments
 (0)