Skip to content

Commit

Permalink
1.6.2 port (continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flow86 committed Aug 14, 2013
1 parent 3fab47c commit a28e17b
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 447 deletions.
12 changes: 4 additions & 8 deletions common/abo/pipes/items/PipeItemsCompactorInventory.java
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.core.utils.Utils;
import buildcraft.core.inventory.InvUtils;

public class PipeItemsCompactorInventory {
private class InventorySlot {
Expand Down Expand Up @@ -101,16 +101,13 @@ public void addItemStack(World worldObj, ItemStack stack) {
*/
public void dropContents(World worldObj, int xCoord, int yCoord, int zCoord) {
for (InventorySlot inventorySlot : inventoryContents) {
Utils.dropItems(worldObj, inventorySlot.getItemStack(), xCoord, yCoord, zCoord);
InvUtils.dropItems(worldObj, inventorySlot.getItemStack(), xCoord, yCoord, zCoord);
}
inventoryContents.clear();
}

/**
* finds a stack in the list which fulfills on of these criteria:
* - stackSize is larger than stackSize
* - has not been changed since unchangedSince ticks
* - stack is full or not stackable
* finds a stack in the list which fulfills on of these criteria: - stackSize is larger than stackSize - has not been changed since unchangedSince ticks - stack is full or not stackable
*
* @param stackSize
* @param unchangedSince
Expand All @@ -120,8 +117,7 @@ public ItemStack findItemStackToRemove(World worldObj, int stackSize, int unchan
for (Iterator<InventorySlot> inventorySlots = inventoryContents.iterator(); inventorySlots.hasNext();) {
InventorySlot inventorySlot = inventorySlots.next();

if (inventorySlot.getItemStack().stackSize >= stackSize || inventorySlot.isItemStackFull()
|| inventorySlot.isNotModifiedSince(worldObj, unchangedSince)) {
if (inventorySlot.getItemStack().stackSize >= stackSize || inventorySlot.isItemStackFull() || inventorySlot.isNotModifiedSince(worldObj, unchangedSince)) {
inventorySlots.remove();
return inventorySlot.getItemStack();
}
Expand Down
36 changes: 31 additions & 5 deletions common/abo/pipes/items/PipeItemsCrossover.java
Expand Up @@ -12,25 +12,51 @@

package abo.pipes.items;

import java.util.LinkedList;

import net.minecraftforge.common.ForgeDirection;
import abo.PipeIconProvider;
import abo.pipes.ABOPipe;
import buildcraft.transport.pipes.PipeLogicStone;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;

/**
* This pipe will always prefer to use the opposite direction, so items will go
* "straight through"
* This pipe will always prefer to use the opposite direction, so items will go "straight through"
*
* @author blakmajik ported to BC > 2.2 by Flow86
*/
public class PipeItemsCrossover extends ABOPipe {
public class PipeItemsCrossover extends ABOPipe<PipeTransportItems> implements IPipeTransportItemsHook {

public PipeItemsCrossover(int itemID) {
super(new PipeTransportItemsCrossover(), new PipeLogicStone(), itemID);
super(new PipeTransportItems(), itemID);
}

@Override
public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsCrossover;
}

@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> list = new LinkedList<ForgeDirection>();

pos.moveForwards(1.0);
if (transport.canReceivePipeObjects(pos.orientation, item))
list.add(pos.orientation);
else
list = possibleOrientations;

return list;
}

@Override
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}

@Override
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
}
81 changes: 56 additions & 25 deletions common/abo/pipes/items/PipeItemsExtraction.java
Expand Up @@ -12,42 +12,38 @@

package abo.pipes.items;

import java.util.LinkedList;

import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import abo.ABO;
import abo.PipeIconProvider;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems;
import buildcraft.api.transport.IPipe;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.PipeConnectionBans;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.PipeItemsWood;
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/**
* This pipe will always prefer to insert it's objects into another pipe over
* one that is not a pipe.
* This pipe will always prefer to insert it's objects into another pipe over one that is not a pipe.
*
* @author Scott Chamberlain (Leftler) ported to BC > 2.2 by Flow86
*/
public class PipeItemsExtraction extends PipeItemsWood implements IPowerReceptor {
private final int baseTexture = PipeIconProvider.PipeItemsExtraction;
private final int sideTexture = PipeIconProvider.PipeItemsExtractionSide;
public class PipeItemsExtraction extends PipeItemsWood implements IPowerReceptor, IPipeTransportItemsHook {
private final int standardIconIndex = PipeIconProvider.PipeItemsExtraction;
private final int solidIconIndex = PipeIconProvider.PipeItemsExtractionSide;

public PipeItemsExtraction(int itemID) {
super(itemID, new PipeTransportItemsExtraction());

((PipeTransportItems) transport).allowBouncing = true;

// THIS IS DAMN UGLY - but I have no other chance to change logic
// afterwards :/
try {
ReflectionHelper.setPrivateValue(Pipe.class, this, new PipeLogicExtraction(), "logic");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
super(itemID);

PipeConnectionBans.banConnection(PipeItemsExtraction.class, PipeItemsWood.class);

transport.allowBouncing = true;
}

@Override
Expand All @@ -59,14 +55,49 @@ public IIconProvider getIconProvider() {
@Override
public int getIconIndex(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN)
return baseTexture;
return standardIconIndex;
else {
int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int metadata = container.getBlockMetadata();

if (metadata == direction.ordinal())
return sideTexture;
return solidIconIndex;
else
return standardIconIndex;
}
}

@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> nonPipesList = new LinkedList<ForgeDirection>();
LinkedList<ForgeDirection> pipesList = new LinkedList<ForgeDirection>();

item.blacklist.add(item.input.getOpposite());

return baseTexture;
for (ForgeDirection o : possibleOrientations) {
if (!item.blacklist.contains(o) && container.pipe.outputOpen(o)) {
if (transport.canReceivePipeObjects(o, item)) {

TileEntity entity = container.getTile(o);
if (entity instanceof IPipe)
pipesList.add(o);
else
nonPipesList.add(o);
}
}
}

if (!pipesList.isEmpty())
return pipesList;
else
return nonPipesList;
}

@Override
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}

@Override
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
}
52 changes: 46 additions & 6 deletions common/abo/pipes/items/PipeItemsInsertion.java
Expand Up @@ -12,28 +12,68 @@

package abo.pipes.items;

import java.util.LinkedList;

import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import abo.PipeIconProvider;
import abo.pipes.ABOPipe;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IPipe;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.pipes.PipeLogicStone;
import buildcraft.transport.TravelingItem;

/**
* This pipe will always prefer to insert it's objects into a tile that is not a
* pipe over another pipe.
* This pipe will always prefer to insert it's objects into a tile that is not a pipe over another pipe.
*
* @author Scott Chamberlain (Leftler) ported to BC > 2.2 by Flow86
*/
public class PipeItemsInsertion extends ABOPipe {
public class PipeItemsInsertion extends ABOPipe<PipeTransportItems> implements IPipeTransportItemsHook {

public PipeItemsInsertion(int itemID) {
super(new PipeTransportItemsInsertion(), new PipeLogicStone(), itemID);
super(new PipeTransportItems(), itemID);

((PipeTransportItems) transport).allowBouncing = true;
transport.allowBouncing = true;
}

@Override
public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsInsertion;
}

@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> nonPipesList = new LinkedList<ForgeDirection>();
LinkedList<ForgeDirection> pipesList = new LinkedList<ForgeDirection>();

item.blacklist.add(item.input.getOpposite());

for (ForgeDirection o : possibleOrientations) {
if (!item.blacklist.contains(o) && container.pipe.outputOpen(o)) {
if (transport.canReceivePipeObjects(o, item)) {

TileEntity entity = container.getTile(o);
if (entity instanceof IPipe)
pipesList.add(o);
else
nonPipesList.add(o);
}
}
}

if (!nonPipesList.isEmpty())
return nonPipesList;

return pipesList;
}

@Override
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}

@Override
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
}
49 changes: 46 additions & 3 deletions common/abo/pipes/items/PipeItemsRoundRobin.java
Expand Up @@ -12,23 +12,66 @@

