Jump to content

Kalma

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by Kalma

  1. hahahahaha! I am not sure if this is what you really need as draco18s estated. I mean, blockDestroy is server-side, so you should change most of the code you posted since it is definitely client-side. Besides that, you can not input "false/true"! You have to call the function using "false" (no drops) or true (drop items)... I would recommend you follow diesieben7 suggestion, and take a look to "Minecraft#sendClickBlockToController for the client-side part."
  2. I would suggest you try with Block#destroyBlock, instead of Block#harvestBlock: player.world.getBlockState(new BlockPos(x, y, z)) .getBlock(). .destroyBlock(player, false/true); or you can also use Block#spawnDrops whenever needed.
  3. HAHAHAHA! Well... I learned a lot on the way! So, I should stick to the "old" method, right? public class onLootTableLoadListener { @SubscribeEvent public void LootTablesLoad(final LootTableLoadEvent event) { String prefix = "minecraft:chests/"; String name = event.getName().toString(); // Test: /loot give @p loot minecraft:chests/pillager_outpost if (name.startsWith(prefix)) { event.getTable().addPool(LootPool.builder() .addEntry(TableLootEntry.builder(new ResourceLocation(Refs.MODID, "chests/lazy_builder")) .weight(1)) .bonusRolls(0, 1) .name(Refs.MODID) .build() ); } } } Thank you anyway!
  4. Hi again! I have been searching and testing a lot. I think I have everything in place (global_loot_modifier.json file, my custom .json file, the class which extends LootModifier class, and the registry stuff). What I still don't get to know is how to add my custom items to the vanilla chests. I guess it is something related to the "conditions" or "type" part of my custom loot_modifier.json, right? I have tried to find out the right option, and I think it can be related to "table_bonus" (though inside the class seems to be related to enchantments) or "reference"... but I am not able to find the "predicate" or whatever is needed to "hook" my items to the chests loot ... Am I missing anything? My global_loot_modifier.json: { "replace": false, "entries": [ "lazybuilder:chests_lazy_builder" ] } My custom loot_modifier.json { "type": "lazybuilder:chests_lazy_builder", "conditions": [ { "condition": "WHAT SHOULD GO HERE???: e.g. reference???", "name":"AND HERE?: e.g. minecraft:chests???" } ], "items": [ { "item": "lazybuilder:start_block", "weight": 20 }, { "item": "lazybuilder:mid_block", "weight": 30 }, { "item": "lazybuilder:end_block", "weight": 20 }, { "item": "lazybuilder:copy_paste_block", "weight": 10 } ] } My LootModifier class public class ChestLootModifier extends LootModifier { @SuppressWarnings("unused") private static final Logger LOGGER = LogManager.getLogger(); private final List<Item> itemToAdd; private final List<Integer> weights; private final String addTo = "minecraft:chests"; ILootCondition[] conditions; public ChestLootModifier(ILootCondition[] conditionsIn, List<Item> itemLoot, List<Integer> itemWeights) { super(conditionsIn); itemToAdd = itemLoot; weights = itemWeights; } @Nonnull @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { if (false) { // How do I hook to chests loot to add my stuff??? for (int i = 0; i < itemToAdd.size() && i < weights.size(); ++i) { int randValue = new Random().nextInt(101); int count = 0; if (randValue <= weights.get(i)) { count = 1; } generatedLoot.add(new ItemStack(itemToAdd.get(i), count)); } } return generatedLoot; } public static class Serializer extends GlobalLootModifierSerializer<ChestLootModifier> { @Override public ChestLootModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) { List<Item> blockStack = new ArrayList<Item>(); List<Integer> weightList = new ArrayList<Integer>(); for (JsonElement item : JSONUtils.getJsonArray(object, "items")) { blockStack.add(ForgeRegistries.ITEMS.getValue(new ResourceLocation(JSONUtils.getString(item.getAsJsonObject(), "item")))); weightList.add(JSONUtils.getInt(item.getAsJsonObject(), "weight")); } return new ChestLootModifier(conditionsIn, blockStack, weightList); } @Override public JsonObject write(ChestLootModifier instance) { // TODO Auto-generated method stub return null; } } }
  5. Understood. Much clear to me now. Thanks a lot!!! (I had to port my mod to 1.16.3 from 1.14.4 since my last question regarding this very same issue... it is worth anyway).
  6. Still not totally clear, sorry, but I think I have a point to start on. I will make some additional tests to try to figure out the solution or make the questions better ! Thanks again!
  7. Thanks again! I see... may be you mean here? @Nonnull @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { // // Additional conditions can be checked, though as much as possible should be parameterized via JSON data. // It is better to write a new ILootCondition implementation than to do things here. // int numSeeds = 0; for(ItemStack stack : generatedLoot) { if(stack.getItem() == itemToCheck) numSeeds+=stack.getCount(); } if(numSeeds >= numSeedsToConvert) { generatedLoot.removeIf(x -> x.getItem() == itemToCheck); generatedLoot.add(new ItemStack(itemReward, (numSeeds/numSeedsToConvert))); numSeeds = numSeeds%numSeedsToConvert; if(numSeeds > 0) generatedLoot.add(new ItemStack(itemToCheck, numSeeds)); } return generatedLoot; } If so, where can I find some info about how to use all this stuff, specially adding or injecting custom loots into existing ones? There isn't anything similar I can search in vanilla classes as far as I know (if there is, sorry, I couldn't find it)
  8. Thx for your reply! I guess you mean here: { "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "item": "minecraft:shears" } }, { "condition": "block_state_property", "block":"minecraft:wheat" } ], "seedItem": "minecraft:wheat_seeds", "numSeeds": 3, "replacement": "minecraft:wheat" } I can see there is a "replacement" part which might be the key part (right?), but I don't want to replace it, I would like to add custom items to the vanilla chests loots without replacing it.
  9. Hi Sinhika! Thanks a lot for taking the time to make this very useful tutorial (https://dragoness-e.dreamwidth.org/136561.html), there isn't much practical info you can find besides that!!! What it is not clear to me is how to inject custom loot pools into existing vanilla chests tables using this method. Did you find out how to, or you have any "pointer" I can follow? I am working on 1.16.3 version now. Thx again!
  10. Sorry to reopen this thread... and sorry again because I forgot something crucial in my previous post: I am using Forge 1.14.4. I finally got the time to attempt this other method, but my IDE (Eclipse) is not able to find LootModifier class (nor even trying to import it from here: net.minecraftforge.common.loot.LootModifier) In addition to that, I am not sure how to inject my custom pools to the existing chests loot_tables using this method. The documentation here: https://mcforge.readthedocs.io/en/1.14.x/items/globallootmodifiers/#global-loot-modifiers. explains how to create independent loot_tables, but not how to inject them... anyone knows where to investigate more in detail? Thx!!!
  11. Totally different approach... I will give it a try (will need some extra-time though). Thanks for your prompt reply!!!
  12. Hi there! I'm trying to inject my own loot tables within the vanilla chests ones, so there is a chance that a player can find one of those items and blocks. I am doing that in two separate mods. The weird thing is: if I run each mod separately, the loot_tables work fine, and you can find the items or blocks in vanilla chests. But if I run the game with both mods, the common loot tables fail! (in one of the mods I inject my own table in all chests tables, while in the other mod I just inject the tables on some specific chests tables... it is in those tables "common" which fails when running both at the same time!). Totally lost here (it would be easier if it ALWAYS fail!). Here is my event handler: public class onLooTableLoadListener { @SubscribeEvent public void onLootTablesLoad(final LootTableLoadEvent event) { // Test: /loot give @p loot minecraft:chests/end_city_treasure if (event.getName().equals(new ResourceLocation("minecraft", "chests/buried_treasure")) || event.getName().equals(new ResourceLocation("minecraft", "chests/underwater_ruin_big")) || event.getName().equals(new ResourceLocation("minecraft", "chests/pillager_outpost")) || event.getName().equals(new ResourceLocation("minecraft", "chests/end_city_treasure")) || event.getName().equals(new ResourceLocation("minecraft", "chests/stronghold_library")) ) { event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(MODID, "chests/time_sword"))).build()); } } } The handler on the other mod: public class onLooTableLoadListener { @SubscribeEvent public void onLootTablesLoad(final LootTableLoadEvent event) { String prefix = "minecraft:chests/"; String name = event.getName().toString(); if (name.startsWith(prefix)) { event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(Refs.MODID, "chests/lazy_builder"))).build()); } } } The loot table .json file (I have tried many many different combinations, adding and removing fields... they all with the same result): { "pools": [{ "rolls": 1, "entries": [ { "type": "item", "name": "simpleclock:time_sword", "weight": 50, "functions": [ { "function": "minecraft:set_count", "count": { "min": 1.0, "max": 1.0, "type": "minecraft:uniform" } } ] } ] }] } And the second loot table .json file { "pools": [{ "rolls": 1, "entries": [ { "type": "minecraft:item", "name": "lazybuilder:start_block", "weight": 30, "functions": [ { "function": "minecraft:set_count", "count": { "min": 1.0, "max": 1.0, "type": "minecraft:uniform" } } ] }, { "type": "minecraft:item", "name": "lazybuilder:mid_block", "weight": 30, "functions": [ { "function": "minecraft:set_count", "count": { "min": 1.0, "max": 1.0, "type": "minecraft:uniform" } } ] }, { "type": "minecraft:item", "name": "lazybuilder:end_block", "weight": 30, "functions": [ { "function": "minecraft:set_count", "count": { "min": 1.0, "max": 1.0, "type": "minecraft:uniform" } } ] }, { "type": "minecraft:item", "name": "lazybuilder:copy_paste_block", "weight": 10, "functions": [ { "function": "minecraft:set_count", "count": { "min": 1.0, "max": 1.0, "type": "minecraft:uniform" } } ] } ] }] }
×
×
  • Create New...

Important Information

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