02b96c0c05
DDLoot: Implemented a custom version of MC's generateChestContents() for our own chests. It avoids two notable bugs that affect MC's version. FillContainersOperation: Changed code to use DDLoot.generateChestContents() SchematicLoader: Fixed a bug in the way we calculated a seed for selecting our dungeons that would cause certain seeds to dominate all the others. Under certain circumstances, the function would only return -1. That would make our dungeon selection severely biased. That was resolved and the code was specifically tuned for seeding Java's Random even for doors with nearly identical positions. The result was an apparent major improvement in the randomness of dungeons. ruins\rules.txt: Changed the dungeon generation rules to precisely match the complicated scheme we had before. We're still using simple rules to choose dungeons - I used a program to derive the effective distribution of dungeon types that the old code would produce and converted it into the current rule system.
72 lines
1.8 KiB
Java
72 lines
1.8 KiB
Java
package StevenDimDoors.mod_pocketDim.dungeon;
|
|
|
|
import java.util.Random;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockContainer;
|
|
import net.minecraft.inventory.IInventory;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.tileentity.TileEntityChest;
|
|
import net.minecraft.tileentity.TileEntityDispenser;
|
|
import net.minecraft.world.World;
|
|
import StevenDimDoors.mod_pocketDim.DDLoot;
|
|
import StevenDimDoors.mod_pocketDim.schematic.WorldOperation;
|
|
|
|
public class FillContainersOperation extends WorldOperation
|
|
{
|
|
private Random random;
|
|
|
|
public FillContainersOperation(Random random)
|
|
{
|
|
super("FillContainersOperation");
|
|
this.random = random;
|
|
}
|
|
|
|
@Override
|
|
protected boolean applyToBlock(World world, int x, int y, int z)
|
|
{
|
|
int blockID = world.getBlockId(x, y, z);
|
|
|
|
//Fill empty chests and dispensers
|
|
if (Block.blocksList[blockID] instanceof BlockContainer)
|
|
{
|
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
|
|
//Fill chests
|
|
if (tileEntity instanceof TileEntityChest)
|
|
{
|
|
TileEntityChest chest = (TileEntityChest) tileEntity;
|
|
if (isInventoryEmpty(chest))
|
|
{
|
|
DDLoot.generateChestContents(DDLoot.DungeonChestInfo, chest, random);
|
|
}
|
|
}
|
|
|
|
//Fill dispensers
|
|
if (tileEntity instanceof TileEntityDispenser)
|
|
{
|
|
TileEntityDispenser dispenser = (TileEntityDispenser) tileEntity;
|
|
if (isInventoryEmpty(dispenser))
|
|
{
|
|
dispenser.addItem(new ItemStack(Item.arrow, 64));
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static boolean isInventoryEmpty(IInventory inventory)
|
|
{
|
|
int size = inventory.getSizeInventory();
|
|
for (int index = 0; index < size; index++)
|
|
{
|
|
if (inventory.getStackInSlot(index) != null)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|