fixed iteration on filler
This commit is contained in:
parent
374637639e
commit
e8eda47ec8
3 changed files with 132 additions and 54 deletions
|
@ -15,16 +15,17 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.builders.TileAbstractBuilder;
|
||||
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
|
||||
public class BptBuilderTemplate extends BptBuilderBase {
|
||||
|
||||
LinkedList<BuildingSlotBlock> clearList = new LinkedList<BuildingSlotBlock>();
|
||||
LinkedList<BuildingSlotBlock> buildList = new LinkedList<BuildingSlotBlock>();
|
||||
private LinkedList<BuildingSlotBlock> buildList = new LinkedList<BuildingSlotBlock>();
|
||||
private BuildingSlotIterator iterator;
|
||||
|
||||
|
||||
public BptBuilderTemplate(BlueprintBase bluePrint, World world, int x, int y, int z) {
|
||||
super(bluePrint, world, x, y, z);
|
||||
|
@ -47,12 +48,14 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
b.z = zCoord;
|
||||
b.mode = Mode.ClearIfInvalid;
|
||||
|
||||
clearList.add(b);
|
||||
buildList.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildList.add(null);
|
||||
|
||||
for (int j = 0; j < bluePrint.sizeY; ++j) {
|
||||
for (int i = 0; i < bluePrint.sizeX; ++i) {
|
||||
for (int k = 0; k < bluePrint.sizeZ; ++k) {
|
||||
|
@ -77,10 +80,12 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator = new BuildingSlotIterator(buildList);
|
||||
}
|
||||
|
||||
private void checkDone() {
|
||||
if (clearList.size() == 0 && buildList.size() == 0) {
|
||||
if (buildList.size() == 0) {
|
||||
done = true;
|
||||
} else {
|
||||
done = false;
|
||||
|
@ -89,15 +94,6 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
|
||||
@Override
|
||||
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
|
||||
if (clearList.size() != 0) {
|
||||
BuildingSlotBlock slot = internalGetNextBlock(world, inv, clearList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
if (buildList.size() != 0) {
|
||||
BuildingSlotBlock slot = internalGetNextBlock(world, inv, buildList);
|
||||
checkDone();
|
||||
|
@ -126,27 +122,37 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
}
|
||||
}
|
||||
|
||||
while (list.size() > 0) {
|
||||
BuildingSlotBlock slot = list.getFirst();
|
||||
iterator.startIteration();
|
||||
|
||||
if (slot.mode == Mode.ClearIfInvalid
|
||||
&& !BuildCraftAPI.softBlocks.contains(context.world()
|
||||
.getBlock(slot.x, slot.y, slot.z))) {
|
||||
slot.addStackConsumed(new ItemStack(BuildCraftBuilders.stripesBlock));
|
||||
result = slot;
|
||||
list.removeFirst();
|
||||
while (iterator.hasNext()) {
|
||||
BuildingSlotBlock slot = iterator.next();
|
||||
|
||||
if (slot == null) {
|
||||
break;
|
||||
} else if (slot.mode == Mode.Build
|
||||
&& BuildCraftAPI.softBlocks.contains(context.world()
|
||||
.getBlock(slot.x, slot.y, slot.z))) {
|
||||
|
||||
if (firstSlotToConsume != null) {
|
||||
slot.addStackConsumed(firstSlotToConsume.decreaseStackInSlot());
|
||||
} else if (slot.mode == Mode.ClearIfInvalid) {
|
||||
if (BlockUtil.isSoftBlock(world, slot.x, slot.y, slot.z)) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
slot.addStackConsumed(new ItemStack(
|
||||
BuildCraftBuilders.stripesBlock));
|
||||
result = slot;
|
||||
list.removeFirst();
|
||||
iterator.remove();
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (slot.mode == Mode.Build) {
|
||||
if (!BlockUtil.isSoftBlock(world, slot.x, slot.y, slot.z)) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
if (firstSlotToConsume != null) {
|
||||
slot.addStackConsumed(firstSlotToConsume
|
||||
.decreaseStackInSlot());
|
||||
result = slot;
|
||||
iterator.remove();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
62
common/buildcraft/core/blueprints/BuildingSlotIterator.java
Executable file
62
common/buildcraft/core/blueprints/BuildingSlotIterator.java
Executable file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.blueprints;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class BuildingSlotIterator {
|
||||
|
||||
private static int ITERATIONS_MAX = 1000;
|
||||
|
||||
private LinkedList<BuildingSlotBlock> buildList;
|
||||
private Iterator<BuildingSlotBlock> current;
|
||||
private int nbIterations;
|
||||
|
||||
/**
|
||||
* Creates an iterator on the list, which will cycle through iterations per
|
||||
* chunk.
|
||||
*/
|
||||
public BuildingSlotIterator (LinkedList<BuildingSlotBlock> buildList) {
|
||||
this.buildList = buildList;
|
||||
}
|
||||
|
||||
public void startIteration () {
|
||||
if (current == null || !current.hasNext()) {
|
||||
current = buildList.iterator();
|
||||
}
|
||||
|
||||
nbIterations = 0;
|
||||
}
|
||||
|
||||
public boolean hasNext () {
|
||||
return current.hasNext() && nbIterations < ITERATIONS_MAX;
|
||||
}
|
||||
|
||||
public BuildingSlotBlock next () {
|
||||
BuildingSlotBlock next = current.next();
|
||||
|
||||
if (next == null) {
|
||||
// we're only accepting to pass through a null element if this is
|
||||
// the first iteration. Otherwise, elements before null need to
|
||||
// be worked out.
|
||||
if (nbIterations == 0) {
|
||||
current.remove();
|
||||
}
|
||||
}
|
||||
|
||||
nbIterations++;
|
||||
return next;
|
||||
}
|
||||
|
||||
public void remove () {
|
||||
current.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -8,12 +8,6 @@
|
|||
*/
|
||||
package buildcraft.core.utils;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftEnergy;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,6 +20,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.network.play.server.S27PacketExplosion;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fluids.BlockFluidBase;
|
||||
|
@ -34,17 +29,24 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
|||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftEnergy;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class BlockUtil {
|
||||
|
||||
public static List<ItemStack> getItemStackFromBlock(World world, int i, int j, int k) {
|
||||
Block block = world.getBlock(i, j, k);
|
||||
|
||||
if (block == null)
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (block.isAir(world, i, j, k))
|
||||
if (block.isAir(world, i, j, k)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int meta = world.getBlockMetadata(i, j, k);
|
||||
|
||||
|
@ -87,8 +89,9 @@ public class BlockUtil {
|
|||
}
|
||||
|
||||
public static boolean isAnObstructingBlock(Block block, World world, int x, int y, int z) {
|
||||
if (block == null || block.isAir(world, x, y, z))
|
||||
if (block == null || block.isAir(world, x, y, z)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -97,26 +100,30 @@ public class BlockUtil {
|
|||
}
|
||||
|
||||
public static boolean canChangeBlock(Block block, World world, int x, int y, int z) {
|
||||
if (block == null || block.isAir(world, x, y, z))
|
||||
if (block == null || block.isAir(world, x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (block.getBlockHardness(world, x, y, z) < 0)
|
||||
if (block.getBlockHardness(world, x, y, z) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (block == BuildCraftEnergy.blockOil)
|
||||
if (block == BuildCraftEnergy.blockOil) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (block == Blocks.lava || block == Blocks.flowing_lava)
|
||||
if (block == Blocks.lava || block == Blocks.flowing_lava) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isSoftBlock(World world, int x, int y, int z) {
|
||||
public static boolean isSoftBlock(IBlockAccess world, int x, int y, int z) {
|
||||
return isSoftBlock(world.getBlock(x, y, z), world, x, y, z);
|
||||
}
|
||||
|
||||
public static boolean isSoftBlock(Block block, World world, int x, int y, int z) {
|
||||
public static boolean isSoftBlock(Block block, IBlockAccess world, int x, int y, int z) {
|
||||
return block == null || BuildCraftAPI.softBlocks.contains(block) || block.isAir(world, x, y, z);
|
||||
}
|
||||
|
||||
|
@ -131,9 +138,10 @@ public class BlockUtil {
|
|||
return isFullFluidBlock(world.getBlock(x, y, z), world, x, y, z);
|
||||
}
|
||||
|
||||
public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) {
|
||||
if (block instanceof BlockFluidBase || block instanceof IFluidBlock)
|
||||
public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) {
|
||||
if (block instanceof BlockFluidBase || block instanceof IFluidBlock) {
|
||||
return world.getBlockMetadata(x, y, z) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -146,21 +154,21 @@ public class BlockUtil {
|
|||
}
|
||||
|
||||
public static FluidStack drainBlock(Block block, World world, int x, int y, int z, boolean doDrain) {
|
||||
Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
|
||||
|
||||
Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
|
||||
|
||||
if (fluid != null) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
|
||||
if (meta != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (doDrain) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
return new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
|
||||
} else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -170,16 +178,18 @@ public class BlockUtil {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void explodeBlock(World world, int x, int y, int z) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Explosion explosion = new Explosion(world, null, x + .5, y + .5, z + .5, 3f);
|
||||
explosion.affectedBlockPositions.add(new ChunkPosition(x, y, z));
|
||||
explosion.doExplosionB(true);
|
||||
|
||||
for (EntityPlayer player : (List<EntityPlayer>) world.playerEntities) {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
if (!(player instanceof EntityPlayerMP)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.getDistanceSq(x, y, z) < 4096) {
|
||||
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S27PacketExplosion(x + .5, y + .5, z + .5, 3f, explosion.affectedBlockPositions, null));
|
||||
|
|
Loading…
Reference in a new issue