Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I made mana through caps, it works, but I don’t know how to visually display it with a custom sprite. i made this code using minecraft and divinerpg sources as references but this code doesn't works. 
what wrong with it?

public class EtherRenderer {

    Minecraft mc = Minecraft.getInstance();

    @SubscribeEvent
    public void onRender(RenderGameOverlayEvent.Post event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
            onTickRender(event);
        }
    }

    private int getPercentage() {
        assert mc.player != null;
        Ether ether = mc.player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        float result = ether.getEther() / ether.getMaxEther() * 100;
        return (int) MathHelper.clamp(Math.floor(result), 0, 100);
    }

    @SubscribeEvent
    @SuppressWarnings("deprecation")
    private void onTickRender(RenderGameOverlayEvent.Post event) {
        if (mc.currentScreen == null) {
            GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
            IngameGui gui = mc.ingameGUI;
            int x = this.mc.getMainWindow().getScaledWidth() - 111;
            int y = this.mc.getMainWindow().getScaledHeight() - 18;
            gui.blit(event.getMatrixStack(), x, y, 0, 9, 100, 9);
            gui.blit(event.getMatrixStack(), x, y, 0, 9, getPercentage(), 18);
            this.mc.getTextureManager().bindTexture(new ResourceLocation(CoSRPG.MOD_ID, "textures/gui/ether_bar.png"));
        }
    }
}

 

  • Author
2 minutes ago, diesieben07 said:
  • Currently you are first drawing, then binding the texture. Obviously this is the wrong way around.
  • Why?

i don't know what to put in here lol. i tried null but it gives out npe, this thing worked with consume. is there other variants?

Edited by auriny

  • Author
2 minutes ago, diesieben07 said:

Currently you are first drawing, then binding the texture. Obviously this is the wrong way around.

i.e. should i move ```this.mc.getTextureManager().bindTexture(new ResourceLocation(CoSRPG.MOD_ID, "textures/gui/ether_bar.png"));``` up?

  • Author
6 minutes ago, diesieben07 said:

Do you expect your capability to ever not be there? If so, what you want might be the correct choice. But you need to think about it. Usually people always attach their capability, but still use orElse instead of orElseThrow (which would indicate absence as an error).

hmm ok thanks

6 minutes ago, diesieben07 said:

Correct.

going to try

  • Author
17 minutes ago, diesieben07 said:

Correct.

public class EtherRenderer {

    Minecraft mc = Minecraft.getInstance();

    @SubscribeEvent
    public void onRender(RenderGameOverlayEvent.Post event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
            onTickRender(event);
        }
    }

    private int getPercentage() {
        assert mc.player != null;
        Ether ether = mc.player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        float result = ether.getEther() / ether.getMaxEther() * 100;
        return (int) MathHelper.clamp(Math.floor(result), 0, 100);
    }

    @SuppressWarnings("deprecation")
    private void onTickRender(RenderGameOverlayEvent.Post event) {
        this.mc.getTextureManager().bindTexture(new ResourceLocation(CoSRPG.MOD_ID, "textures/gui/ether_bar.png"));
        if (mc.currentScreen == null) {
            GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
            IngameGui gui = mc.ingameGUI;
            int x = this.mc.getMainWindow().getScaledWidth() - 111;
            int y = this.mc.getMainWindow().getScaledHeight() - 18;
            gui.blit(event.getMatrixStack(), x, y, 0, 9, 100, 9);
            gui.blit(event.getMatrixStack(), x, y, 0, 9, getPercentage(), 18);
        }
    }
}

still doesn't work... did i do something wrong?
a bar is displayed, but it does not change depending on the ether (mana)

  • Author

how to use debugger? where is it?

9 minutes ago, diesieben07 said:

Is your ether_bar.png 256x256 pixels?

yes

  • Author
3 minutes ago, diesieben07 said:

This is basic Java programming knowledge and outside the scope of this forum.

are you talking about the one that activates on shift + f9? i thought you were talking about some kind of debugger in the game x)

  • Author

 

