bossmania Posted November 8, 2021 Posted November 8, 2021 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? Quote
Luis_ST Posted November 8, 2021 Posted November 8, 2021 you could overwrite a vanilla Loot Table or you could create a recipe (needs a CustomRecipe) Quote
bossmania Posted November 9, 2021 Author Posted November 9, 2021 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. Quote
bossmania Posted November 9, 2021 Author Posted November 9, 2021 16 hours ago, diesieben07 said: You can look at what the loot tables do in code. In this case ExplorationMapFunction. To get loot from a loot table use LootTable#getRandomItems. Can you elaborate more on that, and give an example of it? Quote
Draco18s Posted November 9, 2021 Posted November 9, 2021 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... Quote 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.
bossmania Posted November 9, 2021 Author Posted November 9, 2021 11 hours ago, Draco18s said: I wonder how Blocks (being harvested) calls loot to be dropped. It's gotta call some code somewhere... So I tried to look for how Blocks call the loot table, but I was not able to find it. Can you provide how it calls the loot table? Quote
Draco18s Posted November 9, 2021 Posted November 9, 2021 Knowing for a fact that it exists, and that it calls ForgeHooks.modifyLoot(...), I'm going to tell you to look harder. Quote 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.
bossmania Posted November 10, 2021 Author Posted November 10, 2021 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 Quote
Luis_ST Posted November 10, 2021 Posted November 10, 2021 you need to check if the World is an instance of ServerWorld first the you can cast the World like vanilla Quote
bossmania Posted November 11, 2021 Author Posted November 11, 2021 18 hours ago, Luis_ST said: you need to check if the World is an instance of ServerWorld first the you can cast the World like vanilla How do I check it? And if it's not an instance of ServerWorld, then how do I get the ServerWorld? Quote
Draco18s Posted November 11, 2021 Posted November 11, 2021 If you're not on the server, do nothing. The client has no say here. Quote 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.
bossmania Posted November 12, 2021 Author Posted November 12, 2021 18 hours ago, Draco18s said: If you're not on the server, do nothing. The client has no say here. So how do I access the server, and send the ServerWorld to the client? Quote
Draco18s Posted November 12, 2021 Posted November 12, 2021 (edited) Through the magic of network packets. That said, I don't see why you'd need it here. Edited November 12, 2021 by Draco18s Quote 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.
bossmania Posted November 12, 2021 Author Posted November 12, 2021 2 hours ago, Draco18s said: Through the magic of network packets. That said, I don't see why you'd need it here. So then, how else do I get a loot table to run in the code? Quote
Draco18s Posted November 12, 2021 Posted November 12, 2021 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. Quote 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.
Recommended Posts
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.