package abo.pipes.items;

import java.util.LinkedList;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import abo.PipeIconProvider;
import abo.pipes.ABOPipe;
import buildcraft.transport.pipes.PipeLogicStone;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;

/**
* @author Flow86
*
*/
public class PipeItemsRoundRobin extends ABOPipe {
public class PipeItemsRoundRobin extends ABOPipe<PipeTransportItems> implements IPipeTransportItemsHook {
private int lastOrientation = 0;

public PipeItemsRoundRobin(int itemID) {
super(new PipeTransportItemsRoundRobin(), new PipeLogicStone(), itemID);
super(new PipeTransportItems(), itemID);
}

@Override
public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsRoundRobin;
}

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);

lastOrientation = nbttagcompound.getInteger("lastOrientation");
}

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);

nbttagcompound.setInteger("lastOrientation", lastOrientation);
}

@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
if (possibleOrientations.size() == 0) {
return new LinkedList();
} else {
lastOrientation = (lastOrientation + 1) % possibleOrientations.size();

LinkedList<ForgeDirection> newPossibleOrientations = new LinkedList();
newPossibleOrientations.add(possibleOrientations.get(lastOrientation));
return newPossibleOrientations;
}
}

@Override
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}

@Override
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
}

0 comments on commit a28e17b

Please sign in to comment.