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
|
package jp.plusplus.fbs.storage;
import jp.plusplus.fbs.block.BlockCore;
import jp.plusplus.fbs.item.ItemCore;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
/**
* Created by plusplus_F on 2016/03/08.
*/
public class BlockMealOutletSingle extends BlockMealInlet {
public BlockMealOutletSingle() {
super();
setBlockName("mealOutletSingle");
infoName="mealOutlet";
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileEntityMealOutletSingle();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
TileEntityMealOutletSingle temos=(TileEntityMealOutletSingle)world.getTileEntity(x,y,z);
if(temos==null) return false;
//リクエストを取り出す
if(temos.hasRequirement()){
if(!world.isRemote){
player.entityDropItem(temos.getRequirement().copy(), player.getEyeHeight());
temos.setRequirement(null);
}
temos.markDirty();
world.markBlockForUpdate(x,y,z);
return true;
}
//リクエストを設定する
ItemStack hav=player.getCurrentEquippedItem();
if(hav!=null && temos.hasFragment()){
if(!world.isRemote){
ItemStack f=hav.copy();
f.stackSize=1;
temos.setRequirement(f);
hav.stackSize--;
if(hav.stackSize<=0){
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
player.addChatComponentMessage(new ChatComponentText("Set requirement : "+f.getDisplayName()));
}
player.inventory.markDirty();
world.markBlockForUpdate(x, y, z);
return true;
}
return super.onBlockActivated(world, x, y, z, player, p_149727_6_, p_149727_7_, p_149727_8_, p_149727_9_);
}
@Override
public void breakBlock(World par1World, int x, int y, int z, Block block, int par6){
TileEntityMealOutletSingle te = (TileEntityMealOutletSingle)par1World.getTileEntity(x, y, z);
if(te!=null && te.hasRequirement()){
float f = this.rand.nextFloat() * 0.8F + 0.1F;
float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
ItemStack fragment=te.getRequirement();
EntityItem entityitem = new EntityItem(par1World, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(fragment.getItem(), fragment.stackSize, fragment.getItemDamage()));
if (fragment.hasTagCompound()){
entityitem.getEntityItem().setTagCompound((NBTTagCompound)fragment.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
par1World.spawnEntityInWorld(entityitem);
}
super.breakBlock(par1World, x, y, z, block, par6);
}
}
|