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
|
package jp.plusplus.fbs.storage;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import jp.plusplus.fbs.FBS;
import jp.plusplus.fbs.block.BlockBase;
import jp.plusplus.fbs.item.ItemCore;
import jp.plusplus.fbs.particle.EntityGlowFX;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
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.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.Random;
/**
* Created by plusplus_F on 2016/03/08.
*/
public class BlockMealTerminal extends BlockBase implements ITileEntityProvider {
public BlockMealTerminal() {
super(Material.rock);
setBlockName("mealTerminal");
setBlockTextureName("mealCrystal");
stepSound=soundTypeGlass;
infoName="mealTerminal";
infoRow=1;
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileEntityMealTerminal();
}
@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_) {
IMealDevice te=(IMealDevice)world.getTileEntity(x,y,z);
if(te==null) return false;
ItemStack hav=player.getCurrentEquippedItem();
if(te.hasFragment()){
if(hav==null && !player.isSneaking()){
//ミールを取り出す
if(!world.isRemote){
player.entityDropItem(te.getFragment().copy(), 0);
}
te.setFragment(null);
((TileEntity)te).markDirty();
player.inventory.markDirty();
world.markBlockForUpdate(x, y, z);
return true;
}
else{
if(!world.isRemote && ItemMealFragment.getTileEntity(te.getFragment())!=null) player.openGui(FBS.instance, -1, world, x,y,z);
return true;
}
}
else if(hav!=null && hav.getItem()==ItemCore.mealFragment){
//ミールを設定する
ItemStack f=hav.copy();
f.stackSize=1;
te.setFragment(f);
if(!world.isRemote){
hav.stackSize--;
if(hav.stackSize<=0){
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
((TileEntity)te).markDirty();
player.inventory.markDirty();
world.markBlockForUpdate(x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World par1World, int x, int y, int z, Block block, int par6){
//ミールの欠片をドロップさせる
IMealDevice te = (IMealDevice)par1World.getTileEntity(x, y, z);
if(te!=null && te.hasFragment()){
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.getFragment();
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);
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return FBS.renderMealTerminalId;
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileEntity te=world.getTileEntity(x,y,z);
if(te instanceof IMealDevice){
return ((IMealDevice) te).hasFragment()?15:0;
}
return 0;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
EntityPlayer ep = FBS.proxy.getEntityPlayerInstance();
if (ep == null) return;
IMealDevice tem=(IMealDevice)world.getTileEntity(x,y,z);
if(tem==null || !tem.hasFragment()) return;
float f = (float) x + 0.5F;
float f1 = (float) y + 0.6f;
float f2 = (float) z + 0.5F;
for(int i=0;i<2;i++){
float f3 = 0.3f*rand.nextFloat()-0.15f;
float f4 = rand.nextFloat() * 0.4F - 0.2F;
float f5 = 0.3f*rand.nextFloat()-0.15f;
spawnParticle(world, (double) (f+f3), (double) (f1+f4), (double) (f2 + f5));
}
}
@SideOnly(Side.CLIENT)
protected void spawnParticle(World world, double x, double y, double z){
EntityGlowFX e=new EntityGlowFX(world, x,y,z);
e.setRBGColorF(0.8f+0.2f*rand.nextFloat(), 0.8f+0.2f*rand.nextFloat(), 0);
FMLClientHandler.instance().getClient().effectRenderer.addEffect(e);
}
}
|