Jump to content
  • Home
  • Files
  • Docs
Status Updates
  • All Content

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Tomlabete

Tomlabete

Members
 View Profile  See their activity
  • Content Count

    9
  • Joined

    September 13, 2017
  • Last visited

    September 23, 2017

Community Reputation

0 Neutral

About Tomlabete

  • Rank
    Tree Puncher

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    I think this can help me, but after a deep look in all the related threads, I can't figure out how exactly can I attach my capability data to the stack NBT. When I try this on the server, I am disconnected with an error on the server console as soon as I take a key/lock in my hand : @Override public NBTTagCompound getNBTShareTag(ItemStack stack) { stack.getTagCompound().setInteger("keyCode", stack.getCapability(KeyCode.Provider.KEY_CODE_CAP, null).get()); return stack.getTagCompound(); } The error :
    • September 21, 2017
    • 11 replies
  2. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    Well, I did it all and this is not working. Packet is sent and received, the code is transmitted from server to client, but I can't find a way to update the ItemStack. It seems that it's overwritten by the server without taking the capability into account. The code of the key/lock is always 0 (default) on the client. On the server it can be anything, but as soon as I open Creative inventory, all codes are reset... I tried to change the quantity and the item type of the stack but nothing is happening, I guess the client hasn't any right to tell which ItemStack is in the inventory of the player. Any idea for me ? (I found this thread on a same topic, unsolved yet...)
    • September 19, 2017
    • 11 replies
  3. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    Thank you very much, that's definitly going to help me
    • September 19, 2017
    • 11 replies
  4. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    That's true, I don't use initCapabilities at all, I'm going to try this, but will data be transmitted from the server to the client and then back to the server with only this ? Here is the gitHub folder where you can find the capability (KeyCode), its interface (IKeyCode) and the Item class (McfrCodedItem). https://github.com/Mc-Fr/Forge/tree/master/Forge1.10/src/main/java/net/mcfr/mecanisms/keys Here is the event handler that I need to delete and replace by usage of initCapabilities (doing this tomorrow). https://github.com/Mc-Fr/Forge/blob/master/Forge1.10/src/main/java/net/mcfr/event/ItemEventsHandler.java
    • September 17, 2017
    • 11 replies
  5. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    Does anyone has an idea that might help me ?
    • September 17, 2017
    • 11 replies
  6. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete replied to Tomlabete's topic in Modder Support

    Ok, np. Here is my Item class, keys and locks are instances of it. public class McfrCodedItem extends McfrItem { public McfrCodedItem(String name, CreativeTabs tab) { super(name, 1, tab); setHasSubtypes(true); } @Override public String getUnlocalizedName(ItemStack stack) { return getUnlocalizedName() + "." + (stack.getMetadata() == 0 ? "blank" : "coded"); } @Override @SideOnly(Side.CLIENT) public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) { subItems.add(new ItemStack(itemIn, 1, 0)); // metadata = 0 --> Blank key/lock, unusable subItems.add(new ItemStack(itemIn, 1, 1)); // metadata = 1 --> Coded key/lock, usable } public void setCode(EntityPlayer player, int code) { ItemStack stack = new ItemStack(player.getHeldItemMainhand().getItem(), 1, 1); // replace item in hand with coded item if (stack.hasCapability(KeyCode.Provider.KEY_CODE_CAP, null)) { IKeyCode keyCode = stack.getCapability(KeyCode.Provider.KEY_CODE_CAP, null); keyCode.set(code); } player.setHeldItem(EnumHand.MAIN_HAND, stack); } @SideOnly(Side.SERVER) public Optional<Integer> getCode(EntityPlayer player) { ItemStack stack = player.getHeldItemMainhand(); if (stack.getMetadata() == 1 && stack.hasCapability(KeyCode.Provider.KEY_CODE_CAP, null)) // Check if item is coded return Optional.of(stack.getCapability(KeyCode.Provider.KEY_CODE_CAP, null).get()); //Optional.of(code) if coded else return Optional.empty(); //Optional.empty() if blank } } The setCode(player, code) and getCode(player) methods are called from my Sponge plugin. I would like to sync client-item-capabilities with server-item-capabilities whenever setCode is called. Here is my capability class. Provider and Storage are static classes inside it. public class KeyCode implements IKeyCode { private int code = 0; @Override public int get() { return this.code; } @Override public void set(int code) { this.code = code; } public static class Storage implements IStorage<IKeyCode> { @Override public NBTBase writeNBT(Capability<IKeyCode> capability, IKeyCode instance, EnumFacing side) { NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("keyCode", instance.get()); return tag; } @Override public void readNBT(Capability<IKeyCode> capability, IKeyCode instance, EnumFacing side, NBTBase nbt) { NBTTagCompound tag = (NBTTagCompound) nbt; instance.set(tag.getInteger("keyCode")); } } public static class Provider implements ICapabilitySerializable<NBTBase> { @CapabilityInject(IKeyCode.class) public static final Capability<IKeyCode> KEY_CODE_CAP = null; private IKeyCode instance = KEY_CODE_CAP.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == KEY_CODE_CAP; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == KEY_CODE_CAP ? KEY_CODE_CAP.<T>cast(this.instance) : null; } @Override public NBTBase serializeNBT() { return KEY_CODE_CAP.getStorage().writeNBT(KEY_CODE_CAP, this.instance, null); } @Override public void deserializeNBT(NBTBase nbt) { KEY_CODE_CAP.getStorage().readNBT(KEY_CODE_CAP, this.instance, null, nbt); } } } Handling of the attachCapabilities event : public class ItemEventsHandler { public static final ResourceLocation KEY_CODE_CAP = new ResourceLocation(Constants.MOD_ID, "keyCode"); @SubscribeEvent public void onAttachEntityCapabilities(AttachCapabilitiesEvent<Item> event) { if (event.getObject() instanceof McfrCodedItem) { event.addCapability(KEY_CODE_CAP, new KeyCode.Provider()); } } } And finally, the line in my Init method, in main class : CapabilityManager.INSTANCE.register(IKeyCode.class, new KeyCode.Storage(), KeyCode.class); Hope this helps
    • September 15, 2017
    • 11 replies
  7. Tomlabete

    [1.10.2] Capabilities unsynced when opening Creative inventory

    Tomlabete posted a topic in Modder Support

    Hello ! I'm on a keys&locks mod that works pairwise with a sponge plugin (not relevant here, though, just remember that it's mainly serversided mecanics). My items have a code-capability that stores a key-code in them that is checked whenever a player tries to open a closed chest/door/trapdoor. Everything works perfectly well with survival inventories : the plugin sends codes to the server-side items, they keep it and re-send it when asked by the plugin. But the problem occurs with Creative inventory : as soon as a Creative inventory is opened, all keys and locks contained in it are reset to a code "0". It happens because the client-side capability is never updated and stays at zero. My question is : what is the best way for me to send the code from the server to the client when code is configured ? I'm not good at all with packages. I guess it will be about it, so if you guys could give me some tutorial links with a quick explanation of what I should do in my particular case, I would be really grateful Thanks, have a nive day !
    • September 15, 2017
    • 11 replies
  • All Activity
  • Home
  • Tomlabete
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community