|
5 | 5 |
|
6 | 6 | import k4unl.minecraft.Hydraulicraft.baseClasses.MachineEntity; |
7 | 7 | import k4unl.minecraft.Hydraulicraft.lib.config.Constants; |
8 | | -import net.minecraft.entity.item.EntityItem; |
9 | | -import net.minecraft.item.ItemStack; |
10 | 8 | import net.minecraft.nbt.NBTTagCompound; |
11 | 9 | import net.minecraft.tileentity.TileEntity; |
| 10 | +import net.minecraft.util.AxisAlignedBB; |
12 | 11 | import net.minecraftforge.common.ForgeDirection; |
13 | 12 |
|
14 | | -public abstract class TileTransporter extends MachineEntity { |
15 | | - private int storedLiquid = 0; |
16 | | - private Map<ForgeDirection, TileEntity> connectedSides; |
17 | | - |
18 | | - public TileTransporter() { |
19 | | - |
20 | | - } |
21 | | - |
22 | | - @Override |
23 | | - public void onBlockBreaks(){ |
24 | | - |
25 | | - } |
26 | | - |
27 | | - /*! |
28 | | - * @author Koen Beckers |
29 | | - * @date 14-12-2013 |
30 | | - * This will return the max ammount of bar this consumer can handle. |
31 | | - */ |
32 | | - @Override |
33 | | - public float getMaxPressure(){ |
34 | | - if(isOilStored()){ |
35 | | - switch(getTier()){ |
36 | | - case 0: |
37 | | - return Constants.MAX_MBAR_OIL_TIER_1; |
38 | | - case 1: |
39 | | - return Constants.MAX_MBAR_OIL_TIER_2; |
40 | | - case 2: |
41 | | - return Constants.MAX_MBAR_OIL_TIER_3; |
42 | | - } |
43 | | - }else{ |
44 | | - switch(getTier()){ |
45 | | - case 0: |
46 | | - return Constants.MAX_MBAR_WATER_TIER_1; |
47 | | - case 1: |
48 | | - return Constants.MAX_MBAR_WATER_TIER_2; |
49 | | - case 2: |
50 | | - return Constants.MAX_MBAR_WATER_TIER_3; |
51 | | - } |
52 | | - } |
53 | | - return 0; |
54 | | - } |
55 | | - |
56 | | - public int getTier(){ |
57 | | - return worldObj.getBlockMetadata(xCoord, yCoord, zCoord); |
58 | | - } |
59 | | - |
60 | | - |
61 | | - private boolean shouldConnectTo(TileEntity entity){ |
62 | | - return (entity instanceof MachineEntity); |
63 | | - } |
64 | | - |
65 | | - public void checkConnectedSides(){ |
66 | | - if(connectedSides == null){ |
67 | | - connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
68 | | - } |
69 | | - Map<ForgeDirection, TileEntity> retList = new HashMap<ForgeDirection, TileEntity>(); |
70 | | - |
71 | | - retList.put(ForgeDirection.WEST, getBlockTileEntity(xCoord+1, yCoord, zCoord)); |
72 | | - retList.put(ForgeDirection.EAST, getBlockTileEntity(xCoord-1, yCoord, zCoord)); |
73 | | - |
74 | | - retList.put(ForgeDirection.UP, getBlockTileEntity(xCoord, yCoord+1, zCoord)); |
75 | | - retList.put(ForgeDirection.DOWN, getBlockTileEntity(xCoord, yCoord-1, zCoord)); |
76 | | - |
77 | | - retList.put(ForgeDirection.NORTH, getBlockTileEntity(xCoord, yCoord, zCoord+1)); |
78 | | - retList.put(ForgeDirection.SOUTH, getBlockTileEntity(xCoord, yCoord, zCoord-1)); |
79 | | - |
80 | | - for(Map.Entry<ForgeDirection, TileEntity> entry : retList.entrySet()){ |
81 | | - if(shouldConnectTo(entry.getValue())){ |
82 | | - connectedSides.put(entry.getKey(), entry.getValue()); |
83 | | - } |
84 | | - } |
85 | 13 |
|
86 | | - updateBlock(); |
87 | | - } |
88 | | - |
89 | | - @Override |
90 | | - public void validate(){ |
91 | | - //super.validate(); |
92 | | - //checkConnectedSides(); |
93 | | - } |
94 | | - |
95 | | - public Map<ForgeDirection, TileEntity> getConnectedSides(){ |
96 | | - if(connectedSides == null){ |
97 | | - checkConnectedSides(); |
98 | | - } |
99 | | - return connectedSides; |
100 | | - } |
| 14 | +public abstract class TileTransporter extends MachineEntity{ |
| 15 | + private final int storedLiquid = 0; |
| 16 | + private Map<ForgeDirection, TileEntity> connectedSides; |
| 17 | + private final boolean[] connectedSideFlags = new boolean[6]; |
| 18 | + private boolean needToCheckNeighbors; |
101 | 19 |
|
| 20 | + public TileTransporter(){ |
102 | 21 |
|
103 | | - private void readConnectedSidesFromNBT(NBTTagCompound tagCompound){ |
104 | | - connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
105 | | - NBTTagCompound ourCompound = tagCompound.getCompoundTag |
106 | | - ("connectedSides"); |
107 | | - |
108 | | - for(ForgeDirection dir: ForgeDirection.VALID_DIRECTIONS){ |
109 | | - int x = xCoord; |
110 | | - int y = yCoord; |
111 | | - int z = zCoord; |
112 | | - |
113 | | - if(ourCompound.getBoolean(dir.toString())){ |
114 | | - if(dir == ForgeDirection.WEST){ |
115 | | - x+=1; |
116 | | - }else if(dir == ForgeDirection.EAST){ |
117 | | - x-=1; |
118 | | - } |
| 22 | + } |
119 | 23 |
|
120 | | - if(dir == ForgeDirection.UP){ |
121 | | - y+=1; |
122 | | - }else if(dir == ForgeDirection.DOWN){ |
123 | | - y-=1; |
| 24 | + @Override |
| 25 | + public void updateEntity(){ |
| 26 | + if(needToCheckNeighbors) { |
| 27 | + needToCheckNeighbors = false; |
| 28 | + connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
| 29 | + for(int i = 0; i < 6; i++) { |
| 30 | + if(connectedSideFlags[i]) { |
| 31 | + ForgeDirection dir = ForgeDirection.getOrientation(i); |
| 32 | + connectedSides.put(dir, getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)); |
124 | 33 | } |
| 34 | + } |
| 35 | + } |
| 36 | + super.updateEntity(); |
| 37 | + } |
125 | 38 |
|
126 | | - if(dir == ForgeDirection.NORTH){ |
127 | | - z+=1; |
128 | | - }else if(dir == ForgeDirection.SOUTH){ |
129 | | - z-=1; |
130 | | - } |
| 39 | + /*! |
| 40 | + * @author Koen Beckers |
| 41 | + * @date 14-12-2013 |
| 42 | + * This will return the max ammount of bar this consumer can handle. |
| 43 | + */ |
| 44 | + @Override |
| 45 | + public float getMaxPressure(){ |
| 46 | + if(isOilStored()) { |
| 47 | + switch(getTier()){ |
| 48 | + case 0: |
| 49 | + return Constants.MAX_MBAR_OIL_TIER_1; |
| 50 | + case 1: |
| 51 | + return Constants.MAX_MBAR_OIL_TIER_2; |
| 52 | + case 2: |
| 53 | + return Constants.MAX_MBAR_OIL_TIER_3; |
| 54 | + } |
| 55 | + } else { |
| 56 | + switch(getTier()){ |
| 57 | + case 0: |
| 58 | + return Constants.MAX_MBAR_WATER_TIER_1; |
| 59 | + case 1: |
| 60 | + return Constants.MAX_MBAR_WATER_TIER_2; |
| 61 | + case 2: |
| 62 | + return Constants.MAX_MBAR_WATER_TIER_3; |
| 63 | + } |
| 64 | + } |
| 65 | + return 0; |
| 66 | + } |
131 | 67 |
|
132 | | - connectedSides.put(dir, getBlockTileEntity(x, y, z)); |
| 68 | + public int getTier(){ |
| 69 | + return worldObj.getBlockMetadata(xCoord, yCoord, zCoord); |
| 70 | + } |
| 71 | + |
| 72 | + private boolean shouldConnectTo(TileEntity entity){ |
| 73 | + return entity instanceof MachineEntity; |
| 74 | + } |
| 75 | + |
| 76 | + public void checkConnectedSides(){ |
| 77 | + connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
| 78 | + |
| 79 | + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { |
| 80 | + TileEntity te = getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); |
| 81 | + if(shouldConnectTo(te)) { |
| 82 | + connectedSides.put(dir, te); |
133 | 83 | } |
134 | 84 | } |
| 85 | + |
| 86 | + updateBlock(); |
135 | 87 | } |
136 | 88 |
|
137 | | - private void writeConnectedSidesToNBT(NBTTagCompound tagCompound){ |
138 | | - if(connectedSides == null){ |
139 | | - connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
| 89 | + public Map<ForgeDirection, TileEntity> getConnectedSides(){ |
| 90 | + if(connectedSides == null) { |
| 91 | + checkConnectedSides(); |
| 92 | + } |
| 93 | + return connectedSides; |
| 94 | + } |
| 95 | + |
| 96 | + private void readConnectedSidesFromNBT(NBTTagCompound tagCompound){ |
| 97 | + NBTTagCompound ourCompound = tagCompound.getCompoundTag("connectedSides"); |
| 98 | + |
| 99 | + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { |
| 100 | + connectedSideFlags[dir.ordinal()] = ourCompound.getBoolean(dir.name()); |
140 | 101 | } |
| 102 | + needToCheckNeighbors = true; |
| 103 | + } |
141 | 104 |
|
142 | | - NBTTagCompound ourCompound = tagCompound.getCompoundTag |
143 | | - ("connectedSides"); |
144 | | - if(ourCompound == null){ |
145 | | - ourCompound = new NBTTagCompound(); |
| 105 | + private void writeConnectedSidesToNBT(NBTTagCompound tagCompound){ |
| 106 | + if(connectedSides == null) { |
| 107 | + connectedSides = new HashMap<ForgeDirection, TileEntity>(); |
146 | 108 | } |
147 | 109 |
|
148 | | - for(Map.Entry<ForgeDirection, TileEntity> entry : connectedSides.entrySet()){ |
| 110 | + NBTTagCompound ourCompound = new NBTTagCompound(); |
| 111 | + for(Map.Entry<ForgeDirection, TileEntity> entry : connectedSides.entrySet()) { |
149 | 112 | ourCompound.setBoolean(entry.getKey().name(), true); |
150 | 113 | } |
151 | 114 | tagCompound.setCompoundTag("connectedSides", ourCompound); |
152 | 115 | } |
153 | 116 |
|
154 | | - @Override |
155 | | - public void readFromNBT(NBTTagCompound tagCompound){ |
156 | | - super.readFromNBT(tagCompound); |
| 117 | + @Override |
| 118 | + public void readFromNBT(NBTTagCompound tagCompound){ |
| 119 | + super.readFromNBT(tagCompound); |
157 | 120 | readConnectedSidesFromNBT(tagCompound); |
158 | | - } |
159 | | - |
160 | | - @Override |
161 | | - public void writeToNBT(NBTTagCompound tagCompound){ |
162 | | - super.writeToNBT(tagCompound); |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public void writeToNBT(NBTTagCompound tagCompound){ |
| 125 | + super.writeToNBT(tagCompound); |
163 | 126 |
|
164 | 127 | writeConnectedSidesToNBT(tagCompound); |
165 | | - } |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public AxisAlignedBB getRenderBoundingBox(){ |
| 132 | + return AxisAlignedBB.getAABBPool().getAABB(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); |
| 133 | + } |
166 | 134 | } |
0 commit comments