Skip to content

Commit

Permalink
Add 3 tick cooldown to prevent instant double-smelting
Browse files Browse the repository at this point in the history
  • Loading branch information
NEstoll committed May 30, 2024
1 parent 90e04e6 commit d4bcb26
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,22 @@
public class MoltenCoreRodItem extends Item {

private static final int COST = 300;
private static final long COOLDOWN = 4;
private long lastUsedAt = -1;

public MoltenCoreRodItem(Properties props) {
super(props);
}

public InteractionResult onLeftClick(Player p, Level world, InteractionHand hand, BlockPos pos, Direction side) {
if (p.isSpectator()) {
return InteractionResult.PASS;
}
ItemStack stack = p.getItemInHand(hand);
if (stack.isEmpty() || !stack.is(this)) {
if (p.isSpectator() || stack.isEmpty() || !stack.is(this)) {
return InteractionResult.PASS;
}
Container dummyInv = new SimpleContainer(1);

if (!ManaItemHandler.instance().requestManaExactForTool(stack, p, COST, false)) {
return InteractionResult.PASS;
if (!ManaItemHandler.instance().requestManaExactForTool(stack, p, COST, false) || lastUsedAt + COOLDOWN > world.getGameTime()) {
return InteractionResult.SUCCESS;
}

Container dummyInv = new SimpleContainer(1);
BlockState state = world.getBlockState(pos);

dummyInv.setItem(0, new ItemStack(state.getBlock()));
Expand All @@ -60,8 +57,8 @@ public InteractionResult onLeftClick(Player p, Level world, InteractionHand hand
world.playSound(null, p.getX(), p.getY(), p.getZ(), BotaniaSounds.smeltRod2, SoundSource.PLAYERS, 1F, 1F);

ManaItemHandler.instance().requestManaExactForTool(stack, p, COST, true);
lastUsedAt = world.getGameTime();
}

WispParticleData data1 = WispParticleData.wisp(0.5F, 1F, 0.2F, 0.2F, 1);
for (int i = 0; i < 25; i++) {
double x = pos.getX() + Math.random();
Expand Down

0 comments on commit d4bcb26

Please sign in to comment.