Reworked Extraction Exclusion hooks for API
This commit is contained in:
parent
0122ef17db
commit
7bba02643e
6 changed files with 109 additions and 59 deletions
|
@ -21,6 +21,8 @@ import buildcraft.api.gates.ActionManager;
|
||||||
import buildcraft.api.gates.Trigger;
|
import buildcraft.api.gates.Trigger;
|
||||||
import buildcraft.api.recipes.AssemblyRecipe;
|
import buildcraft.api.recipes.AssemblyRecipe;
|
||||||
import buildcraft.api.transport.IPipe;
|
import buildcraft.api.transport.IPipe;
|
||||||
|
import buildcraft.api.transport.IExtractionHandler;
|
||||||
|
import buildcraft.api.transport.PipeManager;
|
||||||
import buildcraft.core.CoreProxy;
|
import buildcraft.core.CoreProxy;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.ItemBuildCraft;
|
import buildcraft.core.ItemBuildCraft;
|
||||||
|
@ -72,6 +74,7 @@ import net.minecraft.src.CraftingManager;
|
||||||
import net.minecraft.src.Item;
|
import net.minecraft.src.Item;
|
||||||
import net.minecraft.src.ItemStack;
|
import net.minecraft.src.ItemStack;
|
||||||
import net.minecraft.src.ModLoader;
|
import net.minecraft.src.ModLoader;
|
||||||
|
import net.minecraft.src.World;
|
||||||
import net.minecraft.src.forge.Configuration;
|
import net.minecraft.src.forge.Configuration;
|
||||||
import net.minecraft.src.forge.MinecraftForge;
|
import net.minecraft.src.forge.MinecraftForge;
|
||||||
import net.minecraft.src.forge.Property;
|
import net.minecraft.src.forge.Property;
|
||||||
|
@ -170,6 +173,45 @@ public class BuildCraftTransport {
|
||||||
MinecraftForge.setGuiHandler(mod_BuildCraftTransport.instance, new GuiHandler());
|
MinecraftForge.setGuiHandler(mod_BuildCraftTransport.instance, new GuiHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ExtractionHandler implements IExtractionHandler {
|
||||||
|
private final String[] items;
|
||||||
|
private final String[] liquids;
|
||||||
|
|
||||||
|
public ExtractionHandler(String[] items, String[] liquids){
|
||||||
|
this.items = items;
|
||||||
|
this.liquids = liquids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canExtractItems(World world, int i, int j, int k) {
|
||||||
|
return testStrings(items, world, i, j, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canExtractLiquids(World world, int i, int j, int k) {
|
||||||
|
return testStrings(liquids, world, i, j, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean testStrings(String[] excludedBlocks, World world, int i, int j, int k) {
|
||||||
|
int id = world.getBlockId(i, j, k);
|
||||||
|
Block block = Block.blocksList[id];
|
||||||
|
if(block == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int meta = world.getBlockMetadata(i, j, k);
|
||||||
|
|
||||||
|
for (String excluded : excludedBlocks) {
|
||||||
|
if (excluded.equals(block.getBlockName()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String[] tokens = excluded.split(":");
|
||||||
|
if(tokens[0].equals(Integer.toString(id)) && (tokens.length == 1 || tokens[1].equals(Integer.toString(meta))))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
@ -186,10 +228,19 @@ public class BuildCraftTransport {
|
||||||
Configuration.CATEGORY_GENERAL, DefaultProps.USE_PIPELOSS);
|
Configuration.CATEGORY_GENERAL, DefaultProps.USE_PIPELOSS);
|
||||||
PipeLoss.comment = "Set to false to turn off energy loss over distance on all power pipes";
|
PipeLoss.comment = "Set to false to turn off energy loss over distance on all power pipes";
|
||||||
|
|
||||||
Property exclusionList = BuildCraftCore.mainConfiguration.getOrCreateProperty("woodenPipe.exclusion",
|
Property exclusionItemList = BuildCraftCore.mainConfiguration.getOrCreateProperty("woodenPipe.item.exclusion", Configuration.CATEGORY_BLOCK, "");
|
||||||
Configuration.CATEGORY_BLOCK, "");
|
|
||||||
|
|
||||||
PipeLogicWood.excludedBlocks = exclusionList.value.split(",");
|
String[] excludedItemBlocks = exclusionItemList.value.split(",");
|
||||||
|
for (int j = 0; j < excludedItemBlocks.length; ++j)
|
||||||
|
excludedItemBlocks[j] = excludedItemBlocks[j].trim();
|
||||||
|
|
||||||
|
Property exclusionLiquidList = BuildCraftCore.mainConfiguration.getOrCreateProperty("woodenPipe.liquid.exclusion", Configuration.CATEGORY_BLOCK, "");
|
||||||
|
|
||||||
|
String[] excludedLiquidBlocks = exclusionLiquidList.value.split(",");
|
||||||
|
for (int j = 0; j < excludedLiquidBlocks.length; ++j)
|
||||||
|
excludedLiquidBlocks[j] = excludedLiquidBlocks[j].trim();
|
||||||
|
|
||||||
|
PipeManager.registerExtractionHandler(new ExtractionHandler(excludedItemBlocks, excludedLiquidBlocks));
|
||||||
|
|
||||||
Property maxItemInPipesProp = BuildCraftCore.mainConfiguration.getOrCreateIntProperty("pipes.maxItems",
|
Property maxItemInPipesProp = BuildCraftCore.mainConfiguration.getOrCreateIntProperty("pipes.maxItems",
|
||||||
Configuration.CATEGORY_GENERAL, 100);
|
Configuration.CATEGORY_GENERAL, 100);
|
||||||
|
@ -206,8 +257,6 @@ public class BuildCraftTransport {
|
||||||
Property genericPipeId = BuildCraftCore.mainConfiguration.getOrCreateBlockIdProperty("pipe.id",
|
Property genericPipeId = BuildCraftCore.mainConfiguration.getOrCreateBlockIdProperty("pipe.id",
|
||||||
DefaultProps.GENERIC_PIPE_ID);
|
DefaultProps.GENERIC_PIPE_ID);
|
||||||
|
|
||||||
for (int j = 0; j < PipeLogicWood.excludedBlocks.length; ++j)
|
|
||||||
PipeLogicWood.excludedBlocks[j] = PipeLogicWood.excludedBlocks[j].trim();
|
|
||||||
|
|
||||||
BuildCraftCore.mainConfiguration.save();
|
BuildCraftCore.mainConfiguration.save();
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package buildcraft.api.transport;
|
|
||||||
|
|
||||||
import net.minecraft.src.World;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implemented by blocks that may want to suppress connections from wooden pipes.
|
|
||||||
*/
|
|
||||||
public interface IBlockExtractable {
|
|
||||||
boolean mayExtract(World world, int x, int y, int z);
|
|
||||||
}
|
|
|
@ -1,9 +1,33 @@
|
||||||
package buildcraft.api.transport;
|
package buildcraft.api.transport;
|
||||||
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PipeManager {
|
import net.minecraft.src.World;
|
||||||
|
|
||||||
|
public abstract class PipeManager {
|
||||||
|
|
||||||
public static TreeMap<Integer, IPipedItem> allEntities = new TreeMap<Integer, IPipedItem>();
|
public static TreeMap<Integer, IPipedItem> allEntities = new TreeMap<Integer, IPipedItem>();
|
||||||
|
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
|
||||||
|
|
||||||
|
public static void registerExtractionHandler(IExtractionHandler handler) {
|
||||||
|
extractionHandlers.add(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canExtractItems(World world, int i, int j, int k) {
|
||||||
|
for(IExtractionHandler handler : extractionHandlers)
|
||||||
|
if(!handler.canExtractItems(world, i, j, k))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canExtractLiquids(World world, int i, int j, int k) {
|
||||||
|
for(IExtractionHandler handler : extractionHandlers)
|
||||||
|
if(!handler.canExtractLiquids(world, i, j, k))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import buildcraft.api.APIProxy;
|
||||||
import buildcraft.api.core.Orientations;
|
import buildcraft.api.core.Orientations;
|
||||||
import buildcraft.api.liquids.ITankContainer;
|
import buildcraft.api.liquids.ITankContainer;
|
||||||
import buildcraft.api.tools.IToolWrench;
|
import buildcraft.api.tools.IToolWrench;
|
||||||
import buildcraft.api.transport.IBlockExtractable;
|
import buildcraft.api.transport.PipeManager;
|
||||||
import buildcraft.core.Utils;
|
import buildcraft.core.Utils;
|
||||||
import buildcraft.transport.pipes.PipeLiquidsVoid;
|
import buildcraft.transport.pipes.PipeLiquidsVoid;
|
||||||
import buildcraft.transport.pipes.PipeLiquidsWood;
|
import buildcraft.transport.pipes.PipeLiquidsWood;
|
||||||
|
@ -27,8 +27,6 @@ import net.minecraft.src.World;
|
||||||
|
|
||||||
public class PipeLogicWood extends PipeLogic {
|
public class PipeLogicWood extends PipeLogic {
|
||||||
|
|
||||||
public static String[] excludedBlocks = new String[0];
|
|
||||||
|
|
||||||
public void switchSource() {
|
public void switchSource() {
|
||||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||||
int newMeta = 6;
|
int newMeta = 6;
|
||||||
|
@ -40,7 +38,7 @@ public class PipeLogicWood extends PipeLogic {
|
||||||
TileEntity tile = container.getTile(o);
|
TileEntity tile = container.getTile(o);
|
||||||
|
|
||||||
if (isInput(tile))
|
if (isInput(tile))
|
||||||
if (!isExcludedFromExtraction(block, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord)) {
|
if (PipeManager.canExtractItems(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord) || PipeManager.canExtractLiquids(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord) ) {
|
||||||
newMeta = o.ordinal();
|
newMeta = o.ordinal();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -58,16 +56,6 @@ public class PipeLogicWood extends PipeLogic {
|
||||||
&& Utils.checkPipesConnections(container, tile);
|
&& Utils.checkPipesConnections(container, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExcludedFromExtraction(Block block, World world, int x, int y, int z) {
|
|
||||||
if (block == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if(!(block instanceof IBlockExtractable))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return !((IBlockExtractable)block).mayExtract(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||||
|
|
|
@ -17,6 +17,7 @@ import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerFramework;
|
import buildcraft.api.power.PowerFramework;
|
||||||
import buildcraft.api.power.PowerProvider;
|
import buildcraft.api.power.PowerProvider;
|
||||||
import buildcraft.api.transport.IPipedItem;
|
import buildcraft.api.transport.IPipedItem;
|
||||||
|
import buildcraft.api.transport.PipeManager;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.EntityPassiveItem;
|
import buildcraft.core.EntityPassiveItem;
|
||||||
import buildcraft.core.Utils;
|
import buildcraft.core.Utils;
|
||||||
|
@ -92,36 +93,34 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
||||||
|
|
||||||
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]);
|
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]);
|
||||||
pos.moveForwards(1);
|
pos.moveForwards(1);
|
||||||
int blockId = w.getBlockId((int) pos.x, (int) pos.y, (int) pos.z);
|
|
||||||
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||||
|
|
||||||
if (tile == null || !(tile instanceof IInventory || tile instanceof ITankContainer)
|
|
||||||
|| PipeLogicWood.isExcludedFromExtraction(Block.blocksList[blockId], tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (tile instanceof IInventory) {
|
if (tile instanceof IInventory) {
|
||||||
IInventory inventory = (IInventory) tile;
|
if (!PipeManager.canExtractItems(w, (int) pos.x, (int) pos.y, (int) pos.z))
|
||||||
|
return;
|
||||||
|
|
||||||
ItemStack[] extracted = checkExtract(inventory, true, pos.orientation.reverse());
|
IInventory inventory = (IInventory) tile;
|
||||||
if (extracted == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(ItemStack stack : extracted) {
|
ItemStack[] extracted = checkExtract(inventory, true, pos.orientation.reverse());
|
||||||
if (stack == null || stack.stackSize == 0) {
|
if (extracted == null)
|
||||||
powerProvider.useEnergy(1, 1, false);
|
return;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Position entityPos = new Position(pos.x + 0.5, pos.y + Utils.getPipeFloorOf(stack), pos.z + 0.5,
|
for(ItemStack stack : extracted) {
|
||||||
pos.orientation.reverse());
|
if (stack == null || stack.stackSize == 0) {
|
||||||
|
powerProvider.useEnergy(1, 1, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
entityPos.moveForwards(0.5);
|
Position entityPos = new Position(pos.x + 0.5, pos.y + Utils.getPipeFloorOf(stack), pos.z + 0.5,
|
||||||
|
pos.orientation.reverse());
|
||||||
|
|
||||||
IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack);
|
entityPos.moveForwards(0.5);
|
||||||
|
|
||||||
((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation);
|
IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack);
|
||||||
}
|
|
||||||
}
|
((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,6 +16,7 @@ import buildcraft.api.liquids.LiquidStack;
|
||||||
import buildcraft.api.power.IPowerProvider;
|
import buildcraft.api.power.IPowerProvider;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerFramework;
|
import buildcraft.api.power.PowerFramework;
|
||||||
|
import buildcraft.api.transport.PipeManager;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.network.TileNetworkData;
|
import buildcraft.core.network.TileNetworkData;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
|
@ -62,16 +63,15 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
||||||
|
|
||||||
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]);
|
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]);
|
||||||
pos.moveForwards(1);
|
pos.moveForwards(1);
|
||||||
int blockId = w.getBlockId((int) pos.x, (int) pos.y, (int) pos.z);
|
|
||||||
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||||
|
|
||||||
if (tile == null || !(tile instanceof ITankContainer)
|
if (tile instanceof ITankContainer) {
|
||||||
|| PipeLogicWood.isExcludedFromExtraction(Block.blocksList[blockId], tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
|
if (!PipeManager.canExtractLiquids(w, (int) pos.x, (int) pos.y, (int) pos.z))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (tile instanceof ITankContainer)
|
if (liquidToExtract <= BuildCraftAPI.BUCKET_VOLUME)
|
||||||
if (liquidToExtract <= BuildCraftAPI.BUCKET_VOLUME)
|
liquidToExtract += powerProvider.useEnergy(1, 1, true) * BuildCraftAPI.BUCKET_VOLUME;
|
||||||
liquidToExtract += powerProvider.useEnergy(1, 1, true) * BuildCraftAPI.BUCKET_VOLUME;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue