Search in sources :

Example 1 with Entity

use of net.minecraft.world.entity.Entity in project MinecraftForge by MinecraftForge.

the class ForgeIngameGui method renderHealthMount.

protected void renderHealthMount(int width, int height, PoseStack mStack) {
    Player player = (Player) minecraft.getCameraEntity();
    Entity tmp = player.getVehicle();
    if (!(tmp instanceof LivingEntity))
        return;
    bind(GUI_ICONS_LOCATION);
    boolean unused = false;
    int left_align = width / 2 + 91;
    minecraft.getProfiler().popPush("mountHealth");
    RenderSystem.enableBlend();
    LivingEntity mount = (LivingEntity) tmp;
    int health = (int) Math.ceil((double) mount.getHealth());
    float healthMax = mount.getMaxHealth();
    int hearts = (int) (healthMax + 0.5F) / 2;
    if (hearts > 30)
        hearts = 30;
    final int MARGIN = 52;
    final int BACKGROUND = MARGIN + (unused ? 1 : 0);
    final int HALF = MARGIN + 45;
    final int FULL = MARGIN + 36;
    for (int heart = 0; hearts > 0; heart += 20) {
        int top = height - right_height;
        int rowCount = Math.min(hearts, 10);
        hearts -= rowCount;
        for (int i = 0; i < rowCount; ++i) {
            int x = left_align - i * 8 - 9;
            blit(mStack, x, top, BACKGROUND, 9, 9, 9);
            if (i * 2 + 1 + heart < health)
                blit(mStack, x, top, FULL, 9, 9, 9);
            else if (i * 2 + 1 + heart == health)
                blit(mStack, x, top, HALF, 9, 9, 9);
        }
        right_height += 10;
    }
    RenderSystem.disableBlend();
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player)

Example 2 with Entity

use of net.minecraft.world.entity.Entity in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method setSpawnerSpawnedType.

