f4653d0522
Improved DungeonSchematic to the point that it can replace SchematicLoader as our method of loading dungeons. Some of the code was copied over rather than refactored to save time. It's been subdivided so make it much more readable. Also, we can reimplement portions of it as WorldOperations later on further remove redudancy. Testing shows that there is one problem left to fix: door blocks are not being set up correctly at the moment. Rifts are being set up properly and attaching doors to rifts will show that dungeons continue to generate fine. Added classes to support DungeonSchematic and its additional filtering logic on import and export. SpecialBlockFinder handles listing the entrance, other doors in the dungeon, and end portal frames. FillContainersOperation is a WorldOperation that fills chests and dispensers. BlockRotator is a temporary class to hold transformMetadata() and transformPoint() until we rewrite that code later. Stripped out most of the code from SchematicLoader to ensure it's no longer used. The only remaining function sets up dungeon pockets. We can phase it out in a later version so as not to delay our release. Removed references to SchematicLoader in mod_pocketDim since it no longer needs to be instantiated.
75 lines
2 KiB
Java
75 lines
2 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.util.WeightedRandomChestContent;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.ChestGenHooks;
|
|
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))
|
|
{
|
|
ChestGenHooks info = DDLoot.DungeonChestInfo;
|
|
WeightedRandomChestContent.generateChestContents(random, info.getItems(random), chest, info.getCount(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;
|
|
}
|
|
}
|