-
Notifications
You must be signed in to change notification settings - Fork 497
/
ItemPipe.java
97 lines (83 loc) · 2.78 KB
/
ItemPipe.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
/**
* 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.transport;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import buildcraft.BuildCraftTransport;
import buildcraft.core.IItemPipe;
import buildcraft.core.ItemBuildCraft;
import buildcraft.BuildCraftCore;
public class ItemPipe extends ItemBuildCraft implements IItemPipe {
Pipe dummyPipe;
private int textureIndex = 0;
protected ItemPipe(int i) {
super(i);
this.setCreativeTab(CreativeTabs.tabTransport);
}
@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int side, float par8, float par9, float par10) {
int blockID = BuildCraftTransport.genericPipeBlock.blockID;
Block block = BuildCraftTransport.genericPipeBlock;
int id = world.getBlockId(i, j, k);
if (id == Block.snow.blockID) {
side = 1;
}
else if (id != Block.vine.blockID && id != Block.tallGrass.blockID && id != Block.deadBush.blockID
&& (Block.blocksList[id] == null || !Block.blocksList[id].isBlockReplaceable(world, i, j, k)))
{
if (side == 0) {
j--;
}
if (side == 1) {
j++;
}
if (side == 2) {
k--;
}
if (side == 3) {
k++;
}
if (side == 4) {
i--;
}
if (side == 5) {
i++;
}
}
if (itemstack.stackSize == 0)
return false;
if (entityplayer.canCurrentToolHarvestBlock(i, j, k) && world.canPlaceEntityOnSide(blockID, i, j, k, false, side, entityplayer)) {
Pipe pipe = BlockGenericPipe.createPipe(itemID);
if (pipe == null) {
BuildCraftCore.bcLog.warning("Pipe failed to create during placement at "+i+","+j+","+k);
return true;
}
if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {
Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer);
world.playSoundEffect(i + 0.5F, j + 0.5F, k + 0.5F,
block.stepSound.getPlaceSound(),
(block.stepSound.getVolume() + 1.0F) / 2.0F,
block.stepSound.getPitch() * 0.8F);
itemstack.stackSize--;
}
return true;
} else
return false;
}
public ItemPipe setTextureIndex(int textureIndex) {
this.textureIndex = textureIndex;
return this;
}
public int getTextureIndex() {
return textureIndex;
}
}