use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.
the class LeadItemMixin_1_14 method attachToFence.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static boolean attachToFence(PlayerEntity player, World worldIn, BlockPos fence) {
LeashKnotEntity leashknotentity = null;
boolean flag = false;
double d0 = 7.0D;
int i = fence.getX();
int j = fence.getY();
int k = fence.getZ();
for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
if (mobentity.getLeashHolder() == player) {
if (leashknotentity == null) {
leashknotentity = LeashKnotEntity.create(worldIn, fence);
HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
leashknotentity.remove();
return false;
}
}
if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
continue;
}
mobentity.setLeashHolder(leashknotentity, true);
flag = true;
}
}
return flag;
}
use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.
the class LeashKnotEntityMixin method processInitialInteract.
/**
* @author IzzelAliz
* @reason
*/
@SuppressWarnings("ConstantConditions")
@Overwrite
public boolean processInitialInteract(final PlayerEntity entityhuman, final Hand enumhand) {
if (this.world.isRemote) {
return true;
}
boolean flag = false;
final double d0 = 7.0;
final List<MobEntity> list = this.world.getEntitiesWithinAABB((Class<? extends MobEntity>) MobEntity.class, new AxisAlignedBB(this.posX - 7.0, this.posY - 7.0, this.posZ - 7.0, this.posX + 7.0, this.posY + 7.0, this.posZ + 7.0));
for (final MobEntity entityinsentient : list) {
if (entityinsentient.getLeashHolder() == entityhuman) {
if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, (LeashKnotEntity) (Object) this, entityhuman).isCancelled()) {
((ServerPlayerEntity) entityhuman).connection.sendPacket(new SMountEntityPacket(entityinsentient, entityinsentient.getLeashHolder()));
} else {
entityinsentient.setLeashHolder((LeashKnotEntity) (Object) this, true);
flag = true;
}
}
}
if (!flag) {
boolean die = true;
for (final MobEntity entityinsentient : list) {
if (entityinsentient.getLeashed() && entityinsentient.getLeashHolder() == (Object) this) {
if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
die = false;
} else {
entityinsentient.clearLeashed(true, !entityhuman.abilities.isCreativeMode);
}
}
}
if (die) {
this.remove();
}
}
return true;
}
use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.
the class LeadItemMixin_1_15 method bindPlayerMobs.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static ActionResultType bindPlayerMobs(PlayerEntity player, World worldIn, BlockPos fence) {
LeashKnotEntity leashknotentity = null;
boolean flag = false;
double d0 = 7.0D;
int i = fence.getX();
int j = fence.getY();
int k = fence.getZ();
for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
if (mobentity.getLeashHolder() == player) {
if (leashknotentity == null) {
leashknotentity = LeashKnotEntity.create(worldIn, fence);
HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
leashknotentity.remove();
return ActionResultType.PASS;
}
}
if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
continue;
}
mobentity.setLeashHolder(leashknotentity, true);
flag = true;
}
}
return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
Aggregations