-
Notifications
You must be signed in to change notification settings - Fork 755
/
SpecialStackHandler.java
110 lines (92 loc) · 3.09 KB
/
SpecialStackHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package tconstruct.util.landmine.behavior.stackCombo;
import java.util.ArrayList;
import java.util.List;
import tconstruct.blocks.logic.TileEntityLandmine;
import tconstruct.util.landmine.Helper;
import tconstruct.util.landmine.behavior.Behavior;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/**
*
* @author fuj1n
*
*/
public abstract class SpecialStackHandler
{
public static ArrayList<SpecialStackHandler> handlers = new ArrayList<SpecialStackHandler>();
public static void registerBuiltInStackHandlers ()
{
addSpecialBehavior(new SpecialStackHandlerRocketFireball());
}
public static void addSpecialBehavior (SpecialStackHandler handler)
{
if (!handlers.contains(handler))
{
handlers.add(handler);
}
}
public abstract void checkStack (World par1World, int par2, int par3, int par4, Entity triggerer, ArrayList<ItemStack> stacks);
public EnumFacing getFacing (World par1World, int par2, int par3, int par4)
{
ForgeDirection dir = Helper.convertMetaToForgeOrientation(par1World.getBlockMetadata(par2, par3, par4));
switch (dir)
{
case DOWN:
return EnumFacing.UP;
case UP:
return EnumFacing.DOWN;
case WEST:
return EnumFacing.WEST;
case EAST:
return EnumFacing.EAST;
case SOUTH:
return EnumFacing.NORTH;
case NORTH:
return EnumFacing.SOUTH;
default:
return EnumFacing.UP;
}
}
public final void removeItemFromInventory (World par1World, int x, int y, int z, ItemStack item)
{
if (item == null || item.stackSize <= 0)
{
return;
}
TileEntityLandmine tileEntity = (TileEntityLandmine) par1World.func_147438_o(x, y, z);
while (item.stackSize > 0)
{
boolean hasRemovedThisIteration = false;
for (int i = 0; i < tileEntity.getSizeTriggerInventory(); i++)
{
if (!hasRemovedThisIteration && tileEntity.getStackInSlot(i) != null)
{
if (tileEntity.getStackInSlot(i).isItemEqual(item))
{
tileEntity.decrStackSize(i, 1);
item.stackSize--;
}
}
if (!hasRemovedThisIteration && i == tileEntity.getSizeTriggerInventory() - 1)
{
item.stackSize--;
}
}
}
}
public static final int arrayIndexOfStack (ArrayList<ItemStack> stacks, ItemStack item)
{
return Behavior.arrayIndexOfStack(stacks, item);
}
public static final boolean arrayContainsEqualStack (ArrayList<ItemStack> stacks, ItemStack item)
{
return Behavior.arrayContainsEqualStack(stacks, item);
}
public boolean isOffensive (ArrayList<ItemStack> par1ArrayList)
{
return true;
}
}