-
Notifications
You must be signed in to change notification settings - Fork 497
/
ItemPipe.java
129 lines (113 loc) · 3.52 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
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
/**
* 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 buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.core.IItemPipe;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.utils.BCLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.logging.Level;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class ItemPipe extends ItemBuildCraft implements IItemPipe {
@SideOnly(Side.CLIENT)
private IIconProvider iconProvider;
private int pipeIconIndex;
protected ItemPipe(int i) {
super(i);
}
@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 (world.canPlaceEntityOnSide(blockID, i, j, k, false, side, entityplayer, itemstack)) {
Pipe pipe = BlockGenericPipe.createPipe(itemID);
if (pipe == null) {
BCLog.logger.log(Level.WARNING, "Pipe failed to create during placement at {0},{1},{2}", new Object[]{i, j, k});
return true;
}
if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {
Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
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;
}
@SideOnly(Side.CLIENT)
public void setPipesIcons(IIconProvider iconProvider) {
this.iconProvider = iconProvider;
}
public void setPipeIconIndex(int index) {
this.pipeIconIndex = index;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) {
if (iconProvider != null) { // invalid pipes won't have this set
return iconProvider.getIcon(pipeIconIndex);
} else {
return null;
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister) {
// NOOP
}
@Override
@SideOnly(Side.CLIENT)
public int getSpriteNumber() {
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
super.addInformation(stack, player, list, advanced);
Class<? extends Pipe> pipe = BlockGenericPipe.pipes.get(itemID);
List<String> toolTip = PipeToolTipManager.getToolTip(pipe);
list.addAll(toolTip);
}
}