Jump to content

Can't add dungeon items with ChestGenHooks


telinc1

Recommended Posts

My problem is pretty simple. Seeing as the item methods in DungeonHooks are deprecated, that means that they will be eventually removed, so I want to port to ChestGenHooks, but I'm having trouble.

 

This is my current method:

    public static void addDungeonItems() {
        ChestGenHooks chestGenHooksDungeon = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
        
        // Mega Adamant Blocks in dungeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.megaAdamant), 55, 1, 3));

        // Tomatoes and Peppers in dugeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.tomato), 95, 3, 4));
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.pepper), 95, 3, 4));

        // Adamant in dungeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.adamant), 30, 3, 5));
    }

Using this, the game crashes when it generates a dungeon. Crash report

 

I also found that I can use this (bold part is what's changed from previous method):

    public static void addDungeonItems() {
        ChestGenHooks chestGenHooksDungeon = new ChestGenHooks(ChestGenHooks.DUNGEON_CHEST); // Changed line, note from OP
        
        // Mega Adamant Blocks in dungeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.megaAdamant), 55, 1, 3));

        // Tomatoes and Peppers in dugeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.tomato), 95, 3, 4));
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.pepper), 95, 3, 4));

        // Adamant in dungeons
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(TelicraftMain.adamant), 30, 3, 5));
    }

Using this, the game doesn't crash but no items get generated. Can somebody explain to me how to use ChestGenHooks? Thanks in advance!

 

-Telinc1

Link to comment
Share on other sites

If you'd actually look into what you're doing you'll understand why the 2nd is wrong. OFC it wont use your NEW instance -.- You have to add it to the one you're looking for.

 

Also If you look at the construtor for WeightedRandomChestContent:

new WeightedRandomChestContent(new ItemStack(TelicraftMain.megaAdamant), 55, 1, 3)
    public WeightedRandomChestContent(ItemStack par1ItemStack, int par2, int par3, int par4)
    {
        super(par4);
        this.theItemId = par1ItemStack;
        this.theMinimumChanceToGenerateItem = par2;
        this.theMaximumChanceToGenerateItem = par3;
    }

Essentially you're saying you want the minimum amount to be 55, the max amount to be 1 .....

Thats kinda retarded....

Check your arguments.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

  • 1 month later...

Hello,

 

I'd like to add dragon eggs to dungeon and mineshaft chests. However, I'm not sure if I get the Wight Number right. In dungeons it should have the same probability as saddles, and in mineshafts the same probability as gold ingots. The stack should always consist of 1 dragon egg.

 

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;

public class ChestLoot {

public static void addChestItems() {
	ChestGenHooks chestGenHooksDungeon = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);       
        chestGenHooksDungeon.addItem(new WeightedRandomChestContent(new ItemStack(Block.dragonEgg), 1, 1, 100));

        ChestGenHooks chestGenHooksMineshaft = ChestGenHooks.getInfo(ChestGenHooks.MINESHAFT_CORRIDOR);       
        chestGenHooksMineshaft.addItem(new WeightedRandomChestContent(new ItemStack(Block.dragonEgg), 1, 1, 5));        
    }

}

 

Is this alright?

 

Regards,

Thaliviel

Link to comment
Share on other sites

  • 1 month later...

I don't know if that will work, but I use this method in the @Init method in my base class, and it works perfectly:

ChestGenHooks.getInfo(ChestGenHooks.chestType).addItem(new WeightedRandomChestContent(new ItemStack(yourItem), rarity, min, max));

The italics are arguments, explained here:

chestType: what type of chest will it spawn in? The full list of chest types is in the ChestGenHooks class, in net.minecraftforge.common. You can use dungeon chests, bonus chests, temple chests, etc.

yourItem: Your item.

rarity: rarity of the item, 1 is rarest, and bread is 100, so very common. but you can go over 100(or over 9,000, for that matter)

min: minimum amount of the item spawned in that specific stack.

max: maximum amount of the item spawned in that specific stack.

 

Hope that this was helpful to both you, and others with the same problem, because I had that problem...

Link to comment
Share on other sites

I don't know if that will work, but I use this method in the @Init method in my base class, and it works perfectly:

ChestGenHooks.getInfo(ChestGenHooks.chestType).addItem(new WeightedRandomChestContent(new ItemStack(yourItem), rarity, min, max));

The italics are arguments, explained here:

chestType: what type of chest will it spawn in? The full list of chest types is in the ChestGenHooks class, in net.minecraftforge.common. You can use dungeon chests, bonus chests, temple chests, etc.

yourItem: Your item.

rarity: rarity of the item, 1 is rarest, and bread is 100, so very common. but you can go over 100(or over 9,000, for that matter)

min: minimum amount of the item spawned in that specific stack.

max: maximum amount of the item spawned in that specific stack.

 

Hope that this was helpful to both you, and others with the same problem, because I had that problem...

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.