@Override
public void setSpawnerSpawnedType(CreatureSpawner spawner, EntityTag entity) {
    spawner.setSpawnedType(entity.getBukkitEntityType());
    if (entity.getWaitingMechanisms() == null || entity.getWaitingMechanisms().size() == 0) {
        return;
    }
    try {
        // Wrangle a fake entity
        Entity nmsEntity = ((CraftWorld) spawner.getWorld()).createEntity(spawner.getLocation(), entity.getBukkitEntityType().getEntityClass());
        EntityTag entityTag = new EntityTag(nmsEntity.getBukkitEntity());
        entityTag.isFake = true;
        entityTag.isFakeValid = true;
        for (Mechanism mechanism : entity.getWaitingMechanisms()) {
            entityTag.safeAdjustDuplicate(mechanism);
        }
        nmsEntity.unsetRemoved();
        // Store it into the spawner
        CraftCreatureSpawner bukkitSpawner = (CraftCreatureSpawner) spawner;
        SpawnerBlockEntity nmsSnapshot = (SpawnerBlockEntity) craftBlockEntityState_snapshot.get(bukkitSpawner);
        BaseSpawner nmsSpawner = nmsSnapshot.getSpawner();
        SpawnData toSpawn = nmsSpawner.nextSpawnData;
        net.minecraft.nbt.CompoundTag tag = toSpawn.getEntityToSpawn();
        nmsEntity.saveWithoutId(tag);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BaseSpawner(net.minecraft.world.level.BaseSpawner) EntityTag(com.denizenscript.denizen.objects.EntityTag) SpawnData(net.minecraft.world.level.SpawnData) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Mechanism(com.denizenscript.denizencore.objects.Mechanism)

Example 3 with Entity

use of net.minecraft.world.entity.Entity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method tryProcessMovePacketForAttach.

public void tryProcessMovePacketForAttach(ClientboundMoveEntityPacket packet, Entity e) throws IllegalAccessException {
    EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUUID());
    if (attList != null) {
        for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
            EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUUID());
            if (attMap.attached.isValid() && att != null) {
                ClientboundMoveEntityPacket pNew;
                int newId = att.attached.getBukkitEntity().getEntityId();
                if (packet instanceof ClientboundMoveEntityPacket.Pos) {
                    pNew = new ClientboundMoveEntityPacket.Pos(newId, packet.getXa(), packet.getYa(), packet.getZa(), packet.isOnGround());
                } else if (packet instanceof ClientboundMoveEntityPacket.Rot) {
                    pNew = new ClientboundMoveEntityPacket.Rot(newId, packet.getyRot(), packet.getxRot(), packet.isOnGround());
                } else if (packet instanceof ClientboundMoveEntityPacket.PosRot) {
                    pNew = new ClientboundMoveEntityPacket.PosRot(newId, packet.getXa(), packet.getYa(), packet.getZa(), packet.getyRot(), packet.getxRot(), packet.isOnGround());
                } else {
                    if (Debug.verbose) {
                        Debug.echoError("Impossible move-entity packet class: " + packet.getClass().getCanonicalName());
                    }
                    return;
                }
                if (att.positionalOffset != null && (packet instanceof ClientboundMoveEntityPacket.Pos || packet instanceof ClientboundMoveEntityPacket.PosRot)) {
                    boolean isRotate = packet instanceof ClientboundMoveEntityPacket.PosRot;
                    byte yaw, pitch;
                    if (att.noRotate) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        yaw = EntityAttachmentHelper.compressAngle(attachedEntity.getYRot());
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    } else if (isRotate) {
                        yaw = packet.getyRot();
                        pitch = packet.getxRot();
                    } else {
                        yaw = EntityAttachmentHelper.compressAngle(e.getYRot());
                        pitch = EntityAttachmentHelper.compressAngle(e.getXRot());
                    }
                    if (att.noPitch) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    }
                    byte newYaw = yaw;
                    if (isRotate) {
                        newYaw = EntityAttachmentHelper.adaptedCompressedAngle(newYaw, att.positionalOffset.getYaw());
                        pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
                    }
                    Vector goalPosition = att.fixedForOffset(new Vector(e.getX(), e.getY(), e.getZ()), e.getYRot(), e.getXRot());
                    Vector oldPos = att.visiblePositions.get(player.getUUID());
                    boolean forceTele = false;
                    if (oldPos == null) {
                        oldPos = att.attached.getLocation().toVector();
                        forceTele = true;
                    }
                    Vector moveNeeded = goalPosition.clone().subtract(oldPos);
                    att.visiblePositions.put(player.getUUID(), goalPosition.clone());
                    int offX = (int) (moveNeeded.getX() * (32 * 128));
                    int offY = (int) (moveNeeded.getY() * (32 * 128));
                    int offZ = (int) (moveNeeded.getZ() * (32 * 128));
                    if (forceTele || offX < Short.MIN_VALUE || offX > Short.MAX_VALUE || offY < Short.MIN_VALUE || offY > Short.MAX_VALUE || offZ < Short.MIN_VALUE || offZ > Short.MAX_VALUE) {
                        ClientboundTeleportEntityPacket newTeleportPacket = new ClientboundTeleportEntityPacket(e);
                        ENTITY_ID_PACKTELENT.setInt(newTeleportPacket, att.attached.getBukkitEntity().getEntityId());
                        POS_X_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getX());
                        POS_Y_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getY());
                        POS_Z_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getZ());
                        YAW_PACKTELENT.setByte(newTeleportPacket, newYaw);
                        PITCH_PACKTELENT.setByte(newTeleportPacket, pitch);
                        if (NMSHandler.debugPackets) {
                            Debug.log("Attach Move-Tele Packet: " + newTeleportPacket.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with original yaw " + yaw + " adapted to " + newYaw);
                        }
                        oldManager.send(newTeleportPacket);
                    } else {
                        POS_X_PACKENT.setShort(pNew, (short) Mth.clamp(offX, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Y_PACKENT.setShort(pNew, (short) Mth.clamp(offY, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Z_PACKENT.setShort(pNew, (short) Mth.clamp(offZ, Short.MIN_VALUE, Short.MAX_VALUE));
                        if (isRotate) {
                            YAW_PACKENT.setByte(pNew, yaw);
                            PITCH_PACKENT.setByte(pNew, pitch);
                        }
                        if (NMSHandler.debugPackets) {
                            Debug.log("Attach Move Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with original yaw " + yaw + " adapted to " + newYaw);
                        }
                        oldManager.send(pNew);
                    }
                } else {
                    if (NMSHandler.debugPackets) {
                        Debug.log("Attach Replica-Move Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName());
                    }
                    oldManager.send(pNew);
                }
            }
        }
    }
    if (e.passengers != null && !e.passengers.isEmpty()) {
        for (Entity ent : e.passengers) {
            tryProcessMovePacketForAttach(packet, ent);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) SectionPos(net.minecraft.core.SectionPos) BlockPos(net.minecraft.core.BlockPos) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Example 4 with Entity

use of net.minecraft.world.entity.Entity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method getModifiedMetadataFor.

public ClientboundSetEntityDataPacket getModifiedMetadataFor(ClientboundSetEntityDataPacket metadataPacket) {
    if (!RenameCommand.hasAnyDynamicRenames() && SneakCommand.forceSetSneak.isEmpty()) {
        return null;
    }
    try {
        int eid = metadataPacket.getId();
        Entity ent = player.level.getEntity(eid);
        if (ent == null) {
            // If it doesn't exist on-server, it's definitely not relevant, so move on
            return null;
        }
        String nameToApply = RenameCommand.getCustomNameFor(ent.getUUID(), player.getBukkitEntity(), false);
        Boolean forceSneak = SneakCommand.shouldSneak(ent.getUUID(), player.getUUID());
        if (nameToApply == null && forceSneak == null) {
            return null;
        }
        List<SynchedEntityData.DataItem<?>> data = new ArrayList<>(metadataPacket.getUnpackedData());
        boolean any = false;
        for (int i = 0; i < data.size(); i++) {
            SynchedEntityData.DataItem<?> item = data.get(i);
            EntityDataAccessor<?> watcherObject = item.getAccessor();
            int watcherId = watcherObject.getId();
            if (watcherId == 0 && forceSneak != null) {
                // 0: Entity flags
                byte val = (Byte) item.getValue();
                if (forceSneak) {
                    // 8: Crouching
                    val |= 0x02;
                } else {
                    val &= ~0x02;
                }
                data.set(i, new SynchedEntityData.DataItem(watcherObject, val));
                any = true;
            } else if (watcherId == 2 && nameToApply != null) {
                // 2: Custom name metadata
                Optional<Component> name = Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(nameToApply, ChatColor.WHITE)));
                data.set(i, new SynchedEntityData.DataItem(watcherObject, name));
                any = true;
            } else if (watcherId == 3 && nameToApply != null) {
                // 3: custom name visible metadata
                data.set(i, new SynchedEntityData.DataItem(watcherObject, true));
                any = true;
            }
        }
        if (!any) {
            return null;
        }
        ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
        ENTITY_METADATA_LIST.set(altPacket, data);
        return altPacket;
    } catch (Throwable ex) {
        Debug.echoError(ex);
        return null;
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData)

Example 5 with Entity

use of net.minecraft.world.entity.Entity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processAttachToForPacket.

public boolean processAttachToForPacket(Packet<?> packet) {
    if (EntityAttachmentHelper.toEntityToData.isEmpty()) {
        return false;
    }
    try {
        if (packet instanceof ClientboundMoveEntityPacket) {
            Entity e = ((ClientboundMoveEntityPacket) packet).getEntity(player.getLevel());
            if (e == null) {
                return false;
            }
            if (!e.isPassenger()) {
                tryProcessMovePacketForAttach((ClientboundMoveEntityPacket) packet, e);
            }
            return EntityAttachmentHelper.denyOriginalPacketSend(player.getUUID(), e.getUUID());
        } else if (packet instanceof ClientboundSetEntityMotionPacket) {
            int ider = ((ClientboundSetEntityMotionPacket) packet).getId();
            Entity e = player.getLevel().getEntity(ider);
            if (e == null) {
                return false;
            }
            tryProcessVelocityPacketForAttach((ClientboundSetEntityMotionPacket) packet, e);
            return EntityAttachmentHelper.denyOriginalPacketSend(player.getUUID(), e.getUUID());
        } else if (packet instanceof ClientboundTeleportEntityPacket) {
            int ider = ((ClientboundTeleportEntityPacket) packet).getId();
            Entity e = player.getLevel().getEntity(ider);
            if (e == null) {
                return false;
            }
            tryProcessTeleportPacketForAttach((ClientboundTeleportEntityPacket) packet, e, VECTOR_ZERO);
            return EntityAttachmentHelper.denyOriginalPacketSend(player.getUUID(), e.getUUID());
        }
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
    return false;
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity)

Aggregations

Entity (net.minecraft.world.entity.Entity)22 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)9 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)9 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)8 LivingEntity (org.bukkit.entity.LivingEntity)8 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)6 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)4 LivingEntity (net.minecraft.world.entity.LivingEntity)4 Vector (org.bukkit.util.Vector)4 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)3 ItemStack (net.minecraft.world.item.ItemStack)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 FakeEquipCommand (com.denizenscript.denizen.scripts.commands.entity.FakeEquipCommand)2 DisguiseCommand (com.denizenscript.denizen.scripts.commands.player.DisguiseCommand)2 Pair (com.mojang.datafixers.util.Pair)2 BlockPos (net.minecraft.core.BlockPos)2 NonNullList (net.minecraft.core.NonNullList)2 SectionPos (net.minecraft.core.SectionPos)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2