Java Code Examples for net.minecraft.entity.item.EntityItem#setVelocity()

The following examples show how to use net.minecraft.entity.item.EntityItem#setVelocity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MagnetModeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SubscribeEvent
@SideOnly (Side.CLIENT)
public void clientTickEvent(TickEvent.ClientTickEvent event) {

    if (event.phase == Phase.END || Minecraft.getMinecraft().world == null) {
        return;
    }
    if (!NEIClientConfig.isMagnetModeEnabled()) {
        return;
    }
    EntityPlayer player = Minecraft.getMinecraft().player;

    Iterator<EntityItem> iterator = clientMagnetItems.iterator();
    while (iterator.hasNext()) {
        EntityItem item = iterator.next();
        if (item.cannotPickup()) {
            continue;
        }
        if (item.isDead) {
            iterator.remove();
        }
        if (item.getEntityData().getBoolean("PreventRemoteMovement")) {
            continue;
        }
        if (!NEIClientUtils.canItemFitInInventory(player, item.getItem())) {
            continue;
        }
        double dx = player.posX - item.posX;
        double dy = player.posY + player.getEyeHeight() - item.posY;
        double dz = player.posZ - item.posZ;
        double absxz = Math.sqrt(dx * dx + dz * dz);
        double absy = Math.abs(dy);
        if (absxz > DISTANCE_XZ || absy > DISTANCE_Y) {
            continue;
        }

        if (absxz > 1) {
            dx /= absxz;
            dz /= absxz;
        }

        if (absy > 1) {
            dy /= absy;
        }

        double vx = item.motionX + SPEED_XZ * dx;
        double vy = item.motionY + SPEED_Y * dy;
        double vz = item.motionZ + SPEED_XZ * dz;

        double absvxz = Math.sqrt(vx * vx + vz * vz);
        double absvy = Math.abs(vy);

        double rationspeedxz = absvxz / MAX_SPEED_XZ;
        if (rationspeedxz > 1) {
            vx /= rationspeedxz;
            vz /= rationspeedxz;
        }

        double rationspeedy = absvy / MAX_SPEED_Y;
        if (rationspeedy > 1) {
            vy /= rationspeedy;
        }

        if (absvxz < 0.2 && absxz < 0.2) {
            item.setDead();
        }

        item.setVelocity(vx, vy, vz);
    }
}
 
Example 2
Source File: ClientHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private void updateMagnetMode(World world, EntityPlayerSP player) {
    if (!NEIClientConfig.getMagnetMode()) return;

    float distancexz = 16;
    float distancey = 8;
    double maxspeedxz = 0.5;
    double maxspeedy = 0.5;
    double speedxz = 0.05;
    double speedy = 0.07;

    for (Iterator<EntityItem> iterator = SMPmagneticItems.iterator(); iterator.hasNext(); ) {
        EntityItem item = iterator.next();

        if (item.cannotPickup()) continue;
        if (item.isDead) iterator.remove();
        if (!NEIClientUtils.canItemFitInInventory(player, item.getEntityItem())) continue;

        double dx = player.posX - item.posX;
        double dy = player.posY + player.getEyeHeight() - item.posY;
        double dz = player.posZ - item.posZ;
        double absxz = Math.sqrt(dx * dx + dz * dz);
        double absy = Math.abs(dy);
        if (absxz > distancexz || absy > distancey)
            continue;

        if (absxz > 1) {
            dx /= absxz;
            dz /= absxz;
        }

        if (absy > 1) {
            dy /= absy;
        }

        double vx = item.motionX + speedxz * dx;
        double vy = item.motionY + speedy * dy;
        double vz = item.motionZ + speedxz * dz;

        double absvxz = Math.sqrt(vx * vx + vz * vz);
        double absvy = Math.abs(vy);

        double rationspeedxz = absvxz / maxspeedxz;
        if (rationspeedxz > 1) {
            vx /= rationspeedxz;
            vz /= rationspeedxz;
        }

        double rationspeedy = absvy / maxspeedy;
        if (rationspeedy > 1)
            vy /= rationspeedy;

        if (absvxz < 0.2 && absxz < 0.2)
            item.setDead();

        item.setVelocity(vx, vy, vz);
    }
}