2012-10-25 05:53:23 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class TileEntityBeacon extends TileEntity implements IInventory {
|
|
|
|
|
|
|
|
public static final MobEffectList[][] a = new MobEffectList[][] { { MobEffectList.FASTER_MOVEMENT, MobEffectList.FASTER_DIG}, { MobEffectList.RESISTANCE, MobEffectList.JUMP}, { MobEffectList.INCREASE_DAMAGE}, { MobEffectList.REGENERATION}};
|
2013-11-04 14:07:38 +01:00
|
|
|
private boolean k;
|
|
|
|
private int l = -1;
|
|
|
|
private int m;
|
|
|
|
private int n;
|
2013-04-27 11:40:05 +02:00
|
|
|
private ItemStack inventorySlot;
|
2013-11-04 14:07:38 +01:00
|
|
|
private String p;
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
|
|
private int maxStack = MAX_STACK;
|
|
|
|
|
|
|
|
public ItemStack[] getContents() {
|
2013-04-27 11:40:05 +02:00
|
|
|
return new ItemStack[] { this.inventorySlot };
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onOpen(CraftHumanEntity who) {
|
|
|
|
transaction.add(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClose(CraftHumanEntity who) {
|
|
|
|
transaction.remove(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<HumanEntity> getViewers() {
|
|
|
|
return transaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMaxStackSize(int size) {
|
|
|
|
maxStack = size;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public TileEntityBeacon() {}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void h() {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.world.getTime() % 80L == 0L) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.y();
|
|
|
|
this.x();
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private void x() {
|
|
|
|
if (this.k && this.l > 0 && !this.world.isStatic && this.m > 0) {
|
|
|
|
double d0 = (double) (this.l * 10 + 10);
|
2012-10-25 05:53:23 +02:00
|
|
|
byte b0 = 0;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.l >= 4 && this.m == this.n) {
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AxisAlignedBB axisalignedbb = AxisAlignedBB.a().a((double) this.x, (double) this.y, (double) this.z, (double) (this.x + 1), (double) (this.y + 1), (double) (this.z + 1)).grow(d0, d0, d0);
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
axisalignedbb.e = (double) this.world.getHeight();
|
2012-10-25 05:53:23 +02:00
|
|
|
List list = this.world.a(EntityHuman.class, axisalignedbb);
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
|
|
|
|
EntityHuman entityhuman;
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
entityhuman = (EntityHuman) iterator.next();
|
2013-11-04 14:07:38 +01:00
|
|
|
entityhuman.addEffect(new MobEffect(this.m, 180, b0, true));
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.l >= 4 && this.m != this.n && this.n > 0) {
|
2012-10-25 05:53:23 +02:00
|
|
|
iterator = list.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
entityhuman = (EntityHuman) iterator.next();
|
2013-11-04 14:07:38 +01:00
|
|
|
entityhuman.addEffect(new MobEffect(this.n, 180, 0, true));
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private void y() {
|
|
|
|
int i = this.l;
|
|
|
|
|
|
|
|
if (!this.world.i(this.x, this.y + 1, this.z)) {
|
|
|
|
this.k = false;
|
|
|
|
this.l = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.k = true;
|
|
|
|
this.l = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int j = 1; j <= 4; this.l = j++) {
|
|
|
|
int k = this.y - j;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (k < 0) {
|
2012-10-25 05:53:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int l = this.x - j; l <= this.x + j && flag; ++l) {
|
|
|
|
for (int i1 = this.z - j; i1 <= this.z + j; ++i1) {
|
|
|
|
Block block = this.world.getType(l, k, i1);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block != Blocks.EMERALD_BLOCK && block != Blocks.GOLD_BLOCK && block != Blocks.DIAMOND_BLOCK && block != Blocks.IRON_BLOCK) {
|
2012-10-25 05:53:23 +02:00
|
|
|
flag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.l == 0) {
|
|
|
|
this.k = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.world.isStatic && this.l == 4 && i < this.l) {
|
|
|
|
Iterator iterator = this.world.a(EntityHuman.class, AxisAlignedBB.a().a((double) this.x, (double) this.y, (double) this.z, (double) this.x, (double) (this.y - 4), (double) this.z).grow(10.0D, 5.0D, 10.0D)).iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityHuman entityhuman = (EntityHuman) iterator.next();
|
|
|
|
|
|
|
|
entityhuman.a((Statistic) AchievementList.K);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int j() {
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.m;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int k() {
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.n;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int l() {
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.l;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void d(int i) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.m = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int j = 0; j < this.l && j < 3; ++j) {
|
2012-10-25 05:53:23 +02:00
|
|
|
MobEffectList[] amobeffectlist = a[j];
|
|
|
|
int k = amobeffectlist.length;
|
|
|
|
|
|
|
|
for (int l = 0; l < k; ++l) {
|
|
|
|
MobEffectList mobeffectlist = amobeffectlist[l];
|
|
|
|
|
|
|
|
if (mobeffectlist.id == i) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.m = i;
|
2012-10-25 05:53:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void e(int i) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.n = 0;
|
|
|
|
if (this.l >= 4) {
|
2012-10-25 05:53:23 +02:00
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
MobEffectList[] amobeffectlist = a[j];
|
|
|
|
int k = amobeffectlist.length;
|
|
|
|
|
|
|
|
for (int l = 0; l < k; ++l) {
|
|
|
|
MobEffectList mobeffectlist = amobeffectlist[l];
|
|
|
|
|
|
|
|
if (mobeffectlist.id == i) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.n = i;
|
2012-10-25 05:53:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public Packet getUpdatePacket() {
|
2012-10-25 05:53:23 +02:00
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
|
|
|
this.b(nbttagcompound);
|
2013-11-04 14:07:38 +01:00
|
|
|
return new PacketPlayOutTileEntityData(this.x, this.y, this.z, 3, nbttagcompound);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2013-11-04 14:07:38 +01:00
|
|
|
this.m = nbttagcompound.getInt("Primary");
|
|
|
|
this.n = nbttagcompound.getInt("Secondary");
|
|
|
|
this.l = nbttagcompound.getInt("Levels");
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2013-11-04 14:07:38 +01:00
|
|
|
nbttagcompound.setInt("Primary", this.m);
|
|
|
|
nbttagcompound.setInt("Secondary", this.n);
|
|
|
|
nbttagcompound.setInt("Levels", this.l);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getSize() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getItem(int i) {
|
2013-04-27 11:40:05 +02:00
|
|
|
return i == 0 ? this.inventorySlot : null;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack splitStack(int i, int j) {
|
2013-04-27 11:40:05 +02:00
|
|
|
if (i == 0 && this.inventorySlot != null) {
|
|
|
|
if (j >= this.inventorySlot.count) {
|
|
|
|
ItemStack itemstack = this.inventorySlot;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-04-27 11:40:05 +02:00
|
|
|
this.inventorySlot = null;
|
2012-10-25 05:53:23 +02:00
|
|
|
return itemstack;
|
|
|
|
} else {
|
2013-04-27 11:40:05 +02:00
|
|
|
this.inventorySlot.count -= j;
|
2013-11-04 14:07:38 +01:00
|
|
|
return new ItemStack(this.inventorySlot.getItem(), j, this.inventorySlot.getData());
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack splitWithoutUpdate(int i) {
|
2013-04-27 11:40:05 +02:00
|
|
|
if (i == 0 && this.inventorySlot != null) {
|
|
|
|
ItemStack itemstack = this.inventorySlot;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-04-27 11:40:05 +02:00
|
|
|
this.inventorySlot = null;
|
2012-10-25 05:53:23 +02:00
|
|
|
return itemstack;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
|
|
|
if (i == 0) {
|
2013-04-27 11:40:05 +02:00
|
|
|
this.inventorySlot = itemstack;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public String getInventoryName() {
|
|
|
|
return this.k_() ? this.p : "container.beacon";
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean k_() {
|
|
|
|
return this.p != null && this.p.length() > 0;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(String s) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.p = s;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxStackSize() {
|
|
|
|
return maxStack; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public boolean a(EntityHuman entityhuman) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.world.getTileEntity(this.x, this.y, this.z) != this ? false : entityhuman.e((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D) <= 64.0D;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startOpen() {}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void l_() {}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
public boolean b(int i, ItemStack itemstack) {
|
2013-11-04 14:07:38 +01:00
|
|
|
return itemstack.getItem() == Items.EMERALD || itemstack.getItem() == Items.DIAMOND || itemstack.getItem() == Items.GOLD_INGOT || itemstack.getItem() == Items.IRON_INGOT;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|