Energy - Client Minecraft |link|
int x = 10; int y = 10; int width = 100; int height = 10; int filledWidth = (int)((energy / (float)maxEnergy) * width);
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;
@Override public void onHudRender(DrawContext context, RenderTickCounter tickCounter) MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null) return; energy client minecraft
// BatteryItem.java public class BatteryItem extends Item private final int charge; public BatteryItem(Settings settings, int charge) super(settings); this.charge = charge;
"custom": "cardinal-components": [ "energyclient:energy" ] int x = 10; int y = 10;
public int getEnergy() return energy; public int getMaxEnergy() return MAX_ENERGY; public void setEnergy(int amount) this.energy = Math.min(MAX_ENERGY, Math.max(0, amount)); public void addEnergy(int amount) setEnergy(energy + amount); public boolean consume(int amount) if (energy >= amount) energy -= amount; return true; return false;
@Override public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) registry.registerForPlayers(ENERGY, EnergyComponent::new, RespawnCopyStrategy.ALWAYS_COPY); int x = 10
@Override public void serverTick()