Skip to content

Commit

Permalink
feat: water wheel no longer disappears on break, but stops instead
Browse files Browse the repository at this point in the history
Breaking it drops an item with 0% durability, allowing possible repair
  • Loading branch information
desht committed Oct 24, 2023
1 parent 351c174 commit 7a80245
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import dev.ftb.mods.ftbricketyww.config.ConfigHolder;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;

import java.util.List;

Expand All @@ -29,14 +32,21 @@ public void tick() {

if (!level.isClientSide() && hasNetwork()) {
if (stress > 0f) {
durability--;
int prevDurability = durability;
durability = Math.max(0, durability - 1);
if (durability > ConfigHolder.maxDurability()) {
// in case config was changed on the fly
durability = ConfigHolder.maxDurability();
sendData();
} else if (durability <= 0) {
level.playSound(null, worldPosition, SoundEvents.ITEM_BREAK, SoundSource.BLOCKS, 1f, 1f);
level.destroyBlock(worldPosition, false);
} else if (durability == 0) {
if (prevDurability > 0) {
level.playSound(null, worldPosition, SoundEvents.ITEM_BREAK, SoundSource.BLOCKS, 1f, 1f);
getOrCreateNetwork().updateCapacityFor(this, 0f);
}
if (level.random.nextBoolean()) {
Vec3 vec = Vec3.atBottomCenterOf(getBlockPos().above());
((ServerLevel) level).sendParticles(ParticleTypes.SMOKE, vec.x(), vec.y(), vec.z(), 10, 0, 0, 0, 0);
}
} else if (durability % (ConfigHolder.maxDurability() / 100) == 0) {
// sync to client (also does a setChanged())
notifyUpdate();
Expand Down Expand Up @@ -73,4 +83,9 @@ public void write(CompoundTag compound, boolean clientPacket) {

compound.putInt("Durability", durability);
}

@Override
public float getGeneratedSpeed() {
return durability > 0 ? super.getGeneratedSpeed() : 0f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List<Compone
super.appendHoverText(stack, level, list, flag);

int durabilityPct = (int)(getDurability(stack) * 100);
list.add(Component.translatable("create.ricketyww.goggles.durability").withStyle(ChatFormatting.GRAY)
list.add(Component.translatable("create.ftbricketyww.goggles.durability").withStyle(ChatFormatting.GRAY)
.append(Component.literal(durabilityPct + "%").withStyle(ChatFormatting.AQUA)));
}

Expand Down

0 comments on commit 7a80245

Please sign in to comment.