int x = 10; int y = 10; int width = 100; int height = 10; int filledWidth = (int)((energy / (float)maxEnergy) * width);
@Mixin(ClientPlayerInteractionManager.class) public class BreakBlockMixin @Inject(method = "breakBlock", at = @At("HEAD")) private void onBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) MinecraftClient.getInstance().player.ifPresent(player -> EnergyComponent comp = EnergyClientMod.ENERGY.get(player); comp.onBreakBlock(); ); energy client minecraft
@Override public void onHudRender(DrawContext context, RenderTickCounter tickCounter) MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null) return; int x = 10; int y = 10;
@Override public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) ItemStack stack = user.getStackInHand(hand); EnergyComponent energy = EnergyClientMod.ENERGY.get(user); if (energy.getEnergy() < energy.getMaxEnergy()) energy.addEnergy(charge); stack.decrementUnlessCreative(1, user); return TypedActionResult.success(stack); return TypedActionResult.fail(stack); int x = 10
public class EnergyComponent implements Component, AutoSyncedComponent, ServerTickingComponent public static final int MAX_ENERGY = 1000; private static final int GEN_WALK = 2; private static final int GEN_SPRINT = 5; private static final int COST_SPRINT = 3; private static final int COST_JUMP = 10; private static final int COST_ATTACK = 15; private static final int COST_BREAK = 8;
// Drain actions if (player.isSprinting() && player.isOnGround()) if (!consume(COST_SPRINT)) player.setSprinting(false);