Solved Replacing vanilla Container

Discussion in 'Plugin Development' started by mncat77, Apr 9, 2013.

Thread Status:
Not open for further replies.
  1. Does anyone know how to reaplace the normal NMS containers with custom ones? I have already seen ways to do this with blocks, but I have no idea how to do this with containers. Anyone an idea?
     
  2. Offline

    Cybermaxke

    What kind of container do you want to replace?
    Block containers are pretty easy to change.
     
  3. I want to replace ContainerAnvil with a custom one. Only way I found is overriding this (which I don't want to do):

    https://github.com/Bukkit/CraftBukk...a/net/minecraft/server/EntityPlayer.java#L483
    https://github.com/Bukkit/CraftBukk.../minecraft/server/PlayerConnection.java#L1555

    Edit:
    Also replacing loaded classes is a really cheaty option I wan't to avoid if possible any other way, which there should be, right?
     
  4. Offline

    Cybermaxke

    You only need to change the block and container.
    For example this was the code I used to open my new enchanting table container:
    Code:
    public class BlockEnchantmentTable extends net.minecraft.server.v1_5_R2.BlockEnchantmentTable {
     
        public BlockEnchantmentTable(int i) {
            super(i);
            this.c(5.0F);
            this.b(2000.0F);
            this.c("enchantmentTable");
        }
     
        public boolean interact(World paramWorld, int paramInt1, int paramInt2, int paramInt3, EntityHuman paramEntityHuman, int paramInt4, float paramFloat1, float paramFloat2, float paramFloat3) {
            if (paramWorld.isStatic) {
                return true;
            }
     
            TileEntityEnchantTable t = (TileEntityEnchantTable) paramWorld.getTileEntity(paramInt1, paramInt2, paramInt3);
            this.startEnchanting((EntityPlayer) paramEntityHuman, paramInt1, paramInt2, paramInt3, t.b() ? t.a() : null);
            return true;
        }
     
        public void startEnchanting(EntityPlayer p, int i, int j, int k, String name) {
            Container container = new ContainerEnchantTable(p.inventory, p.world, i, j, k);
     
            int c = p.nextContainerCounter();
            p.playerConnection.sendPacket(new Packet100OpenWindow(c, 4, name == null ? "" : name, 9, name != null));
            p.activeContainer = container;
            p.activeContainer.windowId = c;
            p.activeContainer.addSlotListener(p);
        }
    }
     
    mncat77 likes this.
  5. Offline

    Cybermaxke

    I just use jd-gui to look into the code.
     
Thread Status:
Not open for further replies.

Share This Page