-
Notifications
You must be signed in to change notification settings - Fork 755
/
FilledBucket.java
187 lines (155 loc) · 5.82 KB
/
FilledBucket.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
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
package tconstruct.items;
import java.util.List;
import tconstruct.blocks.logic.LiquidTextureLogic;
import tconstruct.common.TContent;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class FilledBucket extends ItemBucket
{
public FilledBucket(int id)
{
super(id, 0);
//setTextureFile(TContent.craftingTexture);
//setIconIndex(224);
setUnlocalizedName("tconstruct.bucket");
setContainerItem(Item.bucketEmpty);
this.setHasSubtypes(true);
}
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
float var4 = 1.0F;
double trueX = player.prevPosX + (player.posX - player.prevPosX) * (double) var4;
double trueY = player.prevPosY + (player.posY - player.prevPosY) * (double) var4 + 1.62D - (double) player.yOffset;
double trueZ = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) var4;
boolean wannabeFull = false;
MovingObjectPosition position = this.getMovingObjectPositionFromPlayer(world, player, wannabeFull);
if (position == null)
{
return stack;
}
else
{
/*FillBucketEvent event = new FillBucketEvent(player, stack, world, position);
if (MinecraftForge.EVENT_BUS.post(event))
{
return stack;
}
if (event.getResult() == Event.Result.ALLOW)
{
if (player.capabilities.isCreativeMode)
{
return stack;
}
if (--stack.stackSize <= 0)
{
return event.result;
}
if (!player.inventory.addItemStackToInventory(event.result))
{
player.dropPlayerItem(event.result);
}
return stack;
}*/
if (position.typeOfHit == EnumMovingObjectType.TILE)
{
int clickX = position.blockX;
int clickY = position.blockY;
int clickZ = position.blockZ;
if (!world.canMineBlock(player, clickX, clickY, clickZ))
{
return stack;
}
if (position.sideHit == 0)
{
--clickY;
}
if (position.sideHit == 1)
{
++clickY;
}
if (position.sideHit == 2)
{
--clickZ;
}
if (position.sideHit == 3)
{
++clickZ;
}
if (position.sideHit == 4)
{
--clickX;
}
if (position.sideHit == 5)
{
++clickX;
}
if (!player.canPlayerEdit(clickX, clickY, clickZ, position.sideHit, stack))
{
return stack;
}
if (this.tryPlaceContainedLiquid(world, clickX, clickY, clickZ, stack.getItemDamage()) && !player.capabilities.isCreativeMode)
{
return new ItemStack(Item.bucketEmpty);
}
}
return stack;
}
}
public boolean tryPlaceContainedLiquid (World world, int clickX, int clickY, int clickZ, int type)
{
if (!world.isAirBlock(clickX, clickY, clickZ) && world.getBlockMaterial(clickX, clickY, clickZ).isSolid())
{
return false;
}
else
{
int id = 0;
int metadata = 0;
if (type == 25)
metadata = 0;
world.setBlock(clickX, clickY, clickZ, TContent.fluidBlocks[type].blockID, metadata, 3); //TODO: Merge liquids
return true;
}
}
@Override
public void getSubItems (int id, CreativeTabs tab, List list)
{
for (int i = 0; i < icons.length; i++)
list.add(new ItemStack(id, 1, i));
}
public Icon[] icons;
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage (int meta)
{
return icons[meta];
}
@SideOnly(Side.CLIENT)
public void registerIcons (IconRegister iconRegister)
{
this.icons = new Icon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("tinker:materials/bucket_" + textureNames[i]);
}
}
public String getUnlocalizedName (ItemStack stack)
{
int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, materialNames.length);
return getUnlocalizedName() + "." + materialNames[arr];
}
public static final String[] materialNames = new String[] { "Iron", "Gold", "Copper", "Tin", "Aluminum", "Cobalt", "Ardite", "Bronze", "AluBrass", "Manyullyn", "Alumite", "Obsidian", "Steel",
"Glass", "Stone", "Villager", "Cow", "Nickel", "Lead", "Silver", "Shiny", "Invar", "Electrum", "Ender", "Slime", "PigIron" };
public static final String[] textureNames = new String[] { "iron", "gold", "copper", "tin", "aluminum", "cobalt", "ardite", "bronze", "alubrass", "manyullyn", "alumite", "obsidian", "steel",
"glass", "stone", "emerald", "blood", "nickel", "lead", "silver", "shiny", "invar", "electrum", "ender", "slime", "pigiron" };
}