Anvil Casting

Discussion in 'Plugin Help/Development/Requests' started by Gamerdude157, Dec 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Gamerdude157

    Hey guys for my plugin I need to open Anvil Inventories and i don't want to go into extending classes or anything so i though of a smart solution. I'm going to place an anvil in my world, and when i need to open a GUI i'll open that anvils inventory. But what would I cast the block state to? There is no option for anvils. What should I do!
     
  2. Offline

    CullanP

  3. Offline

    Gamerdude157

    But how would I get that anvil inventory i would need to cast it to the blockstate or what CullanP or anyone else?
     
  4. Offline

    CullanP

    Get the players inventory and cast it to AnvilInventory - Use variables
     
  5. Offline

    Skionz

    CullanP Pretty sure you can't cast an AnvilInventory to Inventory.
     
  6. Offline

    Darkpicasa

    I'm not sure to do this, however, search up the source code for the plugin MobileTools.
    I believe they have anvil support.
    You can see how they did it, and learn from them :)

    They seem to have used net.minecraft.server.v1_7_R3.ContainerAnvil;


    public void openAnvil() {
    AnvilContainer container = new AnvilContainer(this.handle);
    int c = this.handle.nextContainerCounter();
    this.handle.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, 8, "Repairing", 9, true));
    this.handle.activeContainer = container;
    this.handle.activeContainer.windowId = c;
    this.handle.activeContainer.addSlotListener(this.handle);
    }

    https://github.com/Cybermaxke/MobileTools/tree/master/src/main/java/me/cybermaxke/mobiletools
     
  7. Offline

    Rocoty

    Skionz Of course you can. An AnvilInventory is always an Inventory, so it will be cashable to Inventory in all cases (although explicitly casting it to Inventory would be completely redundant). I think what you meant to say - given the context - is that you can't cast a PlayerInventory reference to AnvilInventory. And that is true in all cases.
     
    Skionz likes this.
  8. Offline

    Gamerdude157

    But I've tried casting with
    AnvilInventory i = (AnvilInventory) Bukkit.createInventory(null,InventoryType.ANVIL);
    And I get a ClassCastException that AnvilInventory can not be cast CraftInventoryCustom
     
  9. Offline

    Gamerdude157

  10. Offline

    Experminator

    Gamerdude157 First of all, Don't bump.
    And You can't direct casting to a Anvil. I won't work.

    Find a different way.

    Darkpicasa A suggestion: Use the "[ code] [ /code]" tag for all your code. It is a bit easier to read.

    <Edit by mrCookieSlime: Merged posts.>
     
  11. Offline

    Gamerdude157

    While we talk about rules, Experminator I dont double post :p use edits. And also If I knew a way to open the anvil Why am I here? Bt I'm using the new Craftbukkit 1.8 code (Thank you TheCodingCat for telling us) so the PacketOpenWindow is different now and so is the container anvil so its hard does anyone now a little more about nms so i can open the anvil? Cause mineplex virtual anvil opens fine.
     
  12. Offline

    Experminator

    Gamerdude157 First of all, I see two "Bump" messages.

    And second i want to say: Sorry, i'm a noob at Craftbukkit 1.8 code. (I will learn it.)
     
  13. Offline

    mrCookieSlime

    Moved to Alternatives Section and removed fast bump.

    Gamerdude157
    Please dont bump within 24 hours.
     
  14. Offline

    Gamerdude157

    Ok guys so I used this code but i got this image....
    Code:java
    1. public class AnvilContainer extends ContainerAnvil {
    2.  
    3. private AnvilContainer(EntityHuman entityHuman) {
    4. super(entityHuman.inventory, entityHuman.world, new BlockPosition(93,1,114), entityHuman);
    5. }
    6. @Override
    7. public boolean a(EntityHuman entityHuman) {
    8. return true;
    9. }
    10. @SuppressWarnings("deprecation")
    11. public static void openAnvil(Player pl) {
    12. EntityPlayer entityPlayer = ((CraftPlayer)pl).getHandle();
    13. pl.closeInventory();
    14. AnvilContainer fakeAnvil = new AnvilContainer(entityPlayer);
    15. int containerId = entityPlayer.nextContainerCounter();
    16. entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, "Repairing Man", ChatSerializer.a("{\"text\":\"" + "Name your Pet\"}"),8,0));
    17. entityPlayer.activeContainer = fakeAnvil;
    18. entityPlayer.activeContainer.windowId = containerId;
    19. entityPlayer.activeContainer.addSlotListener(entityPlayer);
    20. pl.updateInventory();
    21. }
    22. }

    no errors or anything just my inventory gets messed up and it looks like my inventory with the title "Inventory" and then on top of that title there is another title that says "Name your Pet" Its like a glitch or something?
     
  15. Offline

    Skionz

  16. Offline

    Gamerdude157

  17. Offline

    Skionz

    Gamerdude157 Upload to web host, press the image icon, enter the url.
     
  18. Offline

    Gamerdude157

    [​IMG]
    Got the image Skionz what do you think is wrong
    EDIT: Forgot to tag you :p

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  19. Offline

    Gamerdude157

    OMG SOLVED I found it! But wait new question. What method is called by the server to drop the items in the anvil container? Because when i close the container, any items inside of the anvil end up in my inventory. What method is it called? Thanks
     
Thread Status:
Not open for further replies.

Share This Page