5 minutes ago, diesieben07 said:

I mean the normal Java debugger.

ok i got it

  • Author
1 hour ago, diesieben07 said:

Is your code executing

yes

 

1 hour ago, diesieben07 said:

Are your position calculations correct

yes, to make sure of this on 100%, i even changed the height of the second blit and i had two bars on the same level, not counting the height.

 

that's right

  • Author
3 minutes ago, diesieben07 said:

So by this you mean you changed your code and the blit started rendering something?

i changed my code and blit started rendering two bars, and all of those bars was full (i have two sprites: full and empty, and sprites was full)
and these bars still doesn't changed

  • Author

the problematic part of the code in getPercentage, i think, but what's wrong in it - idk

  • Author
21 minutes ago, diesieben07 said:

Do these methods return the correct value? Check with the debugger.

hmm no, ether is always equals 200, but this code working perfectly and if i make a certain number of right clicks, the whole ether will end
and in both cases its returning 200
 

    public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
        Ether ether = player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ItemStack itemstack = player.getHeldItem(hand);
        if (!world.isRemote() && ether.getEther() >= 25) { // <- here is breakpoint
            world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(),
                    SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.PLAYERS, 1, 1);
            ether.consume(player, 25);
            player.getCooldownTracker().setCooldown(this, 20);
            return ActionResult.resultFail(itemstack);
        }
        return ActionResult.resultSuccess(itemstack);
    }


ether = {Ether@18499} 
 tickDelay = 4
 max = 200.0
 ether = 200.0

did you sync your Capability to the client?

since rendering is client side only but it seems so you set the value only server side

  • Author
3 minutes ago, Luis_ST said:

did you sync your Capability to the client?

since rendering is client side only but it seems so you set the value only server side

seems like no, i can show all caps code, but how to do it?

23 minutes ago, auriny said:

but how to do it?

you need a custom Network packet which you send when the capability data changes on server, and in PlayerLoggedInEvent, PlayerEvent.PlayerRespawnEvent and PlayerEvent.PlayerChangedDimensionEvent

  • Author
1 minute ago, Luis_ST said:

you need a custom Network packet which you send when the capability data changes on server, and in PlayerLoggedInEvent, PlayerEvent.PlayerRespawnEvent and PlayerEvent.PlayerChangedDimensionEvent

oh, thanks, please wait

  • Author
7 minutes ago, Luis_ST said:

you need a custom Network packet which you send when the capability data changes on server, and in PlayerLoggedInEvent, PlayerEvent.PlayerRespawnEvent and PlayerEvent.PlayerChangedDimensionEvent

like... this?
i has that event before you said, it was used for ether regeneration

 

@Mod.EventBusSubscriber(modid = CoSRPG.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class TickEvent {
    public static int tick;
    @SubscribeEvent
    public void tickServer(TickEvent.ServerTickEvent evt) {
        if(evt.phase == TickEvent.Phase.END) {
            tick ++;
            if(tick > 100000) tick = 0;
        }
    }

    @SubscribeEvent
    public static void playerTick(TickEvent.PlayerTickEvent event){
        if(event.phase == TickEvent.Phase.START){
            Ether ether = event.player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
            ether.regen(event.player);
        }
    }

    @SubscribeEvent
    public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getEther());
    }

    @SubscribeEvent
    public void onChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getMaxEther()-ether.getEther());
    }

    @SubscribeEvent
    public void onLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getEther());
    }
}

 

  • Author
4 minutes ago, auriny said:

like... this?
i has that event before you said, it was used for ether regeneration

 

@Mod.EventBusSubscriber(modid = CoSRPG.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class TickEvent {
    public static int tick;
    @SubscribeEvent
    public void tickServer(TickEvent.ServerTickEvent evt) {
        if(evt.phase == TickEvent.Phase.END) {
            tick ++;
            if(tick > 100000) tick = 0;
        }
    }

    @SubscribeEvent
    public static void playerTick(TickEvent.PlayerTickEvent event){
        if(event.phase == TickEvent.Phase.START){
            Ether ether = event.player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
            ether.regen(event.player);
        }
    }

    @SubscribeEvent
    public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getEther());
    }

    @SubscribeEvent
    public void onChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getMaxEther()-ether.getEther());
    }

    @SubscribeEvent
    public void onLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
        Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance());
        ether.fill(event.getPlayer(), ether.getEther());
    }
}

 

well, this didn't work

  • Author

hah, and this value is out of sync with the test item when i use it. ether is regens, but if i try to use an item and if i completely deplete all the ether, it will still be equal to what i put + time for regen

 

should i send all capability code?

Edited by auriny

1 hour ago, Luis_ST said:

you need a custom Network packet

did you read the link? the code you use has nothing to do with Networking

Edit: show the Ether class (the implementation of your Capability interface)

Edited by Luis_ST

  • Author
1 hour ago, loordgek said:

if you use @Mod.EventBusSubscriber your event methods must be static

ok thx

 

1 hour ago, Luis_ST said:

did you read the link? the code you use has nothing to do with Networking

this code is located in PacketEther class, that registries in NetworkRegistry class

    private static int packetId = 0;
    public static SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(CoSRPG.MOD_ID,
            "main"), () -> "1.0", s -> true, s -> true);

    private static int nextID() {
        return packetId++;
    }

    public static void init() {
        INSTANCE.registerMessage(nextID(), PacketEtherBar.class, PacketEtherBar::toBytes, PacketEtherBar::new, PacketEtherBar::handle);
    }

 

1 hour ago, Luis_ST said:

Edit: show the Ether class (the implementation of your Capability interface)

public class Ether {
    private int tickDelay = 4;
    private float max = 100;
    private float ether;

    public Ether() {
        this(200);
    }
    
    public Ether(float chargeLevel) {
        ether = chargeLevel;
    }

    public float getEther() {
        return ether;
    }

    public void consume(PlayerEntity player, float points) {
        set(getEther() - points);
        sendPacket(player);
    }

    public void fill(PlayerEntity player, float points) {
        float a = getEther();
        set(a + points);

        if (a != getEther())
            sendPacket(player);
    }

    public void regen(PlayerEntity player) {
        if (player.world.getGameTime() % tickDelay == 0)
            fill(player, 1);
    }

    public void set(float points) {
        ether = MathHelper.clamp(points, 0, getMaxEther());
    }


    public float getMaxEther() {
        return max;
    }

    public void setMaxEther(float max) {
        this.max = max;
    }

    public int getRegenDelay() {
        return tickDelay;
    }

    public void setRegenDelay(int delay) {
        tickDelay = delay;
    }

    private void sendPacket(PlayerEntity player) {
        if (!(player instanceof FakePlayer) && player instanceof ServerPlayerEntity)
            NetworkingRegistry.INSTANCE.sendToServer(new PacketEtherBar(this));
    }


    public static class EtherStorage implements Capability.IStorage<Ether> { // implementation of Capability
        @Override
        public INBT writeNBT(Capability<Ether> capability, Ether instance, Direction side) {
            return FloatNBT.valueOf(instance.ether);
        }

        @Override
        public void readNBT(Capability<Ether> capability, Ether instance, Direction side, INBT nbt) {
            float ether = 0;
            if (nbt.getType() == FloatNBT.TYPE) {
                ether = ((FloatNBT) nbt).getFloat();
            }
            instance.set(ether);
        }
    }

    public static Ether createADefaultInstance() {
        return new Ether();
    }
}

 

5 minutes ago, auriny said:
NetworkingRegistry.INSTANCE.sendToServer(new PacketEtherBar(this));

you need to send a Packeet to the client

  • Author
45 minutes ago, Luis_ST said:

you need to send a Packeet to the client

like this?  NetworkingRegistry.INSTANCE.send(PacketDistributor.ALL.noArg(), new PacketEtherBar(this));

Edited by auriny

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.