Jump to content

Remove TileEntity and the Item in Slot


themaw

Recommended Posts

Is there an optimization method if I want to have a large scale removal?

private void clean(EntityPlayer theplayer,World world){
		int start = 500;
		//start is the range of clean
		int x = theplayer.serverPosX-start;

		int y = theplayer.serverPosY-128;

		int z = theplayer.serverPosZ-start;

		int count = 0;

		for(int i1 = 0;i1<start*2;i1++){

			for(int i2 = 0;i2<300;i2++){

				for(int i3 = 0;i3<start*2;i3++){

					TileEntity tile = world.getTileEntity(x+i1, y+i2, z+i3);

					if(tile!=null){

						System.out.println(tile.toString());

						world.removeTileEntity(x+i1, y+i2, z+i3);

						++count;

					}

				}

			}

		}

		System.out.println("Clean "+count+" TileEntities By Player "+theplayer.getDisplayName());

	}

 

Edited by themaw
Link to comment
Share on other sites

Remove tile entity does not do what you want, in any way, shape, or form.

 

You want to remove an item from a tile entity's inventory? Use getCapability() to get its inventory and remove the item from the IItemStackHandler instance.

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.

Link to comment
Share on other sites

2 hours ago, Draco18s said:

Remove tile entity does not do what you want, in any way, shape, or form.

 

You want to remove an item from a tile entity's inventory? Use getCapability() to get its inventory and remove the item from the IItemStackHandler instance.

Thank you so much!:D:D:D

Because of you, I finally implemented a tool today to remove TileEntity from a region.

I successfully made a tool for the player's archive to eliminate the wrong TileEntity.

Although I didn't use getCapability(), I just remembered that I didn't transform TileEntity into IInventory.

Here is my void code:

	private void cleantileentity(EntityPlayer theplayer, World world) {

		

		int start = info.tileentitycleanrange;

		int x = theplayer.serverPosX-start;

		int y = theplayer.serverPosY-128;

		int z = theplayer.serverPosZ-start;

		int count = 0;

		for(int i1 = 0;i1<start*2;i1++){

			for(int i2 = 0;i2<300;i2++){

				for(int i3 = 0;i3<start*2;i3++){

					TileEntity tile = world.getTileEntity(x+i1, y+i2, z+i3);

					if(tile!=null){

						if(tile instanceof IInventory){

							IInventory tile2 = (IInventory)tile;

							for(int i4=0;i4<tile2.getSizeInventory();i4++){

								if(tile2.getStackInSlot(i4)!=null){

									tile2.setInventorySlotContents(i4, null);

								}

							}

						System.out.println("Remove TileEntity with item in "+tile.toString()+"x:"+(x+i1)+" y:"+(y+i2)+" z:"+(z+i3));

						}

						world.removeTileEntity(x+i1, y+i2, z+i3);

						System.out.println("Remove TileEntity in "+tile.toString()+"x:"+(x+i1)+" y:"+(y+i2)+" z:"+(z+i3));

						++count;

					}

				}

			}

		}

		System.out.println("Clean "+count+" TileEntites By Player "+theplayer.getDisplayName());

	}

 

Link to comment
Share on other sites

IInventory is only for vanilla containers. That won't work with mods.

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.

Link to comment
Share on other sites

On 16-2-2018 at 9:33 AM, Draco18s said:

IInventory is only for vanilla containers. That won't work with mods.

nope he is on 1.7.10

 

and WHY remove the tileEntity that could end up badly because the other mod still thinks there is a tile on that block

Edited by loordgek
Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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