Jump to content

CustomNPCs [1.11.2] scripting a Chest


Aropretim

Recommended Posts

I really like the scripting possibilities of this mod, but I'm missing something like a "Scripted Chest" or at least a "setContainer(int size)" method for the "Scripted Block". I was trying to script a workaround with a chest nearby, but I failed because of not knowing how to show the chest's GUI or to create a high dynamic dialog.

 

function interact(event) {
  var container = event.block.world.getBlock(event.block.getX(), event.block.getY()-1, event.block.getZ()).getContainer();
  var tempDialog = new IDialog(); // <--  This don't work - need something similar
  var dialogText = "Content:";
  for (i=0; i<container.getSize(); i++) {
    if(container.getSlot(i) && container.getSlot(i).getName() != "minecraft:air") {
      dialogText += container.getSlot(i).getDisplayName() + " x" + container.getSlot(i).getStackSize();
    }
  }
  tempDialog.setText(dialogText);
  
  // setting DialogOptions here to get some or all items
  
  event.player.showDialog(tempDialog);
}

 

The final idea behind this is to put player dependent content in chests. For example a Player who has finished Quest 1 can find a wooden sword, wood coins or leather armor in a chest, while another player, who has finished Quest 27 can find diamond equipment inside the same chest.

 

Another reason for wanting a Scripted Chest is to want locked chests. I made a working (un)locking script for "Scripted Doors" and it would be really nice, if I could use a similar one for chests too.


Has anyone a solution?

 

 

Edit:

It seems I think too complicated. Two simple lines like these...

var containerBlock = event.target.getWorld().getBlock(event.target.getX(), event.target.getY()-1, event.target.getZ());
PlayerEvent.InteractEvent(event.player, event.type, containerBlock);

... should let me directly interact with the chest, isn't it? Unfortunatly neither PlayerEvent nor InteractEvent are defined. Has anyone another idea?

Edited by Aropretim
Link to comment
Share on other sites

Current state of progress:

I was trying to find another way to "copy" the container-property from the chest to the scripted block, but I didn't find a way to get access to these datas, except the getContainer()-function.

I was also trying to have a look inside the IBlockScripted.class file to check if I were able to add a setContainer()-function myself, but I only found hexcode inside. That's so confusing to me... O.o

 

I tried the best myself. Maybe someone else has an idea.

 

Edit:

I've got a spontaneous suggestion. Instead of scripting chest for the content I could write a playerscript to put progress-dependent content into the chest and put a scripted block nearby to store some data. I didn't test it already but theoretically it should work. It would just explode the playerscript if you have hundrets of chests and want every chest to have individual content (weapons in a bakery chest makes as less sense as bread in a bank's safe). I'll post the code if I'll be successful.

Edited by Aropretim
Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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