Jump to content

Recommended Posts

Posted

Hi,

 

I am wondering how you do a loot table for your custom structure. I have tried looking through the Minecraft code and I have not found anything that helps me.

 

Any help would be appreciated, and thanks in advance.

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted (edited)

After the chest in your structure is generated you need to get it tile entity using world.getTileEntity (you must know it position). Then you call it to TileEntityChest and at the final you need to use methods setLootTable and fillWithLoot.
Hope this will help you a bit, greetings!

Edited by Krevik
Posted

Only problem is, exactly how would I find the location of the chest?

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted (edited)

It depends on how are you generating your structure. If it's done using .nbt file (structure block) then you have to personally count blocks from the structure start to chest pos.
Or less efficient way: you can make loop in loop in loop to check to check every block in your structure if it's chest block like:
 

for(int x=0;x<=structure.getSize().getX();x++){
	for(int y=0;y<=structure.getSize().getY();y++){
		for(int z=0;z<=structure.getSize().getZ();z++){
			BlockPos tmp = new BlockPos(structurePosIn.getX()+x,structurePosIn.getY()+y,structurePosIn.getZ()+z){
				if(world.getTileEntity(tmp)!=null){
					if(world.getTileEntity(tmp) instanceof TileEntityChest){
						TileEntityChest chest = (TileEntityChest)world.getTileEntity(tmp);
						//fill this chest with loot 
					}
				}
			}
		}
	}
}

But this is not recommended to use this cause you're adding unnecessary math. Better to personally check where's the chest pos.

Edited by Krevik
Posted

For chest.fillWithLoot, what would you put as the "player" parameter?

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted

null

  • Haha 1

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 (edited)

Wait, it should be pretty easy. This is your own custom structure, right. So you're the one that places the chest block. The StructureComponent class has a generateChest() method that takes in a loot table parameter.

 

Or you can simply force the placement with something like:

                            worldIn.setBlockState(blockpos2, Blocks.CHEST.correctFacing(worldIn, blockpos, Blocks.CHEST.getDefaultState()), 2);
                            TileEntity tileentity1 = worldIn.getTileEntity(blockpos);

                            if (tileentity1 instanceof TileEntityChest)
                            {
                                ((TileEntityChest)tileentity1).setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, rand.nextLong());
                            }

  Of course you would adjust the loot to suit your needs.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

It said null and when I opened the chest it had nothing. It has given me no errors, no anything. I even used a custom loot table generator and it didn't work. Please help!!!

 

Here's my code:

public static void generateStructure(World world, BlockPos pos) {
		
		MinecraftServer mcServer = world.getMinecraftServer();
		TemplateManager manager = worldServer.getStructureTemplateManager();
		ResourceLocation location = new ResourceLocation(Reference.MOD_ID, structureName);
		Template template = manager.get(mcServer, location);
		
		if(template != null) {
			
			IBlockState state = world.getBlockState(pos);
			world.notifyBlockUpdate(pos, state, state, 3);
			template.addBlocksToWorldChunk(world, pos, settings);
			for(int x = 0; x <= template.getSize().getX(); x++) {
				
				for(int y = 0; y <= template.getSize().getY(); y++) {
					
					for(int z = 0; z <= template.getSize().getZ(); z++){
						
						BlockPos tmp = new BlockPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
							
						if(world.getTileEntity(tmp) != null){
							
							if(world.getTileEntity(tmp) instanceof TileEntityChest){
								
								TileEntityChest chest = (TileEntityChest) world.getTileEntity(tmp);
								chest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest.json"), new Random(chest.getWorld().getSeed()).nextLong());
								chest.fillWithLoot(null);
							}
						}
					}
				}
			}
		}
	}

 

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted (edited)

OK, so I got NBTExplorer to look at the hub.nbt and it said the chest was located at x 2, y 1, and z 3. So I created a BlockPos of pos.getX() + 2, pos.getY() + 1, pos.getZ() + 3 (see above post for the pos variable). Here is my code:

IBlockState state = world.getBlockState(pos);
			world.notifyBlockUpdate(pos, state, state, 3);
			template.addBlocksToWorldChunk(world, pos, settings);
			BlockPos chestPos = new BlockPos(pos.getX() + 2, pos.getY() + 1, pos.getZ() + 3);
			TileEntity tileentity = world.getTileEntity(chestPos);
			
			if(tileentity == null) {
				
				Main.logger.info("There is no chest!!! Run away!!!");
				return;
			}
			
			if(tileentity instanceof TileEntityChest) {
				
				TileEntityChest tileEntityChest = (TileEntityChest) tileentity;
				tileEntityChest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest.json"), new Random(world.getSeed()).nextLong());
				tileEntityChest.fillWithLoot(null);
			}

