mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 20:50:41 +01:00
Add EntityLeash and ItemLeash for diff visibility
This commit is contained in:
parent
8a7c582d54
commit
f7ca953ff1
2 changed files with 171 additions and 0 deletions
118
src/main/java/net/minecraft/server/EntityLeash.java
Normal file
118
src/main/java/net/minecraft/server/EntityLeash.java
Normal file
|
@ -0,0 +1,118 @@
|
|||
package net.minecraft.server;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityLeash extends EntityHanging {
|
||||
|
||||
public EntityLeash(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityLeash(World world, int i, int j, int k) {
|
||||
super(world, i, j, k, 0);
|
||||
this.setPosition((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D);
|
||||
}
|
||||
|
||||
protected void a() {
|
||||
super.a();
|
||||
}
|
||||
|
||||
public void setDirection(int i) {}
|
||||
|
||||
public int d() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
public int e() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
public void b(Entity entity) {}
|
||||
|
||||
public boolean d(NBTTagCompound nbttagcompound) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void b(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
public void a(NBTTagCompound nbttagcompound) {}
|
||||
|
||||
public boolean c(EntityHuman entityhuman) {
|
||||
ItemStack itemstack = entityhuman.aY();
|
||||
boolean flag = false;
|
||||
double d0;
|
||||
List list;
|
||||
Iterator iterator;
|
||||
EntityInsentient entityinsentient;
|
||||
|
||||
if (itemstack != null && itemstack.id == Item.LEASH.id && !this.world.isStatic) {
|
||||
d0 = 7.0D;
|
||||
list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
|
||||
if (list != null) {
|
||||
iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
entityinsentient = (EntityInsentient) iterator.next();
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
|
||||
entityinsentient.b(this, true);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.world.isStatic && !flag) {
|
||||
this.die();
|
||||
if (entityhuman.abilities.canInstantlyBuild) {
|
||||
d0 = 7.0D;
|
||||
list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
|
||||
if (list != null) {
|
||||
iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
entityinsentient = (EntityInsentient) iterator.next();
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == this) {
|
||||
entityinsentient.a(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean survives() {
|
||||
int i = this.world.getTypeId(this.x, this.y, this.z);
|
||||
|
||||
return Block.byId[i] != null && Block.byId[i].d() == 11;
|
||||
}
|
||||
|
||||
public static EntityLeash a(World world, int i, int j, int k) {
|
||||
EntityLeash entityleash = new EntityLeash(world, i, j, k);
|
||||
|
||||
entityleash.p = true;
|
||||
world.addEntity(entityleash);
|
||||
return entityleash;
|
||||
}
|
||||
|
||||
public static EntityLeash b(World world, int i, int j, int k) {
|
||||
List list = world.a(EntityLeash.class, AxisAlignedBB.a().a((double) i - 1.0D, (double) j - 1.0D, (double) k - 1.0D, (double) i + 1.0D, (double) j + 1.0D, (double) k + 1.0D));
|
||||
Object object = null;
|
||||
|
||||
if (list != null) {
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityLeash entityleash = (EntityLeash) iterator.next();
|
||||
|
||||
if (entityleash.x == i && entityleash.y == j && entityleash.z == k) {
|
||||
return entityleash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
53
src/main/java/net/minecraft/server/ItemLeash.java
Normal file
53
src/main/java/net/minecraft/server/ItemLeash.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package net.minecraft.server;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemLeash extends Item {
|
||||
|
||||
public ItemLeash(int i) {
|
||||
super(i);
|
||||
this.a(CreativeModeTab.i);
|
||||
}
|
||||
|
||||
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
|
||||
int i1 = world.getTypeId(i, j, k);
|
||||
|
||||
if (Block.byId[i1] != null && Block.byId[i1].d() == 11) {
|
||||
if (world.isStatic) {
|
||||
return true;
|
||||
} else {
|
||||
a(entityhuman, world, i, j, k);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean a(EntityHuman entityhuman, World world, int i, int j, int k) {
|
||||
EntityLeash entityleash = EntityLeash.b(world, i, j, k);
|
||||
boolean flag = false;
|
||||
double d0 = 7.0D;
|
||||
List list = world.a(EntityInsentient.class, AxisAlignedBB.a().a((double) i - d0, (double) j - d0, (double) k - d0, (double) i + d0, (double) j + d0, (double) k + d0));
|
||||
|
||||
if (list != null) {
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityInsentient entityinsentient = (EntityInsentient) iterator.next();
|
||||
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
|
||||
if (entityleash == null) {
|
||||
entityleash = EntityLeash.a(world, i, j, k);
|
||||
}
|
||||
|
||||
entityinsentient.b(entityleash, true);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue