Jump to content

Making a vanilla block drop a second item


TheCrudNation

Recommended Posts

I found something on another post from Forge 1.11.2 

@SubscribeEvent
	public void yourPlayerHarvestEvent(HarvestDropsEvent event) {
		if (event.getHarvester() != null) {
			
			if (event.getState() == Blocks.QUARTZ_ORE.getDefaultState()) {
				event.setDropChance(0.1f);
				event.getDrops().add(new ItemStack(ItemRegistry.herkimer_diamond, 1));
			}
			
		}
	}

Has it really changed that much in so little versions or is there a simpler way of doing it?

Link to comment
Share on other sites

  

Just now, TheCrudNation said:

HarvestDropsEvent event

Doesn't exist any more. Has been replaced by Global Loot Modifiers

 

If you don't want to use them then do it this way:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderfarming/EventHandlers.java#L49-L53

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/resources/data/harderfarming/loot_tables/blocks/grass.json

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

I'm quite new to java, how does one make sure the event is fired? I created a class called EventHandler inside of my handlers package and it contains literally just this.


@EventBusSubscriber
public class EventHandler {

}

so anything I put in here will be fired?

Link to comment
Share on other sites

1 minute ago, TheCrudNation said:

So I don't need to reference my EventHandler class anywhere else?

As long as it's got the EventBusSubscriber annotation and the event handler methods are static, and have the SubscribeEvent annotation, you should be good to go.

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

Can you stop recommending this crappy way to people?

Sure can.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Here is the latest logs  https://paste.ee/p/ad9H6
    • I test with other forge version and this work
    • Also add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • Hi, I'm trying to add a chance for the LootTableIdCondition. I've tried to manipulate the AddItemModifier class, but it still doesn't work: public class AddItemModifier extends LootModifier { public static final Supplier<Codec<AddItemModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst).and(ForgeRegistries.ITEMS.getCodec() .fieldOf("item").forGetter(m -> m.item)) .and(Codec.FLOAT.fieldOf("chance").forGetter(m -> m.chance)) .apply(inst, AddItemModifier::new))); private final Item item; public AddItemModifier(LootItemCondition[] conditionsIn, Item item) { super(conditionsIn); this.item = item; } @Override protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) { if(context.getRandom().nextFloat() < chance) { generatedLoot.add(new ItemStack(this.item)); } for(LootItemCondition condition : this.conditions) { if(!condition.test(context)) { return generatedLoot; } } generatedLoot.add(new ItemStack(this.item)); return generatedLoot; } @Override public Codec<? extends IGlobalLootModifier> codec() { return CODEC.get(); } } the only problem is the two "chance" are not defined, but when I add a private final Float chance, the AddItemModifier::new is in red underline, and there's an error. Is there a way to solve this, or is there another better way to add a chance to chest loot modifiers?
  • Topics

×
×
  • Create New...

Important Information

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