When I run the game, it says "There is no chest!!! Run away!!!" repeatedly. I don't know what's wrong.

 

And by the way, I tried running the loop in loop in loop code and it didn't work. I clearly have the loot table correctly named, as you can see in the attached image.

 

Yes, there is a chest in there. To prove it, I the second screenshot clearly shows a minecraft:chest in there.

 

Please help, and thank you in advance.

screenshot.JPG

screenshot2.JPG

Edited by lyghtningwither

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted (edited)
  On 5/19/2018 at 5:06 PM, lyghtningwither said:

It said null and when I opened the chest it had nothing. It has given me no errors, no anything. I even used a custom loot table generator and it didn't work. Please help!!!

 

Here's my code:

public static void generateStructure(World world, BlockPos pos) {
		
		MinecraftServer mcServer = world.getMinecraftServer();
		TemplateManager manager = worldServer.getStructureTemplateManager();
		ResourceLocation location = new ResourceLocation(Reference.MOD_ID, structureName);
		Template template = manager.get(mcServer, location);
		
		if(template != null) {
			
			IBlockState state = world.getBlockState(pos);
			world.notifyBlockUpdate(pos, state, state, 3);
			template.addBlocksToWorldChunk(world, pos, settings);
			for(int x = 0; x <= template.getSize().getX(); x++) {
				
				for(int y = 0; y <= template.getSize().getY(); y++) {
					
					for(int z = 0; z <= template.getSize().getZ(); z++){
						
						BlockPos tmp = new BlockPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
							
						if(world.getTileEntity(tmp) != null){
							
							if(world.getTileEntity(tmp) instanceof TileEntityChest){
								
								TileEntityChest chest = (TileEntityChest) world.getTileEntity(tmp);
								chest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest.json"), new Random(chest.getWorld().getSeed()).nextLong());
								chest.fillWithLoot(null);
							}
						}
					}
				}
			}
		}
	}

 

Expand  

 

I don't think the fillWithLoot(null) is really the right thing to do there. Vanilla generation just does the code I said -- sets the loot table. I think the fill with loot would happen later (probably when player actually opens the chest).

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)

How would this work? Would I use the event bus? If so, then what event would you use? Or would the chest automatically do it when you open it?

Edited by lyghtningwither

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Posted
  On 5/20/2018 at 12:21 AM, lyghtningwither said:

How would this work? Would I use the event bus? If so, then what event would you use? Or would the chest automatically do it when you open it?

Expand  

Putting loot can be also done without custom loot table. Do you must have loot table?

Posted (edited)
  On 5/19/2018 at 6:33 PM, lyghtningwither said:

OK, so I got NBTExplorer to look at the hub.nbt and it said the chest was located at x 2, y 1, and z 3. So I created a BlockPos of pos.getX() + 2, pos.getY() + 1, pos.getZ() + 3 (see above post for the pos variable). Here is my code:

IBlockState state = world.getBlockState(pos);
			world.notifyBlockUpdate(pos, state, state, 3);
			template.addBlocksToWorldChunk(world, pos, settings);
			BlockPos chestPos = new BlockPos(pos.getX() + 2, pos.getY() + 1, pos.getZ() + 3);
			TileEntity tileentity = world.getTileEntity(chestPos);
			
			if(tileentity == null) {
				
				Main.logger.info("There is no chest!!! Run away!!!");
				return;
			}
			
			if(tileentity instanceof TileEntityChest) {
				
				TileEntityChest tileEntityChest = (TileEntityChest) tileentity;
				tileEntityChest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest.json"), new Random(world.getSeed()).nextLong());
				tileEntityChest.fillWithLoot(null);
			}

When I run the game, it says "There is no chest!!! Run away!!!" repeatedly. I don't know what's wrong.

 

And by the way, I tried running the loop in loop in loop code and it didn't work. I clearly have the loot table correctly named, as you can see in the attached image.

 

Yes, there is a chest in there. To prove it, I the second screenshot clearly shows a minecraft:chest in there.

 

Please help, and thank you in advance.

screenshot.JPG

screenshot2.JPG

Expand  

Also about resource location:
 

				tileEntityChest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest.json"), new Random(world.getSeed()).nextLong());

shouldn't it be :
 

tileEntityChest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":chests/hub_chest"), new Random(world.getSeed()).nextLong());

?
or just

tileEntityChest.setLootTable(new ResourceLocation(Reference.MOD_ID + ":hub_chest"), new Random(world.getSeed()).nextLong());

 

Edited by Krevik

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • UPDATE: this seems to be an Arch-specific issue. Switching to Ubuntu server fixed EVERYTHING.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
  • Topics

×
×
  • Create New...

Important Information

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