Add block disables to BCFactory
Now if you set the blockId to 0 or -1 in the config, the block will not be loaded.
This commit is contained in:
parent
e523988ea2
commit
6e1788fb0c
4 changed files with 651 additions and 101 deletions
|
@ -1,17 +1,17 @@
|
|||
/**
|
||||
* BuildCraft is open-source. It is distributed under the terms of the
|
||||
* BuildCraft Open Source License. It grants rights to read, modify, compile
|
||||
* or run the code. It does *NOT* grant the right to redistribute this software
|
||||
* or its modifications in any form, binary or source, except if expressively
|
||||
* BuildCraft Open Source License. It grants rights to read, modify, compile or
|
||||
* run the code. It does *NOT* grant the right to redistribute this software or
|
||||
* its modifications in any form, binary or source, except if expressively
|
||||
* granted by the copyright holder.
|
||||
*/
|
||||
|
||||
package buildcraft;
|
||||
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.Version;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.factory.BlockAutoWorkbench;
|
||||
import buildcraft.factory.BlockFloodGate;
|
||||
import buildcraft.factory.BlockFrame;
|
||||
import buildcraft.factory.BlockHopper;
|
||||
import buildcraft.factory.BlockMiningWell;
|
||||
|
@ -62,7 +62,7 @@ import net.minecraftforge.common.Property;
|
|||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
@Mod(name = "BuildCraft Factory", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE)
|
||||
@NetworkMod(channels = { DefaultProps.NET_CHANNEL_NAME }, packetHandler = PacketHandlerFactory.class, clientSideRequired = true, serverSideRequired = true)
|
||||
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerFactory.class, clientSideRequired = true, serverSideRequired = true)
|
||||
public class BuildCraftFactory {
|
||||
|
||||
public static BlockQuarry quarryBlock;
|
||||
|
@ -71,25 +71,24 @@ public class BuildCraftFactory {
|
|||
public static BlockFrame frameBlock;
|
||||
public static BlockPlainPipe plainPipeBlock;
|
||||
public static BlockPump pumpBlock;
|
||||
public static BlockFloodGate floodGateBlock;
|
||||
public static BlockTank tankBlock;
|
||||
public static BlockRefinery refineryBlock;
|
||||
public static BlockHopper hopperBlock;
|
||||
public static boolean hopperDisabled;
|
||||
|
||||
public static boolean allowMining = true;
|
||||
|
||||
public static PumpDimensionList pumpDimensionList;
|
||||
|
||||
@Instance("BuildCraft|Factory")
|
||||
public static BuildCraftFactory instance;
|
||||
|
||||
@EventHandler
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent evt) {
|
||||
FactoryProxy.proxy.initializeNEIIntegration();
|
||||
ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
|
||||
}
|
||||
|
||||
public class QuarryChunkloadCallback implements ForgeChunkManager.OrderedLoadingCallback {
|
||||
|
||||
@Override
|
||||
public void ticketsLoaded(List<Ticket> tickets, World world) {
|
||||
for (Ticket ticket : tickets) {
|
||||
|
@ -117,10 +116,9 @@ public class BuildCraftFactory {
|
|||
}
|
||||
return validTickets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent evt) {
|
||||
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler());
|
||||
|
||||
|
@ -149,71 +147,81 @@ public class BuildCraftFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler
|
||||
public void initialize(FMLPreInitializationEvent evt) {
|
||||
allowMining = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "mining.enabled", true).getBoolean(true);
|
||||
|
||||
pumpDimensionList = new PumpDimensionList(BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pumping.controlList", DefaultProps.PUMP_DIMENSION_LIST).getString());
|
||||
|
||||
Property miningWellId = BuildCraftCore.mainConfiguration.getBlock("miningWell.id", DefaultProps.MINING_WELL_ID);
|
||||
Property plainPipeId = BuildCraftCore.mainConfiguration.getBlock("drill.id", DefaultProps.DRILL_ID);
|
||||
Property autoWorkbenchId = BuildCraftCore.mainConfiguration.getBlock("autoWorkbench.id", DefaultProps.AUTO_WORKBENCH_ID);
|
||||
Property frameId = BuildCraftCore.mainConfiguration.getBlock("frame.id", DefaultProps.FRAME_ID);
|
||||
Property quarryId = BuildCraftCore.mainConfiguration.getBlock("quarry.id", DefaultProps.QUARRY_ID);
|
||||
Property pumpId = BuildCraftCore.mainConfiguration.getBlock("pump.id", DefaultProps.PUMP_ID);
|
||||
Property tankId = BuildCraftCore.mainConfiguration.getBlock("tank.id", DefaultProps.TANK_ID);
|
||||
Property refineryId = BuildCraftCore.mainConfiguration.getBlock("refinery.id", DefaultProps.REFINERY_ID);
|
||||
Property hopperId = BuildCraftCore.mainConfiguration.getBlock("hopper.id", DefaultProps.HOPPER_ID);
|
||||
Property hopperDisable = BuildCraftCore.mainConfiguration.get("Block Savers", "hopper.disabled", false);
|
||||
int miningWellId = BuildCraftCore.mainConfiguration.getBlock("miningWell.id", DefaultProps.MINING_WELL_ID).getInt(DefaultProps.MINING_WELL_ID);
|
||||
int plainPipeId = BuildCraftCore.mainConfiguration.getBlock("drill.id", DefaultProps.DRILL_ID).getInt(DefaultProps.DRILL_ID);
|
||||
int autoWorkbenchId = BuildCraftCore.mainConfiguration.getBlock("autoWorkbench.id", DefaultProps.AUTO_WORKBENCH_ID).getInt(DefaultProps.AUTO_WORKBENCH_ID);
|
||||
int frameId = BuildCraftCore.mainConfiguration.getBlock("frame.id", DefaultProps.FRAME_ID).getInt(DefaultProps.FRAME_ID);
|
||||
int quarryId = BuildCraftCore.mainConfiguration.getBlock("quarry.id", DefaultProps.QUARRY_ID).getInt(DefaultProps.QUARRY_ID);
|
||||
int pumpId = BuildCraftCore.mainConfiguration.getBlock("pump.id", DefaultProps.PUMP_ID).getInt(DefaultProps.PUMP_ID);
|
||||
// int floodGateId = BuildCraftCore.mainConfiguration.getBlock("pump.id", DefaultProps.PUMP_ID).getInt(DefaultProps.MINING_WELL_ID);
|
||||
int tankId = BuildCraftCore.mainConfiguration.getBlock("tank.id", DefaultProps.TANK_ID).getInt(DefaultProps.TANK_ID);
|
||||
int refineryId = BuildCraftCore.mainConfiguration.getBlock("refinery.id", DefaultProps.REFINERY_ID).getInt(DefaultProps.REFINERY_ID);
|
||||
int hopperId = BuildCraftCore.mainConfiguration.getBlock("hopper.id", DefaultProps.HOPPER_ID).getInt(DefaultProps.HOPPER_ID);
|
||||
|
||||
if (BuildCraftCore.mainConfiguration.hasChanged())
|
||||
{
|
||||
BuildCraftCore.mainConfiguration.save();
|
||||
if (BuildCraftCore.mainConfiguration.hasChanged()) {
|
||||
BuildCraftCore.mainConfiguration.save();
|
||||
}
|
||||
|
||||
miningWellBlock = new BlockMiningWell(miningWellId.getInt());
|
||||
CoreProxy.proxy.registerBlock(miningWellBlock.setUnlocalizedName("miningWellBlock"));
|
||||
CoreProxy.proxy.addName(miningWellBlock, "Mining Well");
|
||||
|
||||
plainPipeBlock = new BlockPlainPipe(plainPipeId.getInt());
|
||||
CoreProxy.proxy.registerBlock(plainPipeBlock.setUnlocalizedName("plainPipeBlock"));
|
||||
CoreProxy.proxy.addName(plainPipeBlock, "Mining Pipe");
|
||||
|
||||
autoWorkbenchBlock = new BlockAutoWorkbench(autoWorkbenchId.getInt());
|
||||
CoreProxy.proxy.registerBlock(autoWorkbenchBlock.setUnlocalizedName("autoWorkbenchBlock"));
|
||||
CoreProxy.proxy.addName(autoWorkbenchBlock, "Automatic Crafting Table");
|
||||
|
||||
frameBlock = new BlockFrame(frameId.getInt());
|
||||
CoreProxy.proxy.registerBlock(frameBlock.setUnlocalizedName("frameBlock"));
|
||||
CoreProxy.proxy.addName(frameBlock, "Frame");
|
||||
|
||||
quarryBlock = new BlockQuarry(quarryId.getInt());
|
||||
CoreProxy.proxy.registerBlock(quarryBlock.setUnlocalizedName("machineBlock"));
|
||||
CoreProxy.proxy.addName(quarryBlock, "Quarry");
|
||||
|
||||
tankBlock = new BlockTank(tankId.getInt());
|
||||
CoreProxy.proxy.registerBlock(tankBlock.setUnlocalizedName("tankBlock"));
|
||||
CoreProxy.proxy.addName(tankBlock, "Tank");
|
||||
|
||||
pumpBlock = new BlockPump(pumpId.getInt());
|
||||
CoreProxy.proxy.registerBlock(pumpBlock.setUnlocalizedName("pumpBlock"));
|
||||
CoreProxy.proxy.addName(pumpBlock, "Pump");
|
||||
|
||||
refineryBlock = new BlockRefinery(refineryId.getInt());
|
||||
CoreProxy.proxy.registerBlock(refineryBlock.setUnlocalizedName("refineryBlock"));
|
||||
CoreProxy.proxy.addName(refineryBlock, "Refinery");
|
||||
|
||||
hopperDisabled = hopperDisable.getBoolean(false);
|
||||
if (!hopperDisabled) {
|
||||
hopperBlock = new BlockHopper(hopperId.getInt());
|
||||
if (miningWellId > 0) {
|
||||
miningWellBlock = new BlockMiningWell(miningWellId);
|
||||
CoreProxy.proxy.registerBlock(miningWellBlock.setUnlocalizedName("miningWellBlock"));
|
||||
CoreProxy.proxy.addName(miningWellBlock, "Mining Well");
|
||||
}
|
||||
if (plainPipeId > 0) {
|
||||
plainPipeBlock = new BlockPlainPipe(plainPipeId);
|
||||
CoreProxy.proxy.registerBlock(plainPipeBlock.setUnlocalizedName("plainPipeBlock"));
|
||||
CoreProxy.proxy.addName(plainPipeBlock, "Mining Pipe");
|
||||
}
|
||||
if (autoWorkbenchId > 0) {
|
||||
autoWorkbenchBlock = new BlockAutoWorkbench(autoWorkbenchId);
|
||||
CoreProxy.proxy.registerBlock(autoWorkbenchBlock.setUnlocalizedName("autoWorkbenchBlock"));
|
||||
CoreProxy.proxy.addName(autoWorkbenchBlock, "Automatic Crafting Table");
|
||||
}
|
||||
if (frameId > 0) {
|
||||
frameBlock = new BlockFrame(frameId);
|
||||
CoreProxy.proxy.registerBlock(frameBlock.setUnlocalizedName("frameBlock"));
|
||||
CoreProxy.proxy.addName(frameBlock, "Frame");
|
||||
}
|
||||
if (quarryId > 0) {
|
||||
quarryBlock = new BlockQuarry(quarryId);
|
||||
CoreProxy.proxy.registerBlock(quarryBlock.setUnlocalizedName("machineBlock"));
|
||||
CoreProxy.proxy.addName(quarryBlock, "Quarry");
|
||||
}
|
||||
if (tankId > 0) {
|
||||
tankBlock = new BlockTank(tankId);
|
||||
CoreProxy.proxy.registerBlock(tankBlock.setUnlocalizedName("tankBlock"));
|
||||
CoreProxy.proxy.addName(tankBlock, "Tank");
|
||||
}
|
||||
if (pumpId > 0) {
|
||||
pumpBlock = new BlockPump(pumpId);
|
||||
CoreProxy.proxy.registerBlock(pumpBlock.setUnlocalizedName("pumpBlock"));
|
||||
CoreProxy.proxy.addName(pumpBlock, "Pump");
|
||||
}
|
||||
// if (pumpId > 0) {
|
||||
// floodGateBlock = new BlockFloodGate(pumpId);
|
||||
// CoreProxy.proxy.registerBlock(pumpBlock.setUnlocalizedName("pumpBlock"));
|
||||
// CoreProxy.proxy.addName(pumpBlock, "Pump");
|
||||
// }
|
||||
if (refineryId > 0) {
|
||||
refineryBlock = new BlockRefinery(refineryId);
|
||||
CoreProxy.proxy.registerBlock(refineryBlock.setUnlocalizedName("refineryBlock"));
|
||||
CoreProxy.proxy.addName(refineryBlock, "Refinery");
|
||||
}
|
||||
if (hopperId > 0) {
|
||||
hopperBlock = new BlockHopper(hopperId);
|
||||
CoreProxy.proxy.registerBlock(hopperBlock.setUnlocalizedName("blockHopper"));
|
||||
CoreProxy.proxy.addName(hopperBlock, "Hopper");
|
||||
}
|
||||
|
||||
FactoryProxy.proxy.initializeEntityRenders();
|
||||
if (BuildCraftCore.mainConfiguration.hasChanged())
|
||||
{
|
||||
BuildCraftCore.mainConfiguration.save();
|
||||
if (BuildCraftCore.mainConfiguration.hasChanged()) {
|
||||
BuildCraftCore.mainConfiguration.save();
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -222,54 +230,91 @@ public class BuildCraftFactory {
|
|||
public static void loadRecipes() {
|
||||
|
||||
if (allowMining) {
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(miningWellBlock, 1), new Object[] { "ipi", "igi", "iPi", Character.valueOf('p'), Item.redstone,
|
||||
Character.valueOf('i'), Item.ingotIron, Character.valueOf('g'), BuildCraftCore.ironGearItem, Character.valueOf('P'), Item.pickaxeIron });
|
||||
if (miningWellBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(miningWellBlock, 1),
|
||||
"ipi",
|
||||
"igi",
|
||||
"iPi",
|
||||
'p', Item.redstone,
|
||||
'i', Item.ingotIron,
|
||||
'g', BuildCraftCore.ironGearItem,
|
||||
'P', Item.pickaxeIron);
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(
|
||||
new ItemStack(quarryBlock),
|
||||
new Object[] { "ipi", "gig", "dDd", Character.valueOf('i'), BuildCraftCore.ironGearItem, Character.valueOf('p'), Item.redstone,
|
||||
Character.valueOf('g'), BuildCraftCore.goldGearItem, Character.valueOf('d'), BuildCraftCore.diamondGearItem,
|
||||
Character.valueOf('D'), Item.pickaxeDiamond, });
|
||||
if (quarryBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(
|
||||
new ItemStack(quarryBlock),
|
||||
"ipi",
|
||||
"gig",
|
||||
"dDd",
|
||||
'i', BuildCraftCore.ironGearItem,
|
||||
'p', Item.redstone,
|
||||
'g', BuildCraftCore.goldGearItem,
|
||||
'd', BuildCraftCore.diamondGearItem,
|
||||
'D', Item.pickaxeDiamond);
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock), new Object[] { "T ", "W ", Character.valueOf('T'), tankBlock, Character.valueOf('W'),
|
||||
miningWellBlock, });
|
||||
}
|
||||
else {
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock), new Object[] { "iri", "iTi", "gpg",
|
||||
Character.valueOf('r'), Item.redstone,
|
||||
Character.valueOf('i'), Item.ingotIron,
|
||||
Character.valueOf('T'), tankBlock,
|
||||
Character.valueOf('g'), BuildCraftCore.ironGearItem,
|
||||
Character.valueOf('p'), BuildCraftTransport.pipeFluidsGold });
|
||||
if (pumpBlock != null && miningWellBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock),
|
||||
"T",
|
||||
"W",
|
||||
'T', tankBlock != null ? tankBlock : Block.glass,
|
||||
'W', miningWellBlock);
|
||||
}
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(autoWorkbenchBlock), new Object[] { " g ", "gwg", " g ", Character.valueOf('w'), Block.workbench,
|
||||
Character.valueOf('g'), BuildCraftCore.woodenGearItem });
|
||||
if (!allowMining || miningWellBlock == null) {
|
||||
if (pumpBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock),
|
||||
"iri",
|
||||
"iTi",
|
||||
"gpg",
|
||||
'r', Item.redstone,
|
||||
'i', Item.ingotIron,
|
||||
'T', tankBlock != null ? tankBlock : Block.glass,
|
||||
'g', BuildCraftCore.ironGearItem,
|
||||
'p', BuildCraftTransport.pipeFluidsGold);
|
||||
}
|
||||
|
||||
if (autoWorkbenchBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(autoWorkbenchBlock),
|
||||
" g ",
|
||||
"gwg",
|
||||
" g ",
|
||||
'w', Block.workbench,
|
||||
'g', BuildCraftCore.woodenGearItem);
|
||||
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(tankBlock), new Object[] { "ggg", "g g", "ggg", Character.valueOf('g'), Block.glass, });
|
||||
if (tankBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(tankBlock),
|
||||
"ggg",
|
||||
"g g",
|
||||
"ggg",
|
||||
'g', Block.glass);
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(
|
||||
new ItemStack(refineryBlock),
|
||||
new Object[] { " ", "RTR", "TGT", Character.valueOf('T'), tankBlock, Character.valueOf('G'), BuildCraftCore.diamondGearItem,
|
||||
Character.valueOf('R'), Block.torchRedstoneActive, });
|
||||
if (!hopperDisabled) {
|
||||
if (refineryBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(refineryBlock),
|
||||
"RTR",
|
||||
"TGT",
|
||||
'T', tankBlock != null ? tankBlock : Block.glass,
|
||||
'G', BuildCraftCore.diamondGearItem,
|
||||
'R', Block.torchRedstoneActive);
|
||||
|
||||
if (hopperBlock != null)
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(hopperBlock),
|
||||
new Object[] { "ICI", "IGI", " I ", Character.valueOf('I'), Item.ingotIron, Character.valueOf('C'), Block.chest, Character.valueOf('G'),
|
||||
BuildCraftCore.stoneGearItem });
|
||||
}
|
||||
|
||||
"ICI",
|
||||
"IGI",
|
||||
" I ",
|
||||
'I', Item.ingotIron,
|
||||
'C', Block.chest,
|
||||
'G', BuildCraftCore.stoneGearItem);
|
||||
}
|
||||
|
||||
|
||||
@ForgeSubscribe
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void loadTextures(TextureStitchEvent.Pre evt) {
|
||||
if (evt.map.textureType == 0) {
|
||||
TextureMap terrainTextures = evt.map;
|
||||
FactoryProxyClient.pumpTexture = terrainTextures.registerIcon("buildcraft:pump_tube");
|
||||
FactoryProxyClient.drillTexture = terrainTextures.registerIcon("buildcraft:blockDrillTexture");
|
||||
FactoryProxyClient.drillHeadTexture = terrainTextures.registerIcon("buildcraft:blockDrillHeadTexture");
|
||||
}
|
||||
if (evt.map.textureType == 0) {
|
||||
TextureMap terrainTextures = evt.map;
|
||||
FactoryProxyClient.pumpTexture = terrainTextures.registerIcon("buildcraft:pump_tube");
|
||||
FactoryProxyClient.drillTexture = terrainTextures.registerIcon("buildcraft:blockDrillTexture");
|
||||
FactoryProxyClient.drillHeadTexture = terrainTextures.registerIcon("buildcraft:blockDrillHeadTexture");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,12 +120,12 @@ public class CoreProxy {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addCraftingRecipe(ItemStack result, Object[] recipe) {
|
||||
public void addCraftingRecipe(ItemStack result, Object... recipe) {
|
||||
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(result, recipe));
|
||||
//GameRegistry.addRecipe(result, recipe);
|
||||
}
|
||||
|
||||
public void addShapelessRecipe(ItemStack result, Object[] recipe) {
|
||||
public void addShapelessRecipe(ItemStack result, Object... recipe) {
|
||||
GameRegistry.addShapelessRecipe(result, recipe);
|
||||
}
|
||||
|
||||
|
|
98
common/buildcraft/factory/BlockFloodGate.java
Normal file
98
common/buildcraft/factory/BlockFloodGate.java
Normal file
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 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.factory;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.core.CreativeTabBuildCraft;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockPump extends BlockContainer {
|
||||
|
||||
private Icon textureTop;
|
||||
private Icon textureBottom;
|
||||
private Icon textureSide;
|
||||
|
||||
public BlockPump(int i) {
|
||||
super(i, Material.iron);
|
||||
setHardness(5F);
|
||||
setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1) {
|
||||
return new TilePump();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(int i, int j) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return textureBottom;
|
||||
case 1:
|
||||
return textureTop;
|
||||
default:
|
||||
return textureSide;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
|
||||
Utils.preDestroyBlock(world, x, y, z);
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
|
||||
TileEntity tile = world.getBlockTileEntity(i, j, k);
|
||||
|
||||
if (tile instanceof TilePump) {
|
||||
TilePump pump = (TilePump) tile;
|
||||
|
||||
// Drop through if the player is sneaking
|
||||
if (entityplayer.isSneaking())
|
||||
return false;
|
||||
|
||||
// Restart the quarry if its a wrench
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
|
||||
|
||||
pump.tank.reset();
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void addCreativeItems(ArrayList itemList) {
|
||||
itemList.add(new ItemStack(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister par1IconRegister) {
|
||||
textureTop = par1IconRegister.registerIcon("buildcraft:pump_top");
|
||||
textureBottom = par1IconRegister.registerIcon("buildcraft:pump_bottom");
|
||||
textureSide = par1IconRegister.registerIcon("buildcraft:pump_side");
|
||||
}
|
||||
}
|
407
common/buildcraft/factory/TileFloodGate.java
Normal file
407
common/buildcraft/factory/TileFloodGate.java
Normal file
|
@ -0,0 +1,407 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 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.factory;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.EntityBlock;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.liquids.SingleUseTank;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadStream;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor, IFluidHandler {
|
||||
|
||||
public static int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 16;
|
||||
EntityBlock tube;
|
||||
private TreeMap<Integer, Deque<BlockIndex>> pumpLayerQueues = new TreeMap<Integer, Deque<BlockIndex>>();
|
||||
SingleUseTank tank;
|
||||
double tubeY = Double.NaN;
|
||||
int aimY = 0;
|
||||
private PowerHandler powerHandler;
|
||||
|
||||
public TilePump() {
|
||||
powerHandler = new PowerHandler(this, Type.MACHINE);
|
||||
initPowerProvider();
|
||||
tank = new SingleUseTank("tank", MAX_LIQUID);
|
||||
}
|
||||
|
||||
private void initPowerProvider() {
|
||||
powerHandler.configure(1, 8, 10, 100);
|
||||
powerHandler.configurePowerPerdition(1, 100);
|
||||
}
|
||||
|
||||
// TODO, manage this by different levels (pump what's above first...)
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (tube == null)
|
||||
return;
|
||||
|
||||
|
||||
if (CoreProxy.proxy.isRenderWorld(worldObj))
|
||||
return;
|
||||
|
||||
if (tube.posY - aimY > 0.01) {
|
||||
tubeY = tube.posY - 0.01;
|
||||
setTubePosition();
|
||||
sendNetworkUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldObj.getWorldTime() % 4 != 0)
|
||||
return;
|
||||
|
||||
BlockIndex index = getNextIndexToPump(false);
|
||||
|
||||
FluidStack fluidToPump = index != null ? Utils.drainBlock(worldObj, index.x, index.y, index.z, false) : null;
|
||||
if (fluidToPump != null) {
|
||||
if (isFluidAllowed(fluidToPump.getFluid()) && tank.fill(fluidToPump, false) == fluidToPump.amount) {
|
||||
|
||||
if (powerHandler.useEnergy(10, 10, true) == 10) {
|
||||
index = getNextIndexToPump(true);
|
||||
|
||||
if (fluidToPump.getFluid() != FluidRegistry.WATER || BuildCraftCore.consumeWaterSources) {
|
||||
Utils.drainBlock(worldObj, index.x, index.y, index.z, true);
|
||||
}
|
||||
|
||||
tank.fill(fluidToPump, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (worldObj.getWorldTime() % 128 == 0) {
|
||||
// TODO: improve that decision
|
||||
|
||||
initializePumpFromPosition(xCoord, aimY, zCoord);
|
||||
|
||||
if (getNextIndexToPump(false) == null) {
|
||||
for (int y = yCoord - 1; y > 0; --y) {
|
||||
if (isPumpableFluid(xCoord, y, zCoord)) {
|
||||
aimY = y;
|
||||
return;
|
||||
} else if (!worldObj.isAirBlock(xCoord, y, zCoord)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FluidStack liquid = tank.getFluid();
|
||||
if (liquid != null && liquid.amount >= 0) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
Position p = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[i]);
|
||||
p.moveForwards(1);
|
||||
|
||||
TileEntity tile = worldObj.getBlockTileEntity((int) p.x, (int) p.y, (int) p.z);
|
||||
|
||||
if (tile instanceof IFluidHandler) {
|
||||
int moved = ((IFluidHandler) tile).fill(p.orientation.getOpposite(), liquid, true);
|
||||
tank.drain(moved, true);
|
||||
if (liquid.amount <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
tube = FactoryProxy.proxy.newPumpTube(worldObj);
|
||||
|
||||
if (!Double.isNaN(tubeY)) {
|
||||
tube.posY = tubeY;
|
||||
} else {
|
||||
tube.posY = yCoord;
|
||||
}
|
||||
|
||||
tubeY = tube.posY;
|
||||
|
||||
if (aimY == 0) {
|
||||
aimY = yCoord;
|
||||
}
|
||||
|
||||
setTubePosition();
|
||||
|
||||
worldObj.spawnEntityInWorld(tube);
|
||||
|
||||
if (CoreProxy.proxy.isSimulating(worldObj)) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private BlockIndex getNextIndexToPump(boolean remove) {
|
||||
if (pumpLayerQueues.isEmpty())
|
||||
return null;
|
||||
|
||||
Deque<BlockIndex> topLayer = pumpLayerQueues.lastEntry().getValue();
|
||||
|
||||
if (topLayer != null) {
|
||||
if (topLayer.isEmpty())
|
||||
pumpLayerQueues.pollLastEntry();
|
||||
if (remove) {
|
||||
BlockIndex index = topLayer.removeLast();
|
||||
return index;
|
||||
}
|
||||
return topLayer.peekLast();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Deque<BlockIndex> getLayerQueue(int layer) {
|
||||
Deque<BlockIndex> pumpQueue = pumpLayerQueues.get(layer);
|
||||
if (pumpQueue == null) {
|
||||
pumpQueue = new LinkedList<BlockIndex>();
|
||||
pumpLayerQueues.put(layer, pumpQueue);
|
||||
}
|
||||
return pumpQueue;
|
||||
}
|
||||
|
||||
private void initializePumpFromPosition(int x, int y, int z) {
|
||||
Fluid pumpingFluid = getFluid(x, y, z);
|
||||
if(pumpingFluid == null)
|
||||
return;
|
||||
|
||||
if(pumpingFluid != tank.getAcceptedFluid() && tank.getAcceptedFluid() != null)
|
||||
return;
|
||||
|
||||
Set<BlockIndex> visitedBlocks = new HashSet<BlockIndex>();
|
||||
Deque<BlockIndex> fluidsFound = new LinkedList<BlockIndex>();
|
||||
|
||||
queueForPumping(x, y, z, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
|
||||
// long timeoutTime = System.nanoTime() + 10000;
|
||||
|
||||
while (!fluidsFound.isEmpty()) {
|
||||
Deque<BlockIndex> fluidsToExpand = fluidsFound;
|
||||
fluidsFound = new LinkedList<BlockIndex>();
|
||||
|
||||
for (BlockIndex index : fluidsToExpand) {
|
||||
queueForPumping(index.x + 1, index.y, index.z, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
queueForPumping(index.x - 1, index.y, index.z, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
queueForPumping(index.x, index.y, index.z + 1, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
queueForPumping(index.x, index.y, index.z - 1, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
|
||||
|
||||
queueForPumping(index.x, index.y + 1, index.z, visitedBlocks, fluidsFound, pumpingFluid);
|
||||
|
||||
// if (System.nanoTime() > timeoutTime)
|
||||
// return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void queueForPumping(int x, int y, int z, Set<BlockIndex> visitedBlocks, Deque<BlockIndex> fluidsFound, Fluid pumpingFluid) {
|
||||
BlockIndex index = new BlockIndex(x, y, z);
|
||||
if (visitedBlocks.add(index)) {
|
||||
if ((x - xCoord) * (x - xCoord) + (z - zCoord) * (z - zCoord) > 64 * 64)
|
||||
return;
|
||||
|
||||
Fluid fluid = getFluid(x, y, z);
|
||||
if (fluid == pumpingFluid) {
|
||||
getLayerQueue(y).add(index);
|
||||
fluidsFound.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPumpableFluid(int x, int y, int z) {
|
||||
return getFluid(x, y, z) != null;
|
||||
}
|
||||
|
||||
private Fluid getFluid(int x, int y, int z) {
|
||||
FluidStack fluidStack = Utils.drainBlock(worldObj, x, y, z, false);
|
||||
if (fluidStack == null)
|
||||
return null;
|
||||
|
||||
return isFluidAllowed(fluidStack.getFluid()) ? fluidStack.getFluid() : null;
|
||||
}
|
||||
|
||||
private boolean isFluidAllowed(Fluid fluid) {
|
||||
return BuildCraftFactory.pumpDimensionList.isFluidAllowed(fluid, worldObj.provider.dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
powerHandler.readFromNBT(data);
|
||||
tank.readFromNBT(data);
|
||||
|
||||
aimY = data.getInteger("aimY");
|
||||
tubeY = data.getFloat("tubeY");
|
||||
|
||||
initPowerProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
powerHandler.writeToNBT(data);
|
||||
tank.writeToNBT(data);
|
||||
|
||||
data.setInteger("aimY", aimY);
|
||||
|
||||
if (tube != null) {
|
||||
data.setFloat("tubeY", (float) tube.posY);
|
||||
} else {
|
||||
data.setFloat("tubeY", yCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
BlockIndex next = getNextIndexToPump(false);
|
||||
return isPumpableFluid(next.x, next.y, next.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayloadStream payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeInt(aimY);
|
||||
data.writeFloat((float) tubeY);
|
||||
}
|
||||
});
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
PacketPayloadStream payload = (PacketPayloadStream) packet.payload;
|
||||
DataInputStream data = payload.stream;
|
||||
aimY = data.readInt();
|
||||
tubeY = data.readFloat();
|
||||
|
||||
setTubePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException {
|
||||
handleUpdatePacket(packet);
|
||||
}
|
||||
|
||||
private void setTubePosition() {
|
||||
if (tube != null) {
|
||||
tube.iSize = Utils.pipeMaxPos - Utils.pipeMinPos;
|
||||
tube.kSize = Utils.pipeMaxPos - Utils.pipeMinPos;
|
||||
tube.jSize = yCoord - tube.posY;
|
||||
|
||||
tube.setPosition(xCoord + Utils.pipeMinPos, tubeY, zCoord + Utils.pipeMinPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (tube != null) {
|
||||
CoreProxy.proxy.removeEntity(tube);
|
||||
tube = null;
|
||||
tubeY = Double.NaN;
|
||||
aimY = 0;
|
||||
pumpLayerQueues.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageFluids() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageSolids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAction(IAction action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IFluidHandler implementation.
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
// not acceptable
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
if (resource != null && !resource.isFluidEqual(tank.getFluid()))
|
||||
return null;
|
||||
return drain(from, resource.amount, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return new FluidTankInfo[]{tank.getInfo()};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue