Skip to content

Commit

Permalink
Show progress bar when throwing items (#637)
Browse files Browse the repository at this point in the history
* Add #612

* Changes in response to review
  • Loading branch information
RealRTTV authored May 29, 2024
1 parent 3f28e73 commit eb7e3a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.util.StringRepresentable;
Expand Down Expand Up @@ -100,6 +103,7 @@ public class EnchantmentCracker {
*/

public static final Logger LOGGER = LogUtils.getLogger();
private static final int PROGRESS_BAR_WIDTH = 50;

// RENDERING
/*
Expand Down Expand Up @@ -451,6 +455,26 @@ public boolean condition() {
}
return super.condition();
}

@Override
public void onCompleted() {
Minecraft.getInstance().player.playNotifySound(SoundEvents.NOTE_BLOCK_PLING.value(), SoundSource.PLAYERS, 1.0f, 2.0f);
}

@Override
protected void onItemThrown(int current, int total) {
MutableComponent builder = Component.empty();
int color = Mth.hsvToRgb(current / (total * 3.0f), 1.0f, 1.0f);
builder.append(Component.literal("[").withColor(0xAAAAAA));
builder.append(Component.literal("~" + Math.round(100.0 * current / total) + "%").withColor(color));
builder.append(Component.literal("] ").withColor(0xAAAAAA));
int filledWidth = (int) Math.round((double) PROGRESS_BAR_WIDTH * current / total);
int unfilledWidth = PROGRESS_BAR_WIDTH - filledWidth;
builder.append(Component.literal("|".repeat(filledWidth)).withColor(color));
builder.append(Component.literal("|".repeat(unfilledWidth)).withColor(0xAAAAAA));

Minecraft.getInstance().gui.setOverlayMessage(builder, false);
}
});
}
// dummy enchantment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void onTick() {
onFailedToThrowItem();
return;
}
sentItemThrows++;
onItemThrown(++sentItemThrows, totalItemsToThrow);
}

if (!waitingFence && sentItemThrows == totalItemsToThrow && confirmedItemThrows < sentItemThrows) {
Expand Down Expand Up @@ -111,6 +111,9 @@ protected void onSuccess() {
protected void onItemSpawn(ClientboundAddEntityPacket packet) {
}

protected void onItemThrown(int current, int total) {
}

private static void handleItemSpawn(ClientboundAddEntityPacket packet) {
if (packet.getType() != EntityType.ITEM) {
return;
Expand Down

0 comments on commit eb7e3a7

Please sign in to comment.