Jump to content

How to generate a explorer map that points to a village in code?


bossmania

Recommended Posts

Hi, I'm new to modding and to this forum, and I'm trying to get an item that gives the player an explorer map that points to a village. I was able to do this with a loot table, but I was only able to get the loot table to run when a block is broken.  Is there a way to have a loot table to run in code, or is there a different way to create an explorer map that points to a village?

Link to comment
Share on other sites

20 hours ago, Luis_ST said:

you could overwrite a vanilla Loot Table or you could create a recipe (needs a CustomRecipe) 

I was able to get a recipe loot table to generate an explorer map, but the problem with this method is that I want the explorer maps to also point to structures in all three dimensions, and I can't prevent the player from crafting the map in the wrong dimension.

Link to comment
Share on other sites

1 hour ago, bossmania said:

Can you elaborate more on that, and give an example of it?

I wonder how Blocks (being harvested) calls loot to be dropped. It's gotta call some code somewhere...

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

Knowing for a fact that it exists, and that it calls ForgeHooks.modifyLoot(...), I'm going to tell you to look harder.

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

Ok, so after doing some digging into the Block class, I have found out that it uses this function to run a loot table.

public static List<ItemStack> getDrops(BlockState state, ServerWorld worldIn, BlockPos pos, @Nullable TileEntity tileEntityIn, @Nullable Entity entityIn, ItemStack stack) {
	      LootContext.Builder lootcontext$builder = (new LootContext.Builder(worldIn)).withRandom(worldIn.rand).withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(pos)).withParameter(LootParameters.TOOL, stack).withNullableParameter(LootParameters.THIS_ENTITY, entityIn).withNullableParameter(LootParameters.BLOCK_ENTITY, tileEntityIn);
	      return state.getDrops(lootcontext$builder);
	}

 

But, how do I get a ServerWorld to pass into the function? I have tried passing "(ServerWorld)World", like how the Block class did it, but it crashes the game. This is the error message.

The game crashed whilst unexpected error
Error: java.lang.ClassCastException: net.minecraft.client.world.ClientWorld cannot be cast to net.minecraft.world.server.ServerWorld
Exit Code: -1
Link to comment
Share on other sites

If you're not on the server, do nothing. The client has no say here.

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

Through the magic of network packets.

That said, I don't see why you'd need it here.

Edited by Draco18s

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

11 hours ago, bossmania said:

So then, how else do I get a loot table to run in the code?

My point was, you don't make random items on the client, you only do it on the server. If you are not on the server, do nothing, if you ARE on the server, do what D7 said.

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

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.