[1.6.4] Получение энтити

435
1
В общем нужно получить энтити на которого смотрит игрок.
[merge_posts_bbcode]Добавлено: 20.05.2015 20:44:37[/merge_posts_bbcode]

И работать с этим энтитем.
 
Agravaine написал(а):
EntityRenderer#getMouseOver.
Тогда вопрос: где брать partialTickTime для этого метода?
[merge_posts_bbcode]Добавлено: 20.05.2015 21:16:07[/merge_posts_bbcode]

Так я получил энтитя, но мне нужен энтить предмета.
 
Прикол в том что вроде как получается энтити (вообще любой), но не предмет.
 
Код:
entity.canBeCollidedWith()
Типа убрать это из условия (или сделать нужные условия).
[merge_posts_bbcode]Добавлено: 20.05.2015 19:26:25[/merge_posts_bbcode]

Подобное обсуждали, но вроде для 1.7.10.
 
Допустим я получил энтити. Теперь вопрос - как можно отправить полученного энтитя на сервер и работать с ним?
 
Код:
@SideOnly(Side.CLIENT)
    public static Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith) {
        Minecraft mc = Minecraft.getMinecraft();
        Entity pointedEntity = null;
        MovingObjectPosition rayTrace;
        if (mc.renderViewEntity != null) {
            if (mc.theWorld != null) {
                rayTrace = mc.renderViewEntity.rayTrace(distance, partialTicks);
                Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks);
                double distanceToVec3 = distance;

                if (rayTrace != null) {
                    distanceToVec3 = rayTrace.hitVec.distanceTo(positionVec);
                }

                Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks);
                Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance);
                Vec3 tempVec = null;
                double boxExpand = 1.0F;
                List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand));
                double vecInsideDist = distanceToVec3;

                for (Entity entity : entities) {
                    if (!canBeCollidedWith || entity.canBeCollidedWith()) {
                        double borderSize = entity.getCollisionBorderSize();
                        AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize);
                        MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec);

                        if (expEntityBox.isVecInside(positionVec)) {
                            if (0.0D < vecInsideDist || vecInsideDist == 0.0D) {
                                pointedEntity = entity;
                                tempVec = calculateInterceptPos == null ? positionVec : calculateInterceptPos.hitVec;
                                vecInsideDist = 0.0D;
                            }
                        } else if (calculateInterceptPos != null) {
                            double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec);

                            if (calcInterceptPosDist < vecInsideDist || vecInsideDist == 0.0D) {
                                if (entity == mc.renderViewEntity.ridingEntity && !entity.canRiderInteract()) {
                                    if (vecInsideDist == 0.0D) {
                                        pointedEntity = entity;
                                        tempVec = calculateInterceptPos.hitVec;
                                    }
                                } else {
                                    pointedEntity = entity;
                                    tempVec = calculateInterceptPos.hitVec;
                                    vecInsideDist = calcInterceptPosDist;
                                }
                            }
                        }
                    }
                }

                if (pointedEntity != null && (vecInsideDist < distanceToVec3 || rayTrace == null)) {
                    return pointedEntity;
                }
            }
        }

        return null;
    }
 
Да ну, клиент, серьезно? Если скопипастить метод, но делать на сервере, то всё должно работать. Ибо коллайды и коорды на сервере тоже есть, как миленькие. И поворот головы игрока. А partialRenderTime ставь ноль, там как раз лишний бред сократится.
 
Назад
Сверху