port all pipes but two: wooden item pipe and wooden power pipe

This commit is contained in:
asiekierka 2014-09-03 19:47:22 +02:00
parent 95e77f77c3
commit f477d66b00
3 changed files with 134 additions and 69 deletions

View file

@ -8,30 +8,27 @@
*/
package buildcraft.transport.pipes;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.NetworkData;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeManager;
import buildcraft.core.RFBattery;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportFluids;
public class PipeFluidsWood extends Pipe<PipeTransportFluids> {
public class PipeFluidsWood extends Pipe<PipeTransportFluids> implements IEnergyHandler {
@NetworkData
public int liquidToExtract;
@ -40,8 +37,7 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> {
private long lastMining = 0;
private boolean lastPower = false;
@MjBattery(maxCapacity = 250, maxReceivedPerCycle = 100, minimumConsumption = 0)
private double mjStored = 0;
private RFBattery battery = new RFBattery(2500, 1000, 0);
private PipeLogicWood logic = new PipeLogicWood(this) {
@Override
@ -108,7 +104,7 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> {
}
}
if (mjStored >= 1) {
if (battery.useEnergy(10, 10, false) > 0) {
if (meta > 5) {
return;
}
@ -126,7 +122,6 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> {
liquidToExtract += FluidContainerRegistry.BUCKET_VOLUME;
}
}
mjStored -= 1;
}
}
@ -156,4 +151,31 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> {
int meta = container.getBlockMetadata();
return super.outputOpen(to) && meta != to.ordinal();
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive,
boolean simulate) {
return battery.receiveEnergy(maxReceive, simulate);
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract,
boolean simulate) {
return 0;
}
@Override
public int getEnergyStored(ForgeDirection from) {
return battery.getEnergyStored();
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return battery.getMaxEnergyStored();
}
}

View file

@ -11,6 +11,7 @@ package buildcraft.transport.pipes;
import java.util.Arrays;
import java.util.List;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityMinecartChest;
@ -19,16 +20,13 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.RFBattery;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.StackFilter;
@ -40,10 +38,8 @@ import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.events.PipeEventItem;
import buildcraft.transport.utils.TransportUtils;
public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
@MjBattery (maxCapacity = 256, maxReceivedPerCycle = 64, minimumConsumption = 0)
private double mjStored = 0;
public class PipeItemsObsidian extends Pipe<PipeTransportItems> implements IEnergyHandler {
private RFBattery battery = new RFBattery(2560, 640, 0);
private int[] entitiesDropped;
private int entitiesDroppedIndex = 0;
@ -149,14 +145,14 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
public void updateEntity () {
super.updateEntity();
if (mjStored > 0) {
if (battery.getEnergyStored() > 0) {
for (int j = 1; j < 5; ++j) {
if (suckItem(j)) {
return;
}
}
mjStored = mjStored > 0.5 ? mjStored - 0.5 : 0;
battery.useEnergy(0, 5, false);
}
}
@ -182,8 +178,7 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
ForgeDirection openOrientation = getOpenOrientation();
ItemStack stack = trans.remove(StackFilter.ALL, openOrientation, false);
if (stack != null && mjStored >= 1) {
mjStored -= 1;
if (stack != null && battery.useEnergy(10, 10, false) > 0) {
trans.remove(StackFilter.ALL, openOrientation, true);
EntityItem entityitem = new EntityItem(container.getWorldObj(), cart.posX, cart.posY + 0.3F, cart.posZ, stack);
entityitem.delayBeforeCanPickup = 10;
@ -219,8 +214,10 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
CoreProxy.proxy.obsidianPipePickup(container.getWorldObj(), item, this.container);
double energyUsed = mjStored > contained.stackSize * distance ? contained.stackSize * distance : mjStored;
int energyUsed = (int)Math.min(10 * contained.stackSize * distance, battery.getEnergyStored());
// TODO: Why is energyUsed never used here?
if (distance == 0 || energyUsed / distance == contained.stackSize) {
stack = contained;
CoreProxy.proxy.removeEntity(entity);
@ -234,8 +231,7 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
if (speed < 0.01) {
speed = 0.01;
}
} else if (entity instanceof EntityArrow) {
mjStored -= distance;
} else if (entity instanceof EntityArrow && battery.useEnergy(distance * 10, distance * 10, false) > 0) {
stack = new ItemStack(Items.arrow, 1);
CoreProxy.proxy.removeEntity(entity);
}
@ -274,11 +270,38 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> {
}
}
return mjStored >= distance;
return battery.getEnergyStored() >= distance * 10;
} else if (entity instanceof EntityArrow) {
EntityArrow arrow = (EntityArrow) entity;
return arrow.canBePickedUp == 1 && mjStored >= distance;
return arrow.canBePickedUp == 1 && battery.getEnergyStored() >= distance * 10;
}
return false;
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive,
boolean simulate) {
return battery.receiveEnergy(maxReceive, simulate);
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract,
boolean simulate) {
return 0;
}
@Override
public int getEnergyStored(ForgeDirection from) {
return battery.getEnergyStored();
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return battery.getMaxEnergyStored();
}
}

View file

@ -10,6 +10,7 @@ package buildcraft.transport.pipes;
import java.util.ArrayList;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.entity.player.EntityPlayer;
@ -23,13 +24,10 @@ import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil;
import buildcraft.transport.BlockGenericPipe;
@ -42,11 +40,7 @@ import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.events.PipeEventItem;
import buildcraft.transport.utils.TransportUtils;
public class PipeItemsStripes extends Pipe<PipeTransportItems> {
@MjBattery(maxCapacity = 1, maxReceivedPerCycle = 1, minimumConsumption = 0)
private double mjStored = 0;
public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnergyHandler {
public PipeItemsStripes(Item item) {
super(new PipeTransportItems(), item);
}
@ -58,40 +52,6 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
if (container.getWorldObj().isRemote) {
return;
}
if (mjStored > 0) {
ForgeDirection o = getOpenOrientation();
if (o != ForgeDirection.UNKNOWN) {
Position p = new Position(container.xCoord, container.yCoord,
container.zCoord, o);
p.moveForwards(1.0);
if (!BlockUtil.isUnbreakableBlock(getWorld(), (int) p.x, (int) p.y, (int) p.z)) {
ArrayList<ItemStack> stacks = getWorld().getBlock(
(int) p.x, (int) p.y, (int) p.z).getDrops(
getWorld(),
(int) p.x,
(int) p.y,
(int) p.z,
getWorld().getBlockMetadata((int) p.x, (int) p.y,
(int) p.z), 0
);
if (stacks != null) {
for (ItemStack s : stacks) {
if (s != null) {
rollbackItem(s, o);
}
}
}
getWorld().setBlockToAir((int) p.x, (int) p.y, (int) p.z);
}
}
}
mjStored = 0;
}
public void eventHandler(PipeEventItem.DropItem event) {
@ -269,4 +229,64 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
return super.canPipeConnect(tile, side);
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive,
boolean simulate) {
if(maxReceive == 0) return 0;
else if(simulate) return 10;
ForgeDirection o = getOpenOrientation();
if (o != ForgeDirection.UNKNOWN) {
Position p = new Position(container.xCoord, container.yCoord,
container.zCoord, o);
p.moveForwards(1.0);
if (!BlockUtil.isUnbreakableBlock(getWorld(), (int) p.x, (int) p.y, (int) p.z)) {
ArrayList<ItemStack> stacks = getWorld().getBlock(
(int) p.x, (int) p.y, (int) p.z).getDrops(
getWorld(),
(int) p.x,
(int) p.y,
(int) p.z,
getWorld().getBlockMetadata((int) p.x, (int) p.y,
(int) p.z), 0
);
if (stacks != null) {
for (ItemStack s : stacks) {
if (s != null) {
rollbackItem(s, o);
}
}
}
getWorld().setBlockToAir((int) p.x, (int) p.y, (int) p.z);
}
}
return maxReceive;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract,
boolean simulate) {
return 0;
}
@Override
public int getEnergyStored(ForgeDirection from) {
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return 10;
}
}