Jump to content

Recommended Posts

Posted

So I got a list of block positions that I iterate through. They are locations of chests to put random items in.

 

[embed=425,349]public List<BlockPos> chestGeneric = new ArrayList<BlockPos>();[/embed]

 

I use this method to go to each chest and put some items in (I'm using paper just to test).

 

[embed=425,349]

public void fillChests()

{

  World world = Minecraft.getMinecraft().theWorld;

  System.out.println("Filling chests...");

  Random rand = new Random();

  for (Iterator<BlockPos> iter = chestGeneric.iterator(); iter.hasNext();)

  {

    BlockPos position = iter.next();

    TileEntityChest chest = (TileEntityChest)world.getTileEntity(position);

    System.out.println("> Looking for chest...");

    if (chest.getBlockType() == Blocks.chest)

    {

      System.out.println(">> chest at x: " + position.getX() + " y: " + position.getY() + " z: " + position.getZ());

      for (int i = 0; i < 5; i++)

      {

        System.out.println(">>> Setting slot: " + i);

        chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), new ItemStack(Items.paper, 5));

      }

      world.markBlockForUpdate(position);

    }

  }

  System.out.println("Chests filled.");

}

[/embed]

 

This runs when I do a command and the log outputs this with no errors:

 

[embed=425,349]

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:41]: Filling chests...

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:47]: > Looking for chest...

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:50]: >> chest at x: -71 y: 87 z: 257

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 0

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 1

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 2

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 3

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 4

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:47]: > Looking for chest...

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:50]: >> chest at x: -66 y: 87 z: 257

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 0

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 1

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 2

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 3

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:53]: >>> Setting slot: 4

[17:05:01] [server thread/INFO] [sTDOUT]: [wendrom.quarry.Room:fillChests:59]: Chests filled.

[/embed]

 

But in game when I look in the chests, there are no items found and I don't know why.

 

Any ideas?

Posted

World world = Minecraft.getMinecraft().theWorld;

 

That's the client-side world.  The server is undoing all of your changes.

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.

Posted

Thank you very much! It works exactly as I need it to now.

 

I just changed

[embed=425,349]World world = Minecraft.getMinecraft().theWorld;[/embed]

to

[embed=425,349]World world = MinecraftServer.getServer().worldServers[0];[/embed]

Posted

That code's only going to work in the overworld. Dimension/WorldServer 0 is the overworld, so be forewarned, it won't work in the nether/end/any other dimension.

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Posted

Where do you call fillChests()?

 

Depending on where it's called, you either have a World object or something which holds one (entity, tileentity, chunk, world generator etc.).

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.

Announcements



×
×
  • Create New...

Important Information

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