Skip to content

Commit

Permalink
Changed output to depend on the side the upgrade was clicked on inste…
Browse files Browse the repository at this point in the history
…ad of cycling through the 6 sides
  • Loading branch information
Tombenpotter committed Feb 28, 2015
1 parent db82945 commit ce01bb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
ItemStack stack = player.getHeldItem().copy();
stack.stackSize = 1;
tile.setInventorySlotContents(2, stack);
tile.sideToOutput = side;
if (!player.capabilities.isCreativeMode) player.inventory.consumeInventoryItem(stack.getItem());
world.markBlockForUpdate(x, y, z);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraftforge.common.util.ForgeDirection;
import tombenpotter.sanguimancy.api.tile.TileBaseSidedInventory;
import tombenpotter.sanguimancy.util.SanguimancyItemStacks;

public class TileAltarManipulator extends TileBaseSidedInventory {

public int sideToOutput;

public TileAltarManipulator() {
slots = new ItemStack[3];
customNBTTag = new NBTTagCompound();
sideToOutput = 0;
}

@Override
Expand Down Expand Up @@ -126,20 +127,31 @@ public void moveItemsFromAltar(TEAltar altar) {
}

public void outputToAdjacentInventory() {
if (getStackInSlot(2) != null && getStackInSlot(2).isItemEqual(SanguimancyItemStacks.sanguineShifter)) {
ItemStack stack = getStackInSlot(1).copy();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if (tile != null && tile instanceof IInventory && !(tile instanceof TEAltar) && !(tile instanceof TileEntityHopper)) {
IInventory inventory = (IInventory) tile;
if (inventory.getSizeInventory() <= 0) return;
SpellHelper.insertStackIntoInventory(stack, inventory, ForgeDirection.UNKNOWN);
setInventorySlotContents(1, null);
}
ItemStack stack = getStackInSlot(1).copy();
ForgeDirection dir = ForgeDirection.getOrientation(sideToOutput);
if (dir != ForgeDirection.DOWN) {
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if (tile != null && tile instanceof IInventory) {
IInventory inventory = (IInventory) tile;
if (inventory.getSizeInventory() <= 0) return;
SpellHelper.insertStackIntoInventory(stack, inventory, ForgeDirection.UNKNOWN);
setInventorySlotContents(1, null);
}
}
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
sideToOutput = tagCompound.getInteger("sideToOutput");
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setInteger("sideToOutput", sideToOutput);
}

@Override
public int[] getAccessibleSlotsFromSide(int var1) {
ForgeDirection dir = ForgeDirection.getOrientation(var1);
Expand Down

0 comments on commit ce01bb1

Please sign in to comment.