Skip to content

Commit

Permalink
repair delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Khar committed Nov 16, 2024
1 parent c27ae5e commit 41abe8e
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin implements CustomPlayerEntityData {

Expand Down Expand Up @@ -85,7 +83,7 @@ private void setCustomHurtTimeOnDamage(DamageSource source, float amount, Callba
if (foundEntity != null) hybrid_aquatic$setHurtTime(200);
}
}

@Inject(method = "tick", at = @At("TAIL"))
private void tickDownCustomHurtTime(CallbackInfo ci) {
int cHurtTime = hybrid_aquatic$getHurtTime();
Expand All @@ -99,7 +97,7 @@ private void tickDownCustomHurtTime(CallbackInfo ci) {
// Gives Resistance and Slowness if player has Turtle chestplate equipped
updateTurtleChestplate();
// Repairs coral tools in the water
repairCoralTools();
repairCoralTools(10);
}

@Unique
Expand Down Expand Up @@ -139,14 +137,24 @@ private void updateTurtleChestplate() {
}

@Unique
private void repairCoralTools() {
int coralRepairTick = 0;
@Unique
private void repairCoralTools(int tickDelay) {
var player = (PlayerEntity)(Object)this;

if (player.isSubmergedIn(FluidTags.WATER)) {
player.getItemsEquipped().forEach(itemStack -> {
if (itemStack.getItem() instanceof ToolItem tool && tool.getMaterial() == HybridAquaticToolMaterials.CORAL) {
itemStack.setDamage(itemStack.getDamage() - 1);
}
});
if (coralRepairTick > tickDelay) {
player.getItemsEquipped().forEach(itemStack -> {
if (itemStack.getItem() instanceof ToolItem tool &&
tool.getMaterial() == HybridAquaticToolMaterials.CORAL &&
itemStack.isDamaged()) {
itemStack.setDamage(itemStack.getDamage() - 1);
}
});
coralRepairTick = 0;
}

coralRepairTick++;
}
}
}

0 comments on commit 41abe8e

Please sign in to comment.