use of net.minecraft.entity.passive.fish.AbstractFishEntity in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processUseEntity.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processUseEntity(final CUseEntityPacket packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
final ServerWorld world = this.minecraftServer.getWorld(this.player.dimension);
final Entity entity = packetIn.getEntityFromWorld(world);
this.player.markPlayerActive();
if (entity != null) {
final boolean flag = this.player.canEntityBeSeen(entity);
double d0 = 36.0;
if (!flag) {
d0 = 9.0;
}
if (this.player.getDistanceSq(entity) < d0) {
final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand());
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity;
final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem();
PlayerInteractEntityEvent event;
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
} else {
final Vec3d target = packetIn.getHitVec();
event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
}
this.server.getPluginManager().callEvent(event);
if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SSpawnMobPacket((LivingEntity) entity));
this.player.sendContainerToPlayer(this.player.openContainer);
}
if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder()));
}
if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) {
this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true));
}
if (event.isCancelled()) {
return;
}
}
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
final Hand hand = packetIn.getHand();
this.player.interactOn(entity, hand);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final Hand hand = packetIn.getHand();
if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null)
return;
ActionResultType result = entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand);
if (result == ActionResultType.SUCCESS) {
this.player.swingArm(hand);
}
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) {
if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) {
this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked"));
this.minecraftServer.logWarning("Player " + this.player.getName().getString() + " tried to attack an invalid entity");
return;
}
this.player.attackTargetEntityWithCurrentItem(entity);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
}
}
}
}
Aggregations