2011-02-01 22:55:30 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
public class BlockDispenser extends BlockContainer {
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public static final IRegistry a = new RegistryDefault(new DispenseBehaviorItem());
|
2013-03-13 23:33:27 +01:00
|
|
|
protected Random b = new Random();
|
2012-10-25 05:53:23 +02:00
|
|
|
public static boolean eventFired = false; // CraftBukkit
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected BlockDispenser() {
|
|
|
|
super(Material.STONE);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(CreativeModeTab.d);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int a(World world) {
|
2011-02-01 22:55:30 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public void onPlace(World world, int i, int j, int k) {
|
|
|
|
super.onPlace(world, i, j, k);
|
2013-11-04 14:07:38 +01:00
|
|
|
this.m(world, i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private void m(World world, int i, int j, int k) {
|
2011-04-20 22:47:26 +02:00
|
|
|
if (!world.isStatic) {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block = world.getType(i, j, k - 1);
|
|
|
|
Block block1 = world.getType(i, j, k + 1);
|
|
|
|
Block block2 = world.getType(i - 1, j, k);
|
|
|
|
Block block3 = world.getType(i + 1, j, k);
|
2011-04-20 22:47:26 +02:00
|
|
|
byte b0 = 3;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block.j() && !block1.j()) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 3;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block1.j() && !block.j()) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 2;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block2.j() && !block3.j()) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 5;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block3.j() && !block2.j()) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 4;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setData(i, j, k, b0, 2);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman, int l, float f, float f1, float f2) {
|
2011-02-01 23:01:37 +01:00
|
|
|
if (world.isStatic) {
|
2011-02-01 22:55:30 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
2011-02-01 23:01:37 +01:00
|
|
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (tileentitydispenser != null) {
|
2012-02-29 22:31:04 +01:00
|
|
|
entityhuman.openDispenser(tileentitydispenser);
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
// CraftBukkit - protected -> public
|
2012-10-25 05:53:23 +02:00
|
|
|
public void dispense(World world, int i, int j, int k) {
|
|
|
|
SourceBlock sourceblock = new SourceBlock(world, i, j, k);
|
|
|
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity();
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (tileentitydispenser != null) {
|
2013-11-04 14:07:38 +01:00
|
|
|
int l = tileentitydispenser.i();
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (l < 0) {
|
2012-02-29 22:31:04 +01:00
|
|
|
world.triggerEffect(1001, i, j, k, 0);
|
2011-02-01 22:55:30 +01:00
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
ItemStack itemstack = tileentitydispenser.getItem(l);
|
2013-03-13 23:33:27 +01:00
|
|
|
IDispenseBehavior idispensebehavior = this.a(itemstack);
|
2012-08-02 23:54:21 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (idispensebehavior != IDispenseBehavior.a) {
|
|
|
|
ItemStack itemstack1 = idispensebehavior.a(sourceblock, itemstack);
|
|
|
|
eventFired = false; // CraftBukkit - reset event status
|
2012-08-02 23:54:21 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
tileentitydispenser.setItem(l, itemstack1.count == 0 ? null : itemstack1);
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected IDispenseBehavior a(ItemStack itemstack) {
|
|
|
|
return (IDispenseBehavior) a.a(itemstack.getItem());
|
|
|
|
}
|
2011-02-01 22:55:30 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void doPhysics(World world, int i, int j, int k, Block block) {
|
2013-03-13 23:33:27 +01:00
|
|
|
boolean flag = world.isBlockIndirectlyPowered(i, j, k) || world.isBlockIndirectlyPowered(i, j + 1, k);
|
2013-11-04 14:07:38 +01:00
|
|
|
int l = world.getData(i, j, k);
|
|
|
|
boolean flag1 = (l & 8) != 0;
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
if (flag && !flag1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.a(i, j, k, this, this.a(world));
|
|
|
|
world.setData(i, j, k, l | 8, 4);
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (!flag && flag1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setData(i, j, k, l & -9, 4);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
|
|
|
if (!world.isStatic) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.dispense(world, i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public TileEntity a(World world, int i) {
|
2011-02-01 23:01:37 +01:00
|
|
|
return new TileEntityDispenser();
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void postPlace(World world, int i, int j, int k, EntityLiving entityliving, ItemStack itemstack) {
|
|
|
|
int l = BlockPiston.a(world, i, j, k, entityliving);
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setData(i, j, k, l, 2);
|
|
|
|
if (itemstack.hasName()) {
|
|
|
|
((TileEntityDispenser) world.getTileEntity(i, j, k)).a(itemstack.getName());
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void remove(World world, int i, int j, int k, Block block, int l) {
|
2011-05-26 14:48:22 +02:00
|
|
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (tileentitydispenser != null) {
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int i1 = 0; i1 < tileentitydispenser.getSize(); ++i1) {
|
|
|
|
ItemStack itemstack = tileentitydispenser.getItem(i1);
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (itemstack != null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
float f = this.b.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float f1 = this.b.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float f2 = this.b.nextFloat() * 0.8F + 0.1F;
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
while (itemstack.count > 0) {
|
2013-11-04 14:07:38 +01:00
|
|
|
int j1 = this.b.nextInt(21) + 10;
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j1 > itemstack.count) {
|
|
|
|
j1 = itemstack.count;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
itemstack.count -= j1;
|
|
|
|
EntityItem entityitem = new EntityItem(world, (double) ((float) i + f), (double) ((float) j + f1), (double) ((float) k + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getData()));
|
2012-03-22 21:39:39 +01:00
|
|
|
|
|
|
|
if (itemstack.hasTag()) {
|
2012-12-20 05:03:52 +01:00
|
|
|
entityitem.getItemStack().setTag((NBTTagCompound) itemstack.getTag().clone());
|
2012-03-22 21:39:39 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
float f3 = 0.05F;
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
entityitem.motX = (double) ((float) this.b.nextGaussian() * f3);
|
|
|
|
entityitem.motY = (double) ((float) this.b.nextGaussian() * f3 + 0.2F);
|
|
|
|
entityitem.motZ = (double) ((float) this.b.nextGaussian() * f3);
|
2011-09-15 02:23:52 +02:00
|
|
|
world.addEntity(entityitem);
|
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 21:09:23 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
world.f(i, j, k, block);
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
super.remove(world, i, j, k, block, l);
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public static IPosition a(ISourceBlock isourceblock) {
|
2013-11-04 14:07:38 +01:00
|
|
|
EnumFacing enumfacing = b(isourceblock.h());
|
2012-12-20 05:03:52 +01:00
|
|
|
double d0 = isourceblock.getX() + 0.7D * (double) enumfacing.c();
|
2013-03-13 23:33:27 +01:00
|
|
|
double d1 = isourceblock.getY() + 0.7D * (double) enumfacing.d();
|
2012-12-20 05:03:52 +01:00
|
|
|
double d2 = isourceblock.getZ() + 0.7D * (double) enumfacing.e();
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
return new Position(d0, d1, d2);
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public static EnumFacing b(int i) {
|
2013-03-13 23:33:27 +01:00
|
|
|
return EnumFacing.a(i & 7);
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean M() {
|
2013-03-13 23:33:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public int g(World world, int i, int j, int k, int l) {
|
2013-03-13 23:33:27 +01:00
|
|
|
return Container.b((IInventory) world.getTileEntity(i, j, k));
|
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
}
|