-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockTank.java
157 lines (130 loc) · 4.41 KB
/
BlockTank.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
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import java.util.ArrayList;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockTank extends BlockContainer {
private Icon textureStackedSide;
private Icon textureBottomSide;
private Icon textureTop;
public BlockTank(int i) {
super(i, Material.glass);
setBlockBounds(0.125F, 0F, 0.125F, 0.875F, 1F, 0.875F);
setHardness(0.5F);
setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
public boolean isACube() {
return false;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileTank();
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2) {
switch(par1){
case 0:
case 1:
return textureTop;
default:
return textureBottomSide;
}
}
@SuppressWarnings({ "all" })
public Icon getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
switch (l) {
case 0:
case 1:
return textureTop;
default:
if (iblockaccess.getBlockId(i, j - 1, k) == blockID)
return textureStackedSide;
else
return textureBottomSide;
}
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
ItemStack current = entityplayer.inventory.getCurrentItem();
if (current != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k);
// Handle filled containers
if (liquid != null) {
int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current));
}
return true;
// Handle empty containers
} else {
FluidStack available = tank.getTanks(ForgeDirection.UNKNOWN)[0].getFluid();
if (available != null) {
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
if (liquid != null) {
if (!BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) {
if (current.stackSize > 1) {
if (!entityplayer.inventory.addItemStackToInventory(filled))
return false;
else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current));
}
} else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
}
}
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
return true;
}
}
}
}
return false;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
textureStackedSide = par1IconRegister.registerIcon("buildcraft:tank_stacked_side");
textureBottomSide = par1IconRegister.registerIcon("buildcraft:tank_bottom_side");
textureTop = par1IconRegister.registerIcon("buildcraft:tank_top");
}
}