aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/thaumcraft/common/tile/TileFastArcaneAlembic.java
blob: 89ea5c7daa44fac3b7b85322a6ce510eda9b601b (plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package gtPlusPlus.xmod.thaumcraft.common.tile;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.xmod.thaumcraft.common.block.TC_BlockHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.tiles.TileAlembic;

public class TileFastArcaneAlembic extends TileAlembic {
	ForgeDirection fd;

	public TileFastArcaneAlembic() {
		this.aspectFilter = null;
		this.amount = 0;
		this.maxAmount = 64;
		this.facing = 2;
		this.aboveAlembic = false;
		this.aboveFurnace = false;
		this.fd = null;
	}

	@Override
	public AspectList getAspects() {
		return (this.aspect != null) ? new AspectList().add(this.aspect, this.amount) : new AspectList();
	}

	@Override
	public void setAspects(final AspectList aspects) {
	}

	@Override
	@SideOnly(Side.CLIENT)
	public AxisAlignedBB getRenderBoundingBox() {
		return AxisAlignedBB.getBoundingBox(this.xCoord - 1, this.yCoord,
				this.zCoord - 1, this.xCoord + 2, this.yCoord + 1,
				this.zCoord + 2);
	}

	@Override
	public void readCustomNBT(final NBTTagCompound nbttagcompound) {
		this.facing = nbttagcompound.getByte("facing");
		this.aspectFilter = Aspect.getAspect(nbttagcompound.getString("AspectFilter"));
		final String tag = nbttagcompound.getString("aspect");
		if (tag != null) {
			this.aspect = Aspect.getAspect(tag);
		}
		this.amount = nbttagcompound.getShort("amount");
		this.fd = ForgeDirection.getOrientation(this.facing);
	}

	@Override
	public void writeCustomNBT(final NBTTagCompound nbttagcompound) {
		if (this.aspect != null) {
			nbttagcompound.setString("aspect", this.aspect.getTag());
		}
		if (this.aspectFilter != null) {
			nbttagcompound.setString("AspectFilter", this.aspectFilter.getTag());
		}
		nbttagcompound.setShort("amount", (short) this.amount);
		nbttagcompound.setByte("facing", (byte) this.facing);
	}

	@Override
	public boolean canUpdate() {
		return false;
	}

	@Override
	public int addToContainer(final Aspect tt, int am) {
		if (((this.amount < this.maxAmount) && (tt == this.aspect)) || (this.amount == 0)) {
			this.aspect = tt;
			final int added = Math.min(am, this.maxAmount - this.amount);
			this.amount += added;
			am -= added;
		}
		this.markDirty();
		this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
		return am;
	}

	@Override
	public boolean takeFromContainer(final Aspect tt, final int am) {
		if ((this.amount == 0) || (this.aspect == null)) {
			this.aspect = null;
			this.amount = 0;
		}
		if ((this.aspect != null) && (this.amount >= am) && (tt == this.aspect)) {
			this.amount -= am;
			if (this.amount <= 0) {
				this.aspect = null;
				this.amount = 0;
			}
			this.markDirty();
			this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
			return true;
		}
		return false;
	}

	@Override
	public boolean doesContainerContain(final AspectList ot) {
		return (this.amount > 0) && (this.aspect != null) && (ot.getAmount(this.aspect) > 0);
	}

	@Override
	public boolean doesContainerContainAmount(final Aspect tt, final int am) {
		return (this.amount >= am) && (tt == this.aspect);
	}

	@Override
	public int containerContains(final Aspect tt) {
		return (tt == this.aspect) ? this.amount : 0;
	}

	@Override
	public boolean doesContainerAccept(final Aspect tag) {
		return true;
	}

	@Override
	public boolean takeFromContainer(final AspectList ot) {
		return false;
	}

	@Override
	public void getAppearance() {
		this.aboveAlembic = false;
		this.aboveFurnace = false;
		if ((this.worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) == ConfigBlocks.blockStoneDevice)
				&& (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - 1, this.zCoord) == 0)) {
			this.aboveFurnace = true;
		}
		else if ((this.worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) == TC_BlockHandler.blockFastAlchemyFurnace)
				&& (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - 1, this.zCoord) == 0)) {
			this.aboveFurnace = true;
		}

		if ((this.worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) == ConfigBlocks.blockMetalDevice)
				&& (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - 1, this.zCoord) == this
				.getBlockMetadata())) {
			this.aboveAlembic = true;
		}
		else if ((this.worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) == TC_BlockHandler.blockFastArcaneAlembic)
				&& (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - 1, this.zCoord) == 1)) {
			this.aboveAlembic = true;
		}
	}

	@Override
	public void onDataPacket(final NetworkManager net, final S35PacketUpdateTileEntity pkt) {
		super.onDataPacket(net, pkt);
		this.getAppearance();
	}

	@Override
	public int onWandRightClick(final World world, final ItemStack wandstack, final EntityPlayer player, final int x,
			final int y, final int z, final int side, final int md) {
		if (side <= 1) {
			return 0;
		}
		this.facing = side;
		this.fd = ForgeDirection.getOrientation(this.facing);
		this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
		player.swingItem();
		this.markDirty();
		return 0;
	}

	@Override
	public ItemStack onWandRightClick(final World world, final ItemStack wandstack, final EntityPlayer player) {
		return null;
	}

	@Override
	public void onUsingWandTick(final ItemStack wandstack, final EntityPlayer player, final int count) {
	}

	@Override
	public void onWandStoppedUsing(final ItemStack wandstack, final World world, final EntityPlayer player,
			final int count) {
	}

	@Override
	public boolean isConnectable(final ForgeDirection face) {
		return (face != ForgeDirection.getOrientation(this.facing)) && (face != ForgeDirection.DOWN);
	}

	@Override
	public boolean canInputFrom(final ForgeDirection face) {
		return false;
	}

	@Override
	public boolean canOutputTo(final ForgeDirection face) {
		return (face != ForgeDirection.getOrientation(this.facing)) && (face != ForgeDirection.DOWN);
	}

	@Override
	public void setSuction(final Aspect aspect, final int amount) {
	}

	@Override
	public Aspect getSuctionType(final ForgeDirection loc) {
		return null;
	}

	@Override
	public int getSuctionAmount(final ForgeDirection loc) {
		return 0;
	}

	@Override
	public Aspect getEssentiaType(final ForgeDirection loc) {
		return this.aspect;
	}

	@Override
	public int getEssentiaAmount(final ForgeDirection loc) {
		return this.amount;
	}

	@Override
	public int takeEssentia(final Aspect aspect, final int amount, final ForgeDirection face) {
		return (this.canOutputTo(face) && this.takeFromContainer(aspect, amount)) ? amount : 0;
	}

	@Override
	public int addEssentia(final Aspect aspect, final int amount, final ForgeDirection loc) {
		return 0;
	}

	@Override
	public int getMinimumSuction() {
		return 0;
	}

	@Override
	public boolean renderExtendedTube() {
		return true;
	}
}