Jump to content

[1.14.4] Custom Vanilla Block Drops


SimplyCmd

Recommended Posts

I know a lot of people have posted about this topic, but I can not find a forum to support my needs. Keep in mind that I do not have much Java skills, so please explain things as much as possible.

 

I want to add a custom block drop to oak leaves (an acorn). After a couple hours of work, I've ended up with this:

package com.github.n_slash_a.terracraftia;

import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import static com.github.n_slash_a.terracraftia.init.ModItems.ACORN;
import static net.minecraft.block.Blocks.*;

@Mod.EventBusSubscriber
public class LeavesDropEvent {
    @SubscribeEvent
    public void HarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
        if ((event.getState().getBlock() == OAK_LEAVES)) {
            event.getDrops().clear();
            event.getDrops().add(new ItemStack(ACORN, 1));
        }
    }
}

However, while testing, I encountered a problem: Blocks do not drop anything at all! Is this a problem with forge, or something with my mod?

 

Any advice is appreciated. Thanks!

Edited by SimplyCmd
Updating Title
Link to comment
Share on other sites

20 minutes ago, SimplyCmd said:

Is this a problem with forge, or something with my mod?

HarvestDropeEvent is not implemented yet because of design reasons you can just create a loot table json and override the vanilla one. If you just want to add to the vanilla one use the LootTableLoadEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Step 1: create a new loot table json for the block you want to modify (and named with the name of the block).

Step 2: if you want to override completely, place this file in data/minecraft/loot_tables/blocks. If you want to add to, place it in data/<modid>/loot_tables/blocks

Step 3: if you want to override completely, you're done. Otherwise, subscribe to the LootTableLoadEvent:

@SubscribeEvent
public static void onLootLoad(LootTableLoadEvent event) {
    if (event.getName().equals(new ResourceLocation("minecraft",the_block_to_modify))) {
       event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(modid,filename))).build());
    }
}

 

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

 

it does not work when I open a box there is not my item in side

 

simple_dungeon.json

{
  "type": "minecraft:chest",
  "pools": [
    {
      "rolls": {
        "min": 1,
        "max": 9
      },
      "bonus_rolls": {
        "min": 0,
        "max": 2
      },
      "entries": [
        {
          "type": "item",
          "name": "element:magicessence",
          "weight": 50,
          "functions": [
            {
              "function": "set_data",
              "data": 0
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 3
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.301
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:darkessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 1
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.331
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:electrikessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 2
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.332
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:fireessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 3
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.33399999999999996
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:iceessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 4
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.335
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:lifeessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 5
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.335
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:poisonessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 6
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.335
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:wateressense",
          "weight": 40,
          "functions": [
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.335
                }
              ]
            }
          ]
        },
        {
          "type": "item",
          "name": "element:windessense",
          "weight": 40,
          "functions": [
            {
              "function": "set_data",
              "data": 0
            },
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              },
              "conditions": [
                {
                  "condition": "random_chance",
                  "chance": 0.335
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

 

Edited by DevTech
Link to comment
Share on other sites

6 hours ago, Draco18s said:

Step 1: create a new loot table json for the block you want to modify (and named with the name of the block).

Step 2: if you want to override completely, place this file in data/minecraft/loot_tables/blocks. If you want to add to, place it in data/<modid>/loot_tables/blocks

Step 3: if you want to override completely, you're done. Otherwise, subscribe to the LootTableLoadEvent:


@SubscribeEvent
public static void onLootLoad(LootTableLoadEvent event) {
    if (event.getName().equals(new ResourceLocation("minecraft",the_block_to_modify))) {
       event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(modid,filename))).build());
    }
}

 

Thank you so much!

Link to comment
Share on other sites

  • 11 months later...
On 10/8/2019 at 7:33 AM, Draco18s said:

Step 1: create a new loot table json for the block you want to modify (and named with the name of the block).

Step 2: if you want to override completely, place this file in data/minecraft/loot_tables/blocks. If you want to add to, place it in data/<modid>/loot_tables/blocks

Step 3: if you want to override completely, you're done. Otherwise, subscribe to the LootTableLoadEvent:


@SubscribeEvent
public static void onLootLoad(LootTableLoadEvent event) {
    if (event.getName().equals(new ResourceLocation("minecraft",the_block_to_modify))) {
       event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(modid,filename))).build());
    }
}

 

So If i'm trying to change desert_pyramid chest loot, what do I call my loot table json? Would it be desert_pyramid_chest.json? Also, what would i put in "the block to modify" and "filename" above?

Link to comment
Share on other sites

Dear lord this topic is woefully out of date.

 

To modify loot tables, use GlobalLootModifiers

https://mcforge.readthedocs.io/en/1.15.x/items/globallootmodifiers/

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

  • 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.