Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package r3qu13m.bf;
- import java.util.List;
- import buildcraft.BuildCraftBuilders;
- import buildcraft.BuildCraftCore;
- import buildcraft.BuildCraftTransport;
- import buildcraft.api.core.IBox;
- import buildcraft.api.filler.FillerManager;
- import buildcraft.api.filler.IFillerPattern;
- import buildcraft.builders.FillerRemover;
- import buildcraft.core.utils.BlockUtil;
- import buildcraft.core.utils.Utils;
- import cpw.mods.fml.common.Mod;
- import cpw.mods.fml.common.event.FMLInitializationEvent;
- import net.minecraft.block.Block;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraftforge.common.ForgeDirection;
- @Mod(modid = "bumpfiller", name = "BumpFiller", version = "0.0.1", dependencies = "after:BuildCraft|Builders")
- public class BumpFiller {
- @Mod.Instance("bumpfiller")
- public static BumpFiller instance;
- public BumpFiller() {
- instance = this;
- }
- @Mod.Init
- public void init(FMLInitializationEvent event) {
- FillerManager.registry.addRecipe(new FillerRemover() {
- @Override
- public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
- int xMin = (int) box.pMin().x;
- int yMin = (int) box.pMin().y;
- int zMin = (int) box.pMin().z;
- int xMax = (int) box.pMax().x;
- int yMax = (int) box.pMax().y;
- int zMax = (int) box.pMax().z;
- boolean found = false;
- int lastX = Integer.MAX_VALUE, lastY = Integer.MAX_VALUE, lastZ = Integer.MAX_VALUE;
- for (int y = yMax; y >= yMin; y--) {
- found = false;
- for (int x = xMin; x <= xMax; ++x) {
- for (int z = zMin; z <= zMax; ++z) {
- if (!BlockUtil.canChangeBlock(tile.worldObj, x, y, z))
- return false;
- if (!BlockUtil.isSoftBlock(tile.worldObj, x, y, z)) {
- found = true;
- lastX = x;
- lastY = y;
- lastZ = z;
- }
- }
- }
- if (found) {
- break;
- }
- }
- if (lastX != Integer.MAX_VALUE) {
- List<ItemStack> stacks = BlockUtil.getItemStackFromBlock(tile.worldObj, lastX, lastY, lastZ);
- for (ItemStack stack : stacks) {
- tile.worldObj.setBlockWithNotify(lastX, lastY, lastZ, 0);
- // First, try to add to a nearby chest
- ItemStack added = Utils.addToRandomInventory(stack, tile.worldObj, tile.xCoord, tile.yCoord,
- tile.zCoord, ForgeDirection.UNKNOWN);
- stack.stackSize -= added.stackSize;
- // Second, try to add to adjacent pipes
- if (stack.stackSize > 0) {
- Utils.addToRandomPipeEntry(tile, ForgeDirection.UNKNOWN, stack);
- }
- // Lastly, throw the object away
- if (stack.stackSize > 0) {
- float f = tile.worldObj.rand.nextFloat() * 0.8F + 0.1F;
- float f1 = tile.worldObj.rand.nextFloat() * 0.8F + 0.1F;
- float f2 = tile.worldObj.rand.nextFloat() * 0.8F + 0.1F;
- EntityItem entityitem = new EntityItem(tile.worldObj, tile.xCoord + f,
- tile.yCoord + f1 + 0.5F, tile.zCoord + f2, stack);
- entityitem.lifespan = BuildCraftCore.itemLifespan;
- entityitem.delayBeforeCanPickup = 10;
- float f3 = 0.05F;
- entityitem.motionX = (float) tile.worldObj.rand.nextGaussian() * f3;
- entityitem.motionY = (float) tile.worldObj.rand.nextGaussian() * f3 + 1.0F;
- entityitem.motionZ = (float) tile.worldObj.rand.nextGaussian() * f3;
- tile.worldObj.spawnEntityInWorld(entityitem);
- }
- }
- return false;
- }
- return true;
- }
- @Override
- public String getName() {
- return "ClearPipe";
- }
- }, new Object[] { "ggg", "gpg", "ggg", 'g', Block.glass, 'p', BuildCraftTransport.pipeItemsGold });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement