Posted November 16, 20168 yr Hey, i was updating from 1.8 with IEEP to 1.10 with Capabilities, but everything I've done seem to add a copy of my mana, an un usable version of it. I ran a debug system print of the mana value, it rejuvenates as you would expect it too over time, but a ghost value renders over my mana bar and not the value that keeps changing when i right click the item The ghost value rejuvenates as well but it gets to 10, like the bar is supposed too but wont go down when i use the item, the main value does go down when i use it though, its like when i right click the item, the value gets used, then the ghost value is dominate as the bar rending code uses that value instead. [spoiler=Item code] @Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { final IEssenceBar bar1 = player.getCapability(BarTickHandler.ESSENCE_CAP, null); if(!world.isRemote && bar1.useBar(usage)) { //ENTITY SPAWN CODE } } [spoiler=Bar tick code] public class BarTickHandler { private EntityPlayer player; private int ticks = 10; public static int darkAmount, powerAmount; @CapabilityInject(IEssenceBar.class) public static Capability<IEssenceBar> ESSENCE_CAP = null; @SubscribeEvent public void onEntityConstructing(AttachCapabilitiesEvent evt) { evt.addCapability(new ResourceLocation(SlayerAPI.MOD_ID, "IEssenceBar"), new ICapabilitySerializable<NBTPrimitive>() { IEssenceBar inst = ESSENCE_CAP.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == ESSENCE_CAP; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == ESSENCE_CAP ? ESSENCE_CAP.<T>cast(inst) : null; } @Override public NBTPrimitive serializeNBT() { return (NBTPrimitive)ESSENCE_CAP.getStorage().writeNBT(ESSENCE_CAP, inst, null); } @Override public void deserializeNBT(NBTPrimitive nbt) { ESSENCE_CAP.getStorage().readNBT(ESSENCE_CAP, inst, null, nbt); } }); } @SubscribeEvent public void onTick(PlayerTickEvent event) { if(event.phase == Phase.END) tickEnd(event.player); } @SubscribeEvent @SideOnly(Side.CLIENT) public void renderEvent(RenderTickEvent event) { onTickRender(Minecraft.getMinecraft().thePlayer); } @SideOnly(Side.CLIENT) private void onTickRender(EntityPlayer player) { Minecraft mc = Minecraft.getMinecraft(); if(mc.currentScreen == null) { if(!player.capabilities.isCreativeMode) { GL11.glPushMatrix(); GlStateManager.enableBlend(); GlStateManager.enableAlpha(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GuiIngame gig = mc.ingameGUI; ScaledResolution scaledresolution = new ScaledResolution(mc); mc.getTextureManager().bindTexture(new ResourceLocation(SlayerAPI.MOD_ID, "textures/gui/misc.png")); int y = scaledresolution.getScaledHeight() - 30, x = 10, x1 = 10, x2 = 10; gig.drawTexturedModalRect(x - 10, y + 10, 0, 177, 117, 19); gig.drawTexturedModalRect(x - 10, y - 5, 0, 177, 117, 19); gig.drawTexturedModalRect(x - 10, y - 20, 0, 177, 117, 19); gig.drawTexturedModalRect(x - 6, y - 13, 0, 23, 109, 5); for(int i = 0; i < player.getCapability(ESSENCE_CAP, null).getBarValue(); i++) { x += 11; gig.drawTexturedModalRect(x - 17, y - 13, 0, 0, 10, 5); } y += 15; gig.drawTexturedModalRect(x1 - 6, y - 13, 0, 36, 109, 5); for(int i = 0; i < darkAmount; i++) { x1 += 11; gig.drawTexturedModalRect(x1 - 17, y - 13, 0, 5, 10, 5); } gig.drawTexturedModalRect(x2 - 6, y + 2, 0, 49, 109, 5); for(int i = 0; i < powerAmount; i++) { x2 += 11; gig.drawTexturedModalRect(x2 - 17, y + 2, 0, 10, 10, 5); } GlStateManager.disableAlpha(); GlStateManager.disableBlend(); GL11.glPopMatrix(); } } } private void tickEnd(EntityPlayer player) { final IEssenceBar essence = player.getCapability(ESSENCE_CAP, null); if(ticks-- <= 0) ticks = 20; if(ticks >= 20) { essence.updateAllBars(); } essence.mainUpdate(); } } [spoiler=Capability registry in common proxy] CapabilityManager.INSTANCE.register(IEssenceBar.class, new EssenceStorage(), EssenceBar.class); [spoiler=IEssenceBar] public interface IEssenceBar { boolean useBar(int mana); int getBarValue(); void mainUpdate(); void setBarValue(int mana); void removeBarPoints(int mana); void updateAllBars(); } [spoiler=EssenceBar] @Override public boolean useBar(int amount) { if(essence < amount) { regenDelay = 10; return false; } essence -= amount; regenDelay = 10; return true; } @Override public int getBarValue() { return essence; } @Override public void mainUpdate() { if(getBarValue() >= 10) essence = 10; System.out.println(essence); } @Override public void setBarValue(int mana) { essence = mana; } @Override public void removeBarPoints(int mana) { regenDelay = 10; essence -= mana; } @Override public void updateAllBars() { essence += 1; } } [spoiler=EssenceStorage] public class EssenceStorage implements Capability.IStorage<IEssenceBar>{ @Override public NBTBase writeNBT(Capability<IEssenceBar> capability, IEssenceBar instance, EnumFacing side) { return new NBTTagByte((byte)0); } @Override public void readNBT(Capability<IEssenceBar> capability, IEssenceBar instance, EnumFacing side, NBTBase nbt) { } } Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 16, 20168 yr Capabilities aren't automatically synced, do you ever sync the mana value from the server to the client? Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 16, 20168 yr Author do you mean the read/write NBTBase method? Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 16, 20168 yr do you mean the read/write NBTBase method? That is "save to disk" not "send packets" it's right there in the name. "Packets." Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 16, 20168 yr Author Ive really not had much to do with Packets Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 16, 20168 yr They're super easy. http://mcforge.readthedocs.io/en/latest/networking/ Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 22, 20168 yr Author [spoiler=Journey] public static SimpleNetworkWrapper wrapper; @EventHandler public static void preInit(FMLPreInitializationEvent event) { wrapper = NetworkRegistry.INSTANCE.newSimpleChannel("EssenceNetwork"); wrapper.registerMessage(MessageEssenceBar.EssenceHandler.class, MessageEssenceBar.class, 0, Side.CLIENT); } [spoiler=common/client proxy] public void updateEssence(int amount) { } ------------------------------------------------------------------- @Override public void updateEssence(int amount) { final IEssenceBar essence = Minecraft.getMinecraft().thePlayer.getCapability(BarTickHandler.ESSENCE_CAP, null); essence.setBarValue(amount); } [spoiler=MessageEssenceBar] public class MessageEssenceBar implements IMessage { public int amount; public boolean shouldRegen; public MessageEssenceBar() { } public MessageEssenceBar(int amount, boolean shouldRegen) { this.amount = amount; this.shouldRegen = shouldRegen; } @Override public void fromBytes(ByteBuf buf) { amount = buf.readInt(); shouldRegen = buf.readBoolean(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(amount); buf.writeBoolean(shouldRegen); } public static class EssenceHandler implements IMessageHandler<MessageEssenceBar, IMessage> { @Override public IMessage onMessage(MessageEssenceBar message, MessageContext ctx) { BarTickHandler.essenceAmount = message.amount; BarTickHandler.regenEssence = message.shouldRegen; Journey.proxy.updateEssence(message.amount); return null; } } } Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 22, 20168 yr Author Also should state that that code changes things, the bar rendering starts to spazz, changes from rendering the ghost value to the normal value every tick Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 22, 20168 yr Looks like you've made some progress which is good. Do you have your project on a public repo? (GitHub, Bitbucket) I'd be happy to assist the best I can, if you like you can have a look at my capability system https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master packages are named in meaningful ways Was those 3 posted blocks of code you're only changes? or have you updated your bar tick code since then? Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
November 22, 20168 yr Author Here is the github Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 22, 20168 yr I've noticed in your Essence class you use Journey.wrapper.sendToAll() just curious if you mean to do that. Because you register your Capability on "Everything" not just players. But I don't see any "generic" entity tick so it rules out the fact that a random mob could be "sending" it's data to everyone. However that sendToAll() will cause issues because you use your clientProxy to "handle" the data by getting the minecraft.thePlayer which If player 1 ticked and updated, server sends data to all, player 2 now thinks "player 1s" stats are his (then player 2 gets ticked, and server updates all players again player 1 now thinks player 2's stats are his) if you make sure in the player tick event you can just use Journey.wrapper.sendTo(message,(EntityPlayerMP) player); and it will send it to the correct player rather than all players. I'm still digging through some of your code. Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
November 22, 20168 yr Author The thing is i dont have a instance to EntityPlayer in the Essence class, i could make a constructor in the class getting one, but i dont create an instance for the Essence class either, its constructed from the default instance method, and even if i wanted to change that, where i register my class in the BarTickHandler i dont have a player instance either so thats another problem, i could use Minecraft.getMinecraft().thePlayer but thats a SP instance and i want MP Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 22, 20168 yr Update some of your methods that "send a packet" to include a EntityPlayer param, and in your PlayerTick events you can get the player from there if (!player.worldObj.isRemote) essence.mainUpdate(player); ^^^ Journey.wrapper.sendTo(new MessageEssenceBar(essence, regenDelay == 0),(EntityPlayerMP)player); or you can just declare an Entity obj in the Essence class and give your provider a constructor or have it call capability.entity = event.entity then in main updates you just check to see if the entities worldObj is not remote (server) and sendTo from there. Since I can't physically see the ghosting or debug and step through (I might just do a pull and run it personally soon enough) to see what it really could be. EDIT: looks like you have a Console.out somewhere sending out the values which is nice, as I can see numbers flying all over. If I can locate that spot I can try having the console also pump out hopefully any other helpful information. Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
November 22, 20168 yr Author I think its fixed now, i added a player parameter to the methods and seemed to fix it all if(player instanceof EntityPlayerMP) Journey.wrapper.sendTo(new MessageEssenceBar(essence, regenDelay == 0), (EntityPlayerMP)player); also did that, thanks! Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
November 22, 20168 yr Welcome, if anything else creeps up let us know. Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
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.