Jump to content

I want to know how to add Custom Loot Tables for structures [1.12.2]


Brokenglass32

Recommended Posts

This is loot for your own structure, right? And is your structure coded using classes that extend the StructureComponent class? If so, there is a call for generateChest() that you can override. Also, generally if you've coded your own structure you are free to place blocks however you want, so you can just place a chest however you want.

 

Anyway, it is easier to help if you post the code for your structure that you have already.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

This is how my structure is generated.

the structure comes with a chest, and i want to find out how to generate items in that chest.


 

package com.BrokenGlass32.ImprovedMinecraft.gen;

import java.util.ArrayList;
import java.util.Random;

import com.BrokenGlass32.ImprovedMinecraft.init.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.init.Biomes;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeDesert; 
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import scala.actors.threadpool.Arrays;

public class WorldGenCustomStructures implements IWorldGenerator
{

    @Override
    public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
    {
        switch(world.provider.getDimension())
        {
        case 2:
            
            break;
            
        case 1:
            
            break;
            
        case 0:
            
            this.generateStructureSandStoneHouseOne(new WorldGenStructure("sandstonehouse_structure_1"), world, random, chunkX, chunkZ, 75, Blocks.SAND, BiomeDesert.class);                              
            break;
        
        case -1:
            
        }
    }
    
    private void generateStructureSandStoneHouseOne(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chance, Block topBlock, Class<?>... classes)
    {
        ArrayList<Class<?>> classesList = new ArrayList<Class<?>>(Arrays.asList(classes));
        
        int x = (chunkX * 16) + random.nextInt(15) + 8;
        int z = (chunkZ * 16) + random.nextInt(15) + 8;
        int y = calculateGenerationHeight(world, x, z, topBlock);
        BlockPos pos = new BlockPos(x,y,z);
        
        Class<?> biome = world.provider.getBiomeForCoords(pos).getClass();
        
        if(world.getWorldType() != WorldType.FLAT)
        {
            if(classesList.contains(biome))
            {
                if(random.nextInt(chance) == 0)
                {
                    generator.generate(world, random, pos);
                }
            }
        }
    }
    private static int calculateGenerationHeight(World world, int x, int z, Block topBlock)
    {
        int y = world.getHeight();
        boolean foundGround = false;
        
        while(!foundGround && y-- >= 0)
        {
            Block block = world.getBlockState(new BlockPos(x,y,z)).getBlock();
            foundGround = block == topBlock;
        }
        
        return y;
    }
}

Sorry for the very late response, and thank you for the reply.

Edited by Brokenglass32
Link to comment
Share on other sites

What's in the WorldGenStructure class? Is that your own class -- I can't find that class in the vanilla or forge source...

 

Anyway, the basic structure template format doesn't directly allow loot tables to get into the generated chests. But you can mark the chests by adding data blocks to your structure, then when you generate the structure you can loop through the data blocks and use them for additional processing. For example, you could put a data block right on top of the chest block to mark the position and then use that to find the tileentity for the chest when it generates and add the loot table directly at that point.

 

There might be a simpler way, but that seems to be the way some other people have solved this problem.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

26 minutes ago, jabelar said:

There might be a simpler way, but that seems to be the way some other people have solved this problem.

To be fair, that seems to be the way Mojang has solved this problem, too XD It's kind of the only reason the Data Mode of structure blocks even exists.

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.