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
|
package jp.plusplus.fbs.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import jp.plusplus.fbs.FBS;
import jp.plusplus.fbs.alchemy.AlchemyRegistry;
import jp.plusplus.fbs.alchemy.characteristic.CharacteristicBase;
import jp.plusplus.fbs.entity.EntityTableware;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
/**
* Created by plusplus_F on 2015/11/06.
*/
public class ItemPlaceable extends ItemBase {
public static final String[] NAMES={"Spoon", "Knife", "Fork"};
protected IIcon[] icons;
public ItemPlaceable(){
setUnlocalizedName("tableware");
setTextureName("tableware");
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int par1) {
return par1;
}
@Override
public String getUnlocalizedName(ItemStack p_77667_1_) {
int meta=p_77667_1_.getItemDamage();
if(meta<0 ||meta>=NAMES.length) meta=0;
return super.getUnlocalizedName() + NAMES[meta];
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) {
for(int i=0;i<NAMES.length;i++){
list.add(new ItemStack(item, 1, i));
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister register) {
icons=new IIcon[NAMES.length];
for(int i=0;i<NAMES.length;i++){
icons[i]=register.registerIcon(FBS.MODID+":tableware"+NAMES[i]);
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int p_77617_1_) {
if(p_77617_1_<0 || p_77617_1_>=icons.length) p_77617_1_=0;
return icons[p_77617_1_];
}
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
//カラスさんありがとー
if(player != null && player.isSneaking()) {
this.onItemRightClick(item, world, player);
return false;
} else {
Block block = world.getBlock(x, y, z);
if(block == Blocks.snow_layer && (world.getBlockMetadata(x, y, z) & 7) < 1) {
side = 1;
} else if(block != Blocks.vine && block != Blocks.tallgrass && block != Blocks.deadbush && !block.isReplaceable(world, x, y, z)) {
if(side == 0) {
--y;
}
if(side == 1) {
++y;
}
if(side == 2) {
--z;
}
if(side == 3) {
++z;
}
if(side == 4) {
--x;
}
if(side == 5) {
++x;
}
}
if(item.stackSize == 0) {
return false;
} else if(!player.canPlayerEdit(x, y, z, side, item)) {
return false;
} else if(y >= 255) {
return false;
} else{
int m = this.getMetadata(item.getItemDamage());
if(!world.isRemote && this.spawnEntity(world, player, new ItemStack(this, 1, m), (double) ((float) x + 0.5F), (double) ((float) y + 0.0F), (double) ((float) z + 0.5F))) {
world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
--item.stackSize;
}
return true;
}
}
}
protected boolean spawnEntity(World world, EntityPlayer player, ItemStack item, double x, double y, double z) {
EntityTableware entity=new EntityTableware(world, item, x,y,z);
world.spawnEntityInWorld(entity);
return true;
}
}
|