Rewrite Iron/Wood logic into helper classes
This commit is contained in:
parent
4dbd28a0dc
commit
1860ebc300
10 changed files with 246 additions and 143 deletions
|
@ -250,13 +250,15 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
|||
}
|
||||
private boolean initialized = false;
|
||||
|
||||
public boolean needsInit() {
|
||||
return !initialized;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
if (!initialized) {
|
||||
transport.initialize();
|
||||
logic.initialize();
|
||||
initialized = true;
|
||||
updateSignalState();
|
||||
}
|
||||
transport.initialize();
|
||||
logic.initialize();
|
||||
updateSignalState();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private void readNearbyPipesSignal(WireColor color) {
|
||||
|
|
|
@ -287,7 +287,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
|||
computeConnections();
|
||||
scheduleRenderUpdate();
|
||||
|
||||
pipe.initialize();
|
||||
if (pipe.needsInit())
|
||||
pipe.initialize();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import buildcraft.transport.PipeTransportFluids;
|
|||
public class PipeFluidsEmerald extends PipeFluidsWood {
|
||||
|
||||
public PipeFluidsEmerald(int itemID) {
|
||||
super(new PipeLogicWood(), itemID);
|
||||
super(new PipeLogic(), itemID);
|
||||
|
||||
standardIconIndex = PipeIconProvider.TYPE.PipeFluidsEmerald_Standard.ordinal();
|
||||
solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal();
|
||||
|
|
|
@ -9,17 +9,12 @@ package buildcraft.transport.pipes;
|
|||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportFluids;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
@ -28,9 +23,49 @@ public class PipeFluidsIron extends Pipe {
|
|||
|
||||
protected int standardIconIndex = PipeIconProvider.TYPE.PipeFluidsIron_Standard.ordinal();
|
||||
protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();
|
||||
private PipeLogicIron logic = new PipeLogicIron(this) {
|
||||
@Override
|
||||
protected boolean isValidFacing(ForgeDirection facing) {
|
||||
TileEntity tile = pipe.container.getTile(facing);
|
||||
if (tile instanceof TileGenericPipe) {
|
||||
Pipe otherPipe = ((TileGenericPipe) tile).pipe;
|
||||
if (otherPipe instanceof PipeFluidsWood || otherPipe instanceof PipeStructureCobblestone)
|
||||
return false;
|
||||
if (otherPipe.transport instanceof PipeTransportFluids)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (tile instanceof IFluidHandler)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public PipeFluidsIron(int itemID) {
|
||||
super(new PipeTransportFluids(), new PipeLogicIron(), itemID);
|
||||
super(new PipeTransportFluids(), new PipeLogic(), itemID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
logic.onNeighborBlockChange(blockId);
|
||||
super.onNeighborBlockChange(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlaced() {
|
||||
logic.onBlockPlaced();
|
||||
super.onBlockPlaced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logic.initialize();
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
return logic.outputOpen(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ import buildcraft.transport.PipeIconProvider;
|
|||
import buildcraft.transport.PipeTransportFluids;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -37,9 +38,20 @@ public class PipeFluidsWood extends Pipe implements IPowerReceptor {
|
|||
protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
|
||||
long lastMining = 0;
|
||||
boolean lastPower = false;
|
||||
private PipeLogicWood logic = new PipeLogicWood(this) {
|
||||
@Override
|
||||
protected boolean isValidFacing(ForgeDirection facing) {
|
||||
TileEntity tile = pipe.container.getTile(facing);
|
||||
if (!(tile instanceof IFluidHandler))
|
||||
return false;
|
||||
if (!PipeManager.canExtractFluids(pipe, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public PipeFluidsWood(int itemID) {
|
||||
this(new PipeLogicWood(), itemID);
|
||||
this(new PipeLogic(), itemID);
|
||||
}
|
||||
|
||||
protected PipeFluidsWood(PipeLogic logic, int itemID) {
|
||||
|
@ -50,6 +62,23 @@ public class PipeFluidsWood extends Pipe implements IPowerReceptor {
|
|||
powerHandler.configurePowerPerdition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
return logic.blockActivated(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
logic.onNeighborBlockChange(blockId);
|
||||
super.onNeighborBlockChange(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logic.initialize();
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a random piece of item outside of a nearby chest.
|
||||
*/
|
||||
|
@ -131,4 +160,10 @@ public class PipeFluidsWood extends Pipe implements IPowerReceptor {
|
|||
return standardIconIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
int meta = container.getBlockMetadata();
|
||||
return super.outputOpen(to) && meta != to.ordinal();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
|
|||
private int currentFilter = 0;
|
||||
|
||||
protected PipeItemsEmerald(int itemID, PipeTransportItems transport) {
|
||||
super(transport, new PipeLogicWood(), itemID);
|
||||
super(transport, new PipeLogic(), itemID);
|
||||
|
||||
standardIconIndex = PipeIconProvider.TYPE.PipeItemsEmerald_Standard.ordinal();
|
||||
solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal();
|
||||
|
|
|
@ -1,33 +1,82 @@
|
|||
/**
|
||||
* 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.transport.pipes;
|
||||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class PipeItemsIron extends Pipe {
|
||||
|
||||
private int standardIconIndex = PipeIconProvider.TYPE.PipeItemsIron_Standard.ordinal();
|
||||
private int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();
|
||||
private PipeLogicIron logic = new PipeLogicIron(this) {
|
||||
@Override
|
||||
protected boolean isValidFacing(ForgeDirection facing) {
|
||||
TileEntity tile = pipe.container.getTile(facing);
|
||||
if (tile instanceof TileGenericPipe) {
|
||||
Pipe otherPipe = ((TileGenericPipe) tile).pipe;
|
||||
if (otherPipe instanceof PipeItemsWood || otherPipe instanceof PipeStructureCobblestone)
|
||||
return false;
|
||||
if (otherPipe.transport instanceof PipeTransportItems)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (tile instanceof IPipeEntry || tile instanceof IInventory)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public PipeItemsIron(int itemID) {
|
||||
super(new PipeTransportItems(), new PipeLogicIron(), itemID);
|
||||
super(new PipeTransportItems(), new PipeLogic(), itemID);
|
||||
|
||||
((PipeTransportItems) transport).allowBouncing = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
return logic.blockActivated(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
logic.onNeighborBlockChange(blockId);
|
||||
super.onNeighborBlockChange(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlaced() {
|
||||
logic.onBlockPlaced();
|
||||
super.onBlockPlaced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logic.initialize();
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
return logic.outputOpen(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconIndex(ForgeDirection direction) {
|
||||
if (direction == ForgeDirection.UNKNOWN)
|
||||
|
|
|
@ -25,6 +25,7 @@ import buildcraft.transport.PipeIconProvider;
|
|||
import buildcraft.transport.PipeTransportItems;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -36,6 +37,17 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
|||
protected PowerHandler powerHandler;
|
||||
protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal();
|
||||
protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
|
||||
private PipeLogicWood logic = new PipeLogicWood(this) {
|
||||
@Override
|
||||
protected boolean isValidFacing(ForgeDirection facing) {
|
||||
TileEntity tile = pipe.container.getTile(facing);
|
||||
if (!(tile instanceof IInventory))
|
||||
return false;
|
||||
if (!PipeManager.canExtractItems(pipe, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) {
|
||||
super(transport, logic, itemID);
|
||||
|
@ -46,13 +58,30 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
|||
}
|
||||
|
||||
protected PipeItemsWood(int itemID, PipeTransportItems transport) {
|
||||
this(transport, new PipeLogicWood(), itemID);
|
||||
this(transport, new PipeLogic(), itemID);
|
||||
}
|
||||
|
||||
public PipeItemsWood(int itemID) {
|
||||
this(itemID, new PipeTransportItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
return logic.blockActivated(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
logic.onNeighborBlockChange(blockId);
|
||||
super.onNeighborBlockChange(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logic.initialize();
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIconProvider getIconProvider() {
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* 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
|
||||
* 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.transport.pipes;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class PipeLogicIron extends PipeLogic {
|
||||
public abstract class PipeLogicIron {
|
||||
|
||||
boolean lastPower = false;
|
||||
private boolean lastPower = false;
|
||||
protected final Pipe pipe;
|
||||
|
||||
public PipeLogicIron(Pipe pipe) {
|
||||
this.pipe = pipe;
|
||||
}
|
||||
|
||||
private void switchPower() {
|
||||
boolean currentPower = container.worldObj.isBlockIndirectlyGettingPowered(container.xCoord, container.yCoord, container.zCoord);
|
||||
boolean currentPower = pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
|
||||
if (currentPower != lastPower) {
|
||||
switchPosition();
|
||||
|
@ -35,59 +33,39 @@ public class PipeLogicIron extends PipeLogic {
|
|||
}
|
||||
|
||||
private void switchPosition() {
|
||||
int metadata = container.worldObj.getBlockMetadata(container.xCoord, container.yCoord, container.zCoord);
|
||||
int meta = pipe.container.worldObj.getBlockMetadata(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
|
||||
int nextMetadata = metadata;
|
||||
ForgeDirection newFacing = null;
|
||||
|
||||
for (int l = 0; l < 6; ++l) {
|
||||
nextMetadata++;
|
||||
|
||||
if (nextMetadata > 5) {
|
||||
nextMetadata = 0;
|
||||
}
|
||||
|
||||
TileEntity tile = container.getTile(ForgeDirection.values()[nextMetadata]);
|
||||
|
||||
if (tile instanceof TileGenericPipe) {
|
||||
Pipe pipe = ((TileGenericPipe) tile).pipe;
|
||||
if (pipe.logic instanceof PipeLogicWood || pipe instanceof PipeStructureCobblestone) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof IPipeEntry || tile instanceof IInventory || tile instanceof IFluidHandler || tile instanceof TileGenericPipe) {
|
||||
|
||||
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, nextMetadata,0);
|
||||
container.scheduleRenderUpdate();
|
||||
return;
|
||||
for (ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (isValidFacing(facing)) {
|
||||
newFacing = facing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newFacing != null && newFacing.ordinal() != meta) {
|
||||
pipe.container.worldObj.setBlockMetadataWithNotify(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, newFacing.ordinal(), 3);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
protected abstract boolean isValidFacing(ForgeDirection facing);
|
||||
|
||||
lastPower = container.worldObj.isBlockIndirectlyGettingPowered(container.xCoord, container.yCoord, container.zCoord);
|
||||
public void initialize() {
|
||||
lastPower = pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlaced() {
|
||||
super.onBlockPlaced();
|
||||
|
||||
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, 1,0);
|
||||
pipe.container.worldObj.setBlockMetadataWithNotify(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, 1, 3);
|
||||
switchPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
super.blockActivated(entityplayer);
|
||||
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, container.xCoord, container.yCoord, container.zCoord)) {
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)) {
|
||||
switchPosition();
|
||||
container.worldObj.markBlockForUpdate(container.xCoord, container.yCoord, container.zCoord);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, container.xCoord, container.yCoord, container.zCoord);
|
||||
pipe.container.worldObj.markBlockForUpdate(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -95,16 +73,11 @@ public class PipeLogicIron extends PipeLogic {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
super.onNeighborBlockChange(blockId);
|
||||
|
||||
switchPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
return to.ordinal() == container.getBlockMetadata();
|
||||
return to.ordinal() == pipe.container.getBlockMetadata();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,98 +8,77 @@
|
|||
package buildcraft.transport.pipes;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.api.transport.PipeManager;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.Pipe;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class PipeLogicWood extends PipeLogic {
|
||||
public abstract class PipeLogicWood {
|
||||
|
||||
public void switchSource() {
|
||||
int meta = container.getBlockMetadata();
|
||||
int newMeta = 6;
|
||||
protected final Pipe pipe;
|
||||
|
||||
for (int i = meta + 1; i <= meta + 6; ++i) {
|
||||
ForgeDirection o = ForgeDirection.values()[i % 6];
|
||||
public PipeLogicWood(Pipe pipe) {
|
||||
this.pipe = pipe;
|
||||
}
|
||||
|
||||
TileEntity tile = container.getTile(o);
|
||||
private void switchSource() {
|
||||
int meta = pipe.container.getBlockMetadata();
|
||||
ForgeDirection newFacing = null;
|
||||
|
||||
if (isInput(tile))
|
||||
if (PipeManager.canExtractItems(container.getPipe(), tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord)
|
||||
|| PipeManager.canExtractFluids(container.getPipe(), tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord)) {
|
||||
newMeta = o.ordinal();
|
||||
break;
|
||||
}
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (isValidFacing(side)) {
|
||||
newFacing = side;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newMeta != meta) {
|
||||
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, newMeta, 0);
|
||||
container.scheduleRenderUpdate();
|
||||
// worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
if (newFacing != null && newFacing.ordinal() != meta) {
|
||||
pipe.container.worldObj.setBlockMetadataWithNotify(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, newFacing.ordinal(), 3);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInput(TileEntity tile) {
|
||||
return !(tile instanceof TileGenericPipe) && (tile instanceof IInventory || tile instanceof IFluidHandler)
|
||||
&& Utils.checkPipesConnections(container, tile);
|
||||
private void switchSourceIfNeeded() {
|
||||
int meta = pipe.container.getBlockMetadata();
|
||||
|
||||
if (meta > 5) {
|
||||
switchSource();
|
||||
} else {
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(meta);
|
||||
if (!isValidFacing(facing)) {
|
||||
switchSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isValidFacing(ForgeDirection facing);
|
||||
//
|
||||
// private boolean isInput(TileEntity tile) {
|
||||
// return !(tile instanceof TileGenericPipe) && (tile instanceof IInventory || tile instanceof IFluidHandler)
|
||||
// && Utils.checkPipesConnections(pipe.container, tile);
|
||||
// }
|
||||
|
||||
public void initialize() {
|
||||
if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) {
|
||||
switchSourceIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, container.xCoord, container.yCoord, container.zCoord)) {
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)) {
|
||||
switchSource();
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, container.xCoord, container.yCoord, container.zCoord);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
if (!CoreProxy.proxy.isRenderWorld(container.worldObj)) {
|
||||
switchSourceIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private void switchSourceIfNeeded() {
|
||||
int meta = container.getBlockMetadata();
|
||||
|
||||
if (meta > 5) {
|
||||
switchSource();
|
||||
} else {
|
||||
TileEntity tile = container.getTile(ForgeDirection.values()[meta]);
|
||||
|
||||
if (!isInput(tile)) {
|
||||
switchSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
super.onNeighborBlockChange(blockId);
|
||||
|
||||
if (!CoreProxy.proxy.isRenderWorld(container.worldObj)) {
|
||||
if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) {
|
||||
switchSourceIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
if (this.container.pipe instanceof PipeFluidsWood) {
|
||||
int meta = container.getBlockMetadata();
|
||||
return meta != to.ordinal();
|
||||
}
|
||||
return super.outputOpen(to);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue