-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipeItemsDiamond.java
160 lines (136 loc) · 5.01 KB
/
PipeItemsDiamond.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* 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
* granted by the copyright holder.
*/
package buildcraft.transport.pipes;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.network.IClientState;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IPipeTransportItemsHook, IClientState {
private SimpleInventory filters = new SimpleInventory(54, "Filters", 1);
public PipeItemsDiamond(int itemID) {
super(new PipeTransportItems(), itemID);
}
public IInventory getFilters() {
return filters;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return BuildCraftTransport.instance.pipeIconProvider;
}
@Override
public int getIconIndex(ForgeDirection direction) {
switch (direction) {
case UNKNOWN:
return PipeIconProvider.TYPE.PipeItemsDiamond_Center.ordinal();
case DOWN:
return PipeIconProvider.TYPE.PipeItemsDiamond_Down.ordinal();
case UP:
return PipeIconProvider.TYPE.PipeItemsDiamond_Up.ordinal();
case NORTH:
return PipeIconProvider.TYPE.PipeItemsDiamond_North.ordinal();
case SOUTH:
return PipeIconProvider.TYPE.PipeItemsDiamond_South.ordinal();
case WEST:
return PipeIconProvider.TYPE.PipeItemsDiamond_West.ordinal();
case EAST:
return PipeIconProvider.TYPE.PipeItemsDiamond_East.ordinal();
default:
throw new IllegalArgumentException("direction out of bounds");
}
}
@Override
public boolean blockActivated(EntityPlayer entityplayer) {
if (entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID < Block.blocksList.length)
if (Block.blocksList[entityplayer.getCurrentEquippedItem().itemID] instanceof BlockGenericPipe)
return false;
if (!CoreProxy.proxy.isRenderWorld(container.worldObj)) {
entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_DIAMOND, container.worldObj, container.xCoord, container.yCoord, container.zCoord);
}
return true;
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> filteredOrientations = new LinkedList<ForgeDirection>();
LinkedList<ForgeDirection> defaultOrientations = new LinkedList<ForgeDirection>();
// Filtered outputs
for (ForgeDirection dir : possibleOrientations) {
boolean foundFilter = false;
// NB: if there's several of the same match, the probability
// to use that filter is higher, this is why there are
// no breaks here.
for (int slot = 0; slot < 9; ++slot) {
ItemStack filter = getFilters().getStackInSlot(dir.ordinal() * 9 + slot);
if (filter != null)
foundFilter = true;
if (StackHelper.instance().isMatchingItem(filter, item.getItemStack(), true, false))
filteredOrientations.add(dir);
}
if (!foundFilter)
defaultOrientations.add(dir);
}
if (!filteredOrientations.isEmpty())
return filteredOrientations;
return defaultOrientations;
}
@Override
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}
@Override
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
filters.readFromNBT(nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
filters.writeToNBT(nbt);
}
// ICLIENTSTATE
@Override
public void writeData(DataOutputStream data) throws IOException {
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
NBTBase.writeNamedTag(nbt, data);
}
@Override
public void readData(DataInputStream data) throws IOException {
NBTBase nbt = NBTBase.readNamedTag(data);
if (nbt instanceof NBTTagCompound) {
readFromNBT((NBTTagCompound) nbt);
}
}
}