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

Forge hooks for Structure loot.


fabricator77
 Share

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You have invtweaks which is a mod for minecraft 1.16 and you have the version of jade for minecraft 1.18. Neither of these mods will work with minecraft 1.19   The 1.19 version of jade can be found here: https://www.curseforge.com/minecraft/mc-mods/jade/files/all?filter-game-version=1738749986%3a73407  
    • my ForgeSlider can't drag , it can only be click ,I'm not sure if I'm doing something wrong this is my Screen code public class MannequinScreen extends AbstractContainerScreen<MannequinMenu> { private EditBox NameBox; private final MannequinEntity mannequin; public final MannequinMenu menu; private ForgeSlider xRotationSlider; private ForgeSlider yRotationSlider; private ForgeSlider zRotationSlider; private ForgeSlider scaleSlider; private CycleButton<Part> partButton; private Part nowPart; private Rotations rotations; private float xMouse; private float yMouse; private static final ResourceLocation TEXTURE = new ResourceLocation(KpRandomThing.MODID, "textures/gui/mannequin.png"); public MannequinScreen(MannequinMenu container, Inventory inventory, Component text) { super(container, inventory, text); this.imageWidth = 176; this.imageHeight = 210; this.mannequin = container.mannequin; this.menu = container; } @Override public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderTooltip(matrixStack, mouseX, mouseY); this.xMouse = mouseX; this.yMouse = mouseY; } @Override protected void renderBg(PoseStack matrixStack, float partialTicks, int gx, int gy) { RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderTexture(0, TEXTURE); GuiComponent.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight); RenderSystem.disableBlend(); int width = (this.width - this.imageWidth) / 2; int height = (this.height - this.imageHeight) / 2; InventoryScreen.renderEntityInInventory(width + 46, height + 106, 30, (float) (width + 51) - this.xMouse, (float) (height + 75 - 50) - this.yMouse, this.mannequin); } @Override public void init() { super.init(); this.minecraft.keyboardHandler.setSendRepeatsToGui(true); NameBox = new EditBox(this.font, this.leftPos + 6, this.topPos + 4, 99, 20, new TextComponent("name")); NameBox.setMaxLength(60); this.addRenderableWidget(NameBox); Button rename = new Button(this.leftPos + 114, this.topPos + 4, 54, 20, new TextComponent("Rename"), onPress -> { if (!NameBox.getValue().isEmpty()) { KpRandomThing.INSTANCE.sendToServer( new MessagePacket(1, new TextComponent(NameBox.getValue()))); } }); this.addRenderableWidget(rename); int sliderX = this.leftPos + 92; int sliderY = this.topPos + 5; this.partButton = createPartButton(sliderX, sliderY + 80); this.addRenderableWidget(partButton); rotations = this.partButton.getValue().getPose(mannequin); this.xRotationSlider = createAngleSlider(sliderX, sliderY + 20, 74, 20, "X:", rotations.getX()); this.yRotationSlider = createAngleSlider(sliderX, sliderY + 40, 74, 20, "Y:", rotations.getY()); this.zRotationSlider = createAngleSlider(sliderX, sliderY + 60, 74, 20, "Z:", rotations.getZ()); this.scaleSlider = new ForgeSlider(sliderX, sliderY + 100, 74, 20, new TranslatableComponent("button.kp_random_thing.scale"), TextComponent.EMPTY, 0.1, 2, mannequin.getScale(), 0, 2, true); this.addRenderableWidget(xRotationSlider); this.addRenderableWidget(yRotationSlider); this.addRenderableWidget(zRotationSlider); this.addRenderableWidget(scaleSlider); } @Override protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { } @Override public boolean mouseReleased(double xMouse, double yMouse, int id) { updata(); return super.mouseReleased(xMouse, yMouse, id); } @Override public boolean keyPressed(int key, int b, int c) { if (key == 256) { this.minecraft.player.closeContainer(); return true; } return super.keyPressed(key, b, c); } private void updata() { if (nowPart != partButton.getValue()) switchPart(); String name = partButton.getValue().name; double x = xRotationSlider.getValue(); double y = yRotationSlider.getValue(); double z = zRotationSlider.getValue(); double scale = scaleSlider.getValue(); KpRandomThing.INSTANCE.sendToServer(new MessagePacket(0, x, y, z, scale, new TextComponent(name))); } private void switchPart() { Rotations rotations = partButton.getValue().getPose(mannequin); this.xRotationSlider.setValue(rotations.getX()); this.yRotationSlider.setValue(rotations.getY()); this.zRotationSlider.setValue(rotations.getZ()); this.nowPart = partButton.getValue(); } private CycleButton<Part> createPartButton(int width, int height) { CycleButton<Part> button = CycleButton.builder(Part::getName).withValues(Part.values()).create(width, height, 80, 20, new TranslatableComponent("button.kp_random_thing.part")); return button; } private ForgeSlider createAngleSlider(int x, int y, int width, int height, String prefix, double currentValue) { return new ForgeSlider(x, y, width, height, new TextComponent(prefix), TextComponent.EMPTY, -180D, 180D, currentValue, 0, 2, true); } public enum Part { HEAD(MannequinEntity.DATA_HEAD_POSE, MannequinEntity.HEAD), BODY(MannequinEntity.DATA_BODY_POSE, MannequinEntity.BODY), LEFT_ARM(MannequinEntity.DATA_LEFT_ARM_POSE, MannequinEntity.LEFT_ARM), RIGHT_ARM(MannequinEntity.DATA_RIGHT_ARM_POSE, MannequinEntity.RIGHT_ARM), LEFT_LEG(MannequinEntity.DATA_LEFT_LEG_POSE, MannequinEntity.LEFT_LEG), RIGHT_LEG(MannequinEntity.DATA_RIGHT_LEG_POSE, MannequinEntity.RIGHT_LEG); final EntityDataAccessor<Rotations> dataPose; final String name; Part(EntityDataAccessor<Rotations> dataPose, String name) { this.dataPose = dataPose; this.name = name; } public Rotations getPose(ArmorStand entity) { if (entity == null) { return new Rotations(0, 0, 0); } return entity.getEntityData().get(dataPose); } public Component getName() { return new TranslatableComponent("button.kp_random_thing.part." + name); } } }  
    • Hello, I am trying to install client-side mods, to better my minecraft experience on servers, but I run into a few issues with some dependencies missing, so I would like if someone would be able to help me.  Here are the following errors: Error loading mods 3 errors have occurred during loading --------------------------------------- InventoryTweaksRenewed(invtweaks) has failed to load correctly java.lang.NoClassDefFoundError:net/minecraft/client/gui/widget/Widget Jade(jade) has failed to load correctly java.lang.NoClassDefFoundError:net/minecraftforge/event/entity/EntityJoinWorldEvent Waila(Jade)(waila)has failed to load correctly java.lang.NoClassDefFoundError:net/minecraftforge/client/event/ClientPlayerNetworkEvent$LoggedOutEvent Here is a pastebin of the crash report: https://pastebin.com/uMxfcUP3
    • You don't show the error, or minecraft version or any other useful information. "It keeps on crashing and I can't get it to load" is useless.   The github project you posted is incomplete. It has no build.gradle, etc. so we can't build it ourselves to find out the problem you have.   GUESSING: I can see a number of obvious problems with your code:   1) https://github.com/Tucky143/Buzz/blob/a03ffc801f439a095e9c272dff6510970543f0e2/src/main/java/com/example/examplemod/villager/ModVillagers.java#L29 Here you are doing instance equality tests for a Holder<PoiType> with a PoiType. This will never be true.   2) https://github.com/Tucky143/Buzz/blob/a03ffc801f439a095e9c272dff6510970543f0e2/src/main/java/com/example/examplemod/villager/ModVillagers.java#L36 That reflection code does nothing. Look at the method you are calling. Although I suspect you can't find it. The signature of the method you are using is for 1.18.x while the above methods you are using in (1) above are the signatures of methods in 1.19.x    
  • Topics

×
×
  • Create New...

Important Information

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