Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Forge hooks for Structure loot.


Recommended Posts

I've looked at the Forge hooks for Dungeon loot, and would like something like it for the various other map generated loot chests. Yes there are a lot of them. Basically I want to add items from Forge mods to chests, which is easy without Forge until Bukkit is involved.

 

The idea I have is to modify StructureComponent.class so the StructurePieceTreasure[] part is removed/ignored, and a class parameter used instead to determine what set of loot to generate (eg ComponentStrongholdLibrary.class). This way when Mojang add yet another structure with chest loots in it, the API doesn't need yet more changes.

 

I don't mind doing most/all of the code changes, just want to hear what others think of the implementation. Also should I go with 1.2.5 or is it likely to be a wasted effort ?

Link to post
Share on other sites

Dont make anything for 1.2.5 anymore. As as soon as major mods update, nobody will use 1.2.5 anymore

As for the the Structure loot, I have planned for a while to expand this to any world gen chest loot, but that is a future feature, we are currently in the 'fix bugs' stage of Forge, not the 'Add new things'

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Patreon: http://www.patreon.com/lexmanos
Paypal: http://paypal.me/LexManos

BitCoin: 1Q8rWvUNMM2T1ZfDaFeeYQyVXtYoeT6tTn

Link to post
Share on other sites

I've added a few lines of code to StructureComponent so it can determine its called class, eg: ComponentMineshaftCorridor.class and use that name to store each set of loot. This way any structure created gets its own unique loot set, even ones added by modders. Still need to write a data structure to store it all, then look at the pull request.

 

StructureComponent.class contains:

func_74879_a

Loot chests

 

func_74869_a

Dispensers

 

So I might at well tap into the Dispenser code, so mean people can put fire arrows in them or something.

Link to post
Share on other sites
  • 5 weeks later...
  • 3 weeks later...

Got enchanted dungeon loot thanks to the recent changes in Forge (4.2.x)

Thanks for that LexManos!

I had to brush up on sub-classes and such to get it going but I'll put what I found here (if that's ok)

 

The override class:

 

 

package net.minecraft.src;

import net.minecraft.client.Minecraft;

import net.minecraftforge.common.DungeonHooks;

import net.minecraftforge.common.DungeonHooks.DungeonLoot;

import net.minecraft.src.EnchantmentHelper;

import net.minecraft.src.EnchantmentData;

import java.util.*;

 

public class enchantedLoot extends DungeonHooks.DungeonLoot

{

        private ItemStack itemStack;

        private int minCount = 1;

        private int maxCount = 1;

        private int minEnchantLevel = 1;

        private int maxEnchantLevel = 1;

        private int enchantChance = 0;

 

public enchantedLoot(ItemStack item, int weight, int min, int max, int ench)

{

super(weight, item, 1, 1);

this.itemStack = item;

minEnchantLevel = min;

maxEnchantLevel = max;

if (max < min)

{

maxEnchantLevel = min;

}

enchantChance = ench;

 

// Enchantable items should never be stackable

minCount = 1;

maxCount = 1;

}

 

public ItemStack generateStack(Random rand)

{

ItemStack ret = this.itemStack.copy();

 

ret.stackSize = minCount + (rand.nextInt(maxCount - minCount + 1));

if (enchantChance > 0)

{

int i = rand.nextInt(100);

if (i < enchantChance)

{

int level = minEnchantLevel + (rand.nextInt(maxEnchantLevel - minEnchantLevel + 1));

ret.stackSize = 1;

List list = EnchantmentHelper.buildEnchantmentList(rand, ret, level);

if(list != null)

{

EnchantmentData enchantmentdata;

for(Iterator iterator = list.iterator(); iterator.hasNext(); ret.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel))

{

enchantmentdata = (EnchantmentData)iterator.next();

}

}

}

}

            return ret;

        }

}

 

 

 

Then to reference it, add a method to your code:

 

 

private void addEnchantedLoot(ItemStack item, int weight, int min, int max, int ench)

{

DungeonHooks newLoot = new DungeonHooks();

newLoot.addDungeonLoot((DungeonHooks.DungeonLoot)new enchantedLoot(item, weight, min, max, ench));

}

 

 

 

Then if you want to add, for instance, randomly enchanted bows, you could use:

addEnchantedLoot(new ItemStack(Item.bow),100, 1,30, 10);

where 100 is the weight (chance it will be in loot)

1 is the minimum enchantment level

30 is the maximum enchantment level

10 is the percent chance the item will have any enchantment

Link to post
Share on other sites

Wow copy paste up the wazoo, please go learn some java code structure.

But ya.. Enchanting stuff or doing whatever you want is possible now.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Patreon: http://www.patreon.com/lexmanos
Paypal: http://paypal.me/LexManos

BitCoin: 1Q8rWvUNMM2T1ZfDaFeeYQyVXtYoeT6tTn

Link to post
Share on other sites
  • 3 months later...

::)

Yeah yeah. Copy-paste heaven and structure sucks. It's been like 10 years since I had a college course in Java. I'll learn better coding skills if/when I get a full time job writing code.

The main reason for this reply is because with the deprication of DungeonHooks, this all changes. The only way I can think of doing the same thing now is to either add one of every possible enchantment of every possible tool/armor/weapon or to create some kind of new fake item which replaces itself with an enchanted item when created. Not even sure if that would work.

So with the current structure, is it still possible to add dungeon loot that will have a random enchantment applied when generated? If so, any hints?

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • When does shadowJar run? I thought it runs at the same time the jar task runs, which is before reobfJar. I need it to run after reobfJar.
    • You should probably use the Shadow plugin.
    • Hi, I am trying to get HikariCP bundled with my mod as a one fat jar. But there is a problem where HikariCP causes reobfJar to fail with InvalidArgumentException, and I'm not sure why. Here is my gradle code right now (I left out a lot of stuff which I don't think matters):   configurations { embed } dependencies { minecraft 'net.minecraftforge:forge:1.16.5-36.1.0' embed group: 'com.zaxxer', name: 'HikariCP', version: '4.0.3' compileOnly group: 'com.ea.async', name: 'ea-async', version: '1.2.3' } jar { from configurations.embed.collect{ it.isDirectory() ? it : zipTree(it) } manifest { attributes([ "Specification-Title": "examplemod", "Specification-Vendor": "examplemodsareus", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"examplemodsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } jar.finalizedBy('reobfJar')   As I understand, this is the current order of events: `jar` task to run, which will bundle all the dependencies marked with `embed`, which will create the fat jar `reobfJar` will run on that fat jar. Would I would like to do instead is this order of events: `jar` task to run, but no fat jar is created at this time. `reobfJar` will run on the output of `jar`. A new task runs, which will take the output of `reobfJar` and combine it with the dependencies marked with `embed` to create the one fat jar   I think the code would look something like this:   jar { manifest { attributes([ "Specification-Title": "examplemod", "Specification-Vendor": "examplemodsareus", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"examplemodsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } jar.finalizedBy('reobfJar') task bundle(type: Jar) { manifest { attributes 'Main-Class': 'com.gluecode.fpvdrone.server.Main' } from "build/libs/modid-1.0.jar" from configurations.embed.collect{ it.isDirectory() ? it : zipTree(it) } } The problems I have with the above is: I have to run `./gradlew bundle` after running `./gradlew buildNeeded`. And I'd like to just run 1 command. It doesn't work because it results in an invalid mod jar. I'm am still learning gradle. Can anyone help me?
    • You need to make your own modifier with its own ID (otherwise Minecraft will ignore you and consider the two modifiers the same). Then add your own modifier on top of the vanilla modifier.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.