Java Code Examples for codechicken.lib.math.MathHelper#clip()

The following examples show how to use codechicken.lib.math.MathHelper#clip() . 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: GuiItemSorter.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void updateScreen() {
    super.updateScreen();

    int my = getMousePosition().y;
    for (SortItem item : slots) {
        item.update(my);
    }

    if (dragging) {
        int nslot = (int) MathHelper.clip((dragged.y - (2 - 12)) / 24, 0, slots.size() - 1);
        if (nslot != list.indexOf(dragged.e)) {
            list.remove(dragged.e);
            list.add(nslot, dragged.e);
            opt.getTag().setValue(ItemSorter.getSaveString(list));
            if (opt.activeTag() == opt.getTag()) {
                ItemSorter.list = new ArrayList<>(list);
            }
        }
    }
}
 
Example 2
Source File: GuiItemSorter.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void updateScreen() {
    super.updateScreen();

    int my = getMousePosition().y;
    for(SortItem item : slots)
        item.update(my);

    if(dragging) {
        int nslot = (int)MathHelper.clip((dragged.y-(2-12))/24, 0, slots.size()-1);
        if(nslot != list.indexOf(dragged.e)) {
            list.remove(dragged.e);
            list.add(nslot, dragged.e);
            opt.getTag().setValue(ItemSorter.getSaveString(list));
            if(opt.activeTag() == opt.getTag())
                ItemSorter.list = new ArrayList<SortEntry>(list);
        }
    }
}
 
Example 3
Source File: Colour.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Colour multiplyC(double d) {
    r = (byte) MathHelper.clip((r & 0xFF) * d, 0, 255);
    g = (byte) MathHelper.clip((g & 0xFF) * d, 0, 255);
    b = (byte) MathHelper.clip((b & 0xFF) * d, 0, 255);

    return this;
}
 
Example 4
Source File: GuiHighlightTips.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public Point getDrag() {
    Point mouse = getMousePosition();
    Point drag = new Point(mouse.x - dragDown.x, mouse.y - dragDown.y);
    Dimension size = displaySize();
    Dimension sample = sampleSize();
    drag.x *= 10000;
    drag.y *= 10000;
    drag.x /= (size.width - sample.width);
    drag.y /= (size.height - sample.height);
    Point pos = getPos();
    drag.x = (int) MathHelper.clip(drag.x, -pos.x, 10000 - pos.x);
    drag.y = (int) MathHelper.clip(drag.y, -pos.y, 10000 - pos.y);
    return drag;
}
 
Example 5
Source File: GuiScrollPane.java    From CodeChickenCore with MIT License 5 votes vote down vote up
public void calculatePercentScrolled() {
    int barempty = height - scrollbarDim().height;
    if (isScrolling()) {
        int scrolldiff = scrollmousey - scrollclicky;
        percentscrolled = scrolldiff / (float) barempty + scrollpercent;
    }
    percentscrolled = (float) MathHelper.clip(percentscrolled, 0, 1);
}
 
Example 6
Source File: Colour.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Colour multiplyC(double d) {
    r = (byte) MathHelper.clip((r & 0xFF) * d, 0, 255);
    g = (byte) MathHelper.clip((g & 0xFF) * d, 0, 255);
    b = (byte) MathHelper.clip((b & 0xFF) * d, 0, 255);

    return this;
}
 
Example 7
Source File: CustomGradient.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public int getColourI(double position) {
    int off = (int) MathHelper.clip(gradient.length * position, 0, gradient.length - 1);
    return gradient[off];
}
 
Example 8
Source File: WorldOverlayRenderer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void renderMobSpawnOverlay(Entity entity) {
    if (mobOverlay == 0) {
        return;
    }

    boolean cms = Loader.instance().isModLoaded("customspawner");

    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    glLineWidth(1.5F);
    glBegin(GL_LINES);

    GlStateManager.color(1, 0, 0);

    World world = entity.world;
    int x1 = (int) entity.posX;
    int z1 = (int) entity.posZ;
    int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);

    for (int x = x1 - 16; x <= x1 + 16; x++) {
        for (int z = z1 - 16; z <= z1 + 16; z++) {
            BlockPos pos = new BlockPos(x, y1, z);
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            Biome biome = world.getBiome(pos);
            if ((!cms && biome.getSpawnableList(EnumCreatureType.MONSTER).isEmpty()) || biome.getSpawningChance() <= 0) {
                continue;
            }

            for (int y = y1 - 16; y < y1 + 16; y++) {
                int spawnMode = getSpawnMode(chunk, x, y, z);
                if (spawnMode == 0) {
                    continue;
                }

                if (spawnMode == 1) {
                    GlStateManager.color(1, 1, 0);
                } else {
                    GlStateManager.color(1, 0, 0);
                }

                glVertex3d(x, y + 0.004, z);
                glVertex3d(x + 1, y + 0.004, z + 1);
                glVertex3d(x + 1, y + 0.004, z);
                glVertex3d(x, y + 0.004, z + 1);
            }
        }
    }

    glEnd();
    GlStateManager.enableLighting();
    GlStateManager.enableTexture2D();
}
 
Example 9
Source File: WorldOverlayRenderer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void renderMobSpawnOverlay(Entity entity) {
    if (mobOverlay == 0)
        return;

    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    glLineWidth(1.5F);
    glBegin(GL_LINES);

    GlStateManager.color(1, 0, 0);

    World world = entity.worldObj;
    int x1 = (int) entity.posX;
    int z1 = (int) entity.posZ;
    int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);

    for (int x = x1 - 16; x <= x1 + 16; x++)
        for (int z = z1 - 16; z <= z1 + 16; z++) {
            BlockPos pos = new BlockPos(x, y1, z);
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            BiomeGenBase biome = world.getBiomeGenForCoords(pos);
            if (biome.getSpawnableList(EnumCreatureType.MONSTER).isEmpty() || biome.getSpawningChance() <= 0)
                continue;

            for (int y = y1 - 16; y < y1 + 16; y++) {
                int spawnMode = getSpawnMode(chunk, x, y, z);
                if (spawnMode == 0)
                    continue;

                if (spawnMode == 1)
                    GlStateManager.color(1, 1, 0);
                else
                    GlStateManager.color(1, 0, 0);

                glVertex3d(x, y + 0.004, z);
                glVertex3d(x + 1, y + 0.004, z + 1);
                glVertex3d(x + 1, y + 0.004, z);
                glVertex3d(x, y + 0.004, z + 1);
            }
        }

    glEnd();
    GlStateManager.enableLighting();
    GlStateManager.enableTexture2D();
}
 
Example 10
Source File: CustomGradient.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public int getColourI(double position)
{
    int off = (int)MathHelper.clip(gradient.length*position, 0, gradient.length-1);
    return gradient[off];
}