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
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
protected BlockDispenser(int i) {
|
2011-02-01 23:01:37 +01:00
|
|
|
super(i, 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-03-13 23:33:27 +01:00
|
|
|
this.k(world, i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private void k(World world, int i, int j, int k) {
|
2011-04-20 22:47:26 +02:00
|
|
|
if (!world.isStatic) {
|
|
|
|
int l = world.getTypeId(i, j, k - 1);
|
|
|
|
int i1 = world.getTypeId(i, j, k + 1);
|
|
|
|
int j1 = world.getTypeId(i - 1, j, k);
|
|
|
|
int k1 = world.getTypeId(i + 1, j, k);
|
|
|
|
byte b0 = 3;
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Block.s[l] && !Block.s[i1]) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 3;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Block.s[i1] && !Block.s[l]) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 2;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Block.s[j1] && !Block.s[k1]) {
|
2011-04-20 22:47:26 +02:00
|
|
|
b0 = 5;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Block.s[k1] && !Block.s[j1]) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit - private -> public
|
|
|
|
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-03-13 23:33:27 +01:00
|
|
|
int l = tileentitydispenser.j();
|
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-03-13 23:33:27 +01:00
|
|
|
public void doPhysics(World world, int i, int j, int k, int l) {
|
|
|
|
boolean flag = world.isBlockIndirectlyPowered(i, j, k) || world.isBlockIndirectlyPowered(i, j + 1, k);
|
|
|
|
int i1 = world.getData(i, j, k);
|
|
|
|
boolean flag1 = (i1 & 8) != 0;
|
|
|
|
|
|
|
|
if (flag && !flag1) {
|
|
|
|
world.a(i, j, k, this.id, this.a(world));
|
|
|
|
world.setData(i, j, k, i1 | 8, 4);
|
|
|
|
} else if (!flag && flag1) {
|
|
|
|
world.setData(i, j, k, i1 & -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-03-13 23:33:27 +01:00
|
|
|
public TileEntity b(World world) {
|
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
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void remove(World world, int i, int j, int k, int l, int i1) {
|
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) {
|
2012-07-29 09:33:13 +02:00
|
|
|
for (int j1 = 0; j1 < tileentitydispenser.getSize(); ++j1) {
|
|
|
|
ItemStack itemstack = tileentitydispenser.getItem(j1);
|
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) {
|
2012-10-25 05:53:23 +02:00
|
|
|
int k1 = this.b.nextInt(21) + 10;
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (k1 > itemstack.count) {
|
|
|
|
k1 = itemstack.count;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
itemstack.count -= k1;
|
|
|
|
EntityItem entityitem = new EntityItem(world, (double) ((float) i + f), (double) ((float) j + f1), (double) ((float) k + f2), new ItemStack(itemstack.id, k1, 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
|
|
|
|
|
|
|
world.m(i, j, k, l);
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
super.remove(world, i, j, k, l, i1);
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public static IPosition a(ISourceBlock isourceblock) {
|
2013-03-13 23:33:27 +01:00
|
|
|
EnumFacing enumfacing = j_(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
|
|
|
|
|
|
|
public static EnumFacing j_(int i) {
|
|
|
|
return EnumFacing.a(i & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean q_() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int b_(World world, int i, int j, int k, int l) {
|
|
|
|
return Container.b((IInventory) world.getTileEntity(i, j, k));
|
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
}
|