codechicken.lib.math.MathHelper Java Examples
The following examples show how to use
codechicken.lib.math.MathHelper.
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: RenderWireless.java From WirelessRedstone with MIT License | 6 votes |
public static void renderPearl(Vector3 pos, WirelessPart p) { GL11.glPushMatrix(); pos.translation().glApply(); p.rotationT().at(center).glApply(); p.getPearlPos().translation().glApply(); p.getPearlRotation().glApply(); new Scale(p.getPearlScale()).glApply(); float light = 1; if (p.tile() != null) { GL11.glRotatef((float) (p.getPearlSpin() * MathHelper.todeg), 0, 1, 0); light = p.getPearlLight(); } GL11.glDisable(GL11.GL_LIGHTING); CCRenderState.reset(); CCRenderState.changeTexture("wrcbe_core:textures/hedronmap.png"); CCRenderState.pullLightmap(); CCRenderState.setColour(new ColourRGBA(light, light, light, 1).rgba()); CCRenderState.startDrawing(4); CCModelLibrary.icosahedron4.render(); CCRenderState.draw(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); }
Example #2
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 XYintercept(Vector3 end, double pz) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dz == 0) return null; double d = (pz - z) / dz; if (MathHelper.between(-1E-5, d, 1E-5)) return this; if (!MathHelper.between(0, d, 1)) return null; x += d * dx; y += d * dy; z = pz; return this; }
Example #3
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 XZintercept(Vector3 end, double py) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dy == 0) return null; double d = (py - y) / dy; if (MathHelper.between(-1E-5, d, 1E-5)) return this; if (!MathHelper.between(0, d, 1)) return null; x += d * dx; y = py; z += d * dz; return this; }
Example #4
Source File: RenderTileEnderTank.java From EnderStorage with MIT License | 6 votes |
public static void renderTank(CCRenderState ccrs, Matrix4 mat, IRenderTypeBuffer getter, int rotation, float valveRot, double yToCamera, Frequency freq, int pearlOffset) { renderEndPortal.render(mat, getter, yToCamera); ccrs.reset(); mat.translate(0.5, 0, 0.5); mat.rotate((-90 * (rotation + 2)) * MathHelper.torad, Vector3.Y_POS); ccrs.bind(baseType, getter); tankModel.render(ccrs, mat); Matrix4 valveMat = mat.copy().apply(new Rotation(valveRot, Vector3.Z_POS).at(new Vector3(0, 0.4165, 0))); valveModel.render(ccrs, valveMat, new UVTranslation(0, freq.hasOwner() ? 13 / 64D : 0)); ccrs.bind(buttonType, getter); EnumColour[] colours = freq.toArray(); for (int i = 0; i < 3; i++) { //noinspection IntegerDivisionInFloatingPointContext buttons[i].render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4))); } double time = ClientUtils.getRenderTime() + pearlOffset; Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.45 + RenderUtils.getPearlBob(time) * 2, 0), new Rotation(time / 3, Vector3.Y_POS), 0.04); ccrs.brightness = 15728880; ccrs.bind(pearlType, getter); CCModelLibrary.icosahedron4.render(ccrs, pearlMat); ccrs.reset(); }
Example #5
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 YZintercept(Vector3 end, double px) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dx == 0) return null; double d = (px - x) / dx; if (MathHelper.between(-1E-5, d, 1E-5)) return this; if (!MathHelper.between(0, d, 1)) return null; x = px; y += d * dy; z += d * dz; return this; }
Example #6
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 YZintercept(Vector3 end, double px) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dx == 0) { return null; } double d = (px - x) / dx; if (MathHelper.between(-1E-5, d, 1E-5)) { return this; } if (!MathHelper.between(0, d, 1)) { return null; } x = px; y += d * dy; z += d * dz; return this; }
Example #7
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 XZintercept(Vector3 end, double py) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dy == 0) { return null; } double d = (py - y) / dy; if (MathHelper.between(-1E-5, d, 1E-5)) { return this; } if (!MathHelper.between(0, d, 1)) { return null; } x += d * dx; y = py; z += d * dz; return this; }
Example #8
Source File: Vector3.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public Vector3 XYintercept(Vector3 end, double pz) { double dx = end.x - x; double dy = end.y - y; double dz = end.z - z; if (dz == 0) { return null; } double d = (pz - z) / dz; if (MathHelper.between(-1E-5, d, 1E-5)) { return this; } if (!MathHelper.between(0, d, 1)) { return null; } x += d * dx; y += d * dy; z = pz; return this; }
Example #9
Source File: CapabilityCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Notifies {@link CapabilityCache} of a {@link Block#onNeighborChange} event.<br/> * Marks all empty capabilities provided by <code>from</code> block, to be re-cached * next query. * * @param from The from position. */ public void onNeighborChanged(BlockPos from) { if (world == null || pos == null) { return; } BlockPos offset = from.subtract(pos); int diff = MathHelper.absSum(offset); int side = MathHelper.toSide(offset); if (side < 0 || diff != 1) { return; } Direction sideChanged = Direction.BY_INDEX[side]; Iterables.concat(selfCache.entrySet(), getCacheForSide(sideChanged).entrySet()).forEach(entry -> { Object2IntPair<LazyOptional<?>> pair = entry.getValue(); if (pair.getKey() != null && !pair.getKey().isPresent()) { pair.setKey(null); pair.setValue(ticks); } }); }
Example #10
Source File: TileEnderChest.java From EnderStorage with MIT License | 6 votes |
public void updateEntity() { super.updateEntity(); //update compatiblity if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 0) { rotation = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 3); } if(!worldObj.isRemote && (worldObj.getTotalWorldTime() % 20 == 0 || c_numOpen != storage.getNumOpen())) { c_numOpen = storage.getNumOpen(); worldObj.addBlockEvent(xCoord, yCoord, zCoord, EnderStorage.blockEnderChest, 1, c_numOpen); } b_lidAngle = a_lidAngle; a_lidAngle = MathHelper.approachLinear(a_lidAngle, c_numOpen > 0 ? 1 : 0, 0.1); if(b_lidAngle >= 0.5 && a_lidAngle < 0.5) worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); else if(b_lidAngle == 0 && a_lidAngle > 0) worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); }
Example #11
Source File: GuiItemSorter.java From NotEnoughItems with MIT License | 6 votes |
@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 #12
Source File: TileLiquidTranslocator.java From Translocators with MIT License | 6 votes |
public boolean update() { if(a_end == 1) return true; b_start = a_start; a_start = MathHelper.approachLinear(a_start, 1, 0.2); b_end = a_end; if(liquid.amount > 0) { liquid.amount = Math.max(liquid.amount-(fast ? 200 : 20), 0); return liquid.amount == 0; } a_end = MathHelper.approachLinear(a_end, 1, 0.2); return false; }
Example #13
Source File: TileTranslocatorRenderer.java From Translocators with MIT License | 6 votes |
private void renderLink(int src, int dst, double time, int x, int y, int z) { double d = ((time+src+dst*2)%10)/6; //0 is head for(int n = 0; n < 20; n++) { double dn = d-n*0.1; int spriteX = (int) (7-n*1.5-d*2); if(!MathHelper.between(0, dn, 1) || spriteX < 0) continue; Vector3 pos = getPath(src, dst, dn).add(x, y, z); double b = 1;//d*0.6+0.4; double s = 1;//d*0.6+0.4; double u1 = spriteX/8D; double u2 = u1+1/8D; double v1 = 0; double v2 = 1; RenderParticle.render(pos.x, pos.y, pos.z, gradient.getColour((dn-0.5)*1.2+0.5).multiplyC(b), s*0.12, u1, v1, u2, v2); } }
Example #14
Source File: RedstoneEtherServerAddons.java From WirelessRedstone with MIT License | 6 votes |
public void tickTriangs() { for (Entry<String, AddonPlayerInfo> entry : playerInfos.entrySet()) { EntityPlayer player = ServerUtils.getPlayer(entry.getKey()); for (Integer freq : entry.getValue().triangSet) { double spinto; if (!RedstoneEther.server().isFreqOn(freq)) { spinto = -1; } else if (isRemoteOn(player, freq)) { spinto = -2; } else { Vector3 strengthvec = getBroadcastVector(player, freq); if (strengthvec == null)//in another dimension { spinto = -2;//spin to a random place } else { spinto = (player.rotationYaw + 180) * MathHelper.torad - Math.atan2(-strengthvec.x, strengthvec.z);//spin to the transmitter vec } } WRAddonSPH.sendTriangAngleTo(player, freq, (float) spinto); } } }
Example #15
Source File: TileTranslocatorRenderer.java From Translocators with MIT License | 6 votes |
public static Vector3 getPath(int src, int dst, double d) { Vector3 v; if((src^1) == dst)//opposite v = sideVec[src^1].copy().multiply(d); else { Vector3 vsrc = sideVec[src^1]; Vector3 vdst = sideVec[dst^1]; Vector3 a = vsrc.copy().multiply(5/16D); Vector3 b = vdst.copy().multiply(6/16D); double sind = MathHelper.sin(d*Math.PI/2); double cosd = MathHelper.cos(d*Math.PI/2); v = a.multiply(sind).add(b.multiply(cosd-1)).add(vsrc.copy().multiply(3/16D)); } return v.add(sidePos[src]); }
Example #16
Source File: BlockTranslocator.java From Translocators with MIT License | 6 votes |
@Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) return true; MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z); TileTranslocator ttrans = (TileTranslocator) world.getTileEntity(x, y, z); if (hit != null) { if (hit.subHit < 6) { Vector3 vhit = new Vector3(hit.hitVec); vhit.add(-x - 0.5, -y - 0.5, -z - 0.5); vhit.apply(sideRotations[hit.subHit % 6].inverse()); if (MathHelper.between(-2 / 16D, vhit.x, 2 / 16D) && MathHelper.between(-2 / 16D, vhit.z, 2 / 16D)) hit.subHit += 6; } return ttrans.attachments[hit.subHit % 6].activate(player, hit.subHit / 6); } return false; }
Example #17
Source File: GuiItemSorter.java From NotEnoughItems with MIT License | 6 votes |
@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 #18
Source File: TileEnderChest.java From EnderStorage with MIT License | 6 votes |
@Override public void tick() { super.tick(); if (!world.isRemote && (world.getGameTime() % 20 == 0 || c_numOpen != getStorage().getNumOpen())) { c_numOpen = getStorage().getNumOpen(); world.addBlockEvent(getPos(), getBlockState().getBlock(), 1, c_numOpen); world.notifyNeighborsOfStateChange(pos, getBlockState().getBlock()); } b_lidAngle = a_lidAngle; a_lidAngle = MathHelper.approachLinear(a_lidAngle, c_numOpen > 0 ? 1 : 0, 0.1); if (b_lidAngle >= 0.5 && a_lidAngle < 0.5) { world.playSound(null, getPos(), EnderStorageConfig.useVanillaEnderChestSounds ? BLOCK_ENDER_CHEST_CLOSE : BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); } else if (b_lidAngle == 0 && a_lidAngle > 0) { world.playSound(null, getPos(), EnderStorageConfig.useVanillaEnderChestSounds ? BLOCK_ENDER_CHEST_OPEN : BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); } }
Example #19
Source File: TileTranslocatorRenderer.java From Translocators with MIT License | 5 votes |
private static Vector3 getPathNormal(int src, int dst, double d) { if((src^1) == dst) return sideVec[(src+4)%6].copy(); double sind = MathHelper.sin(d*Math.PI/2); double cosd = MathHelper.cos(d*Math.PI/2); Vector3 vsrc = sideVec[src^1].copy(); Vector3 vdst = sideVec[dst^1].copy(); return vsrc.multiply(sind).add(vdst.multiply(cosd)).normalize(); }
Example #20
Source File: RenderTileEnderTank.java From EnderStorage with MIT License | 5 votes |
@Override public void render(TileEnderTank enderTank, float partialTicks, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay) { CCRenderState ccrs = CCRenderState.instance(); ccrs.brightness = packedLight; ccrs.overlay = packedOverlay; float valveRot = (float) MathHelper.interpolate(enderTank.pressure_state.b_rotate, enderTank.pressure_state.a_rotate, partialTicks) * 0.01745F; int pearlOffset = RenderUtils.getTimeOffset(enderTank.getPos()); Matrix4 mat = new Matrix4(mStack); double yToCamera = enderTank.getPos().getY() - renderDispatcher.renderInfo.getProjectedView().y; renderTank(ccrs, mat.copy(), getter, enderTank.rotation, valveRot, yToCamera, enderTank.getFrequency(), pearlOffset); renderFluid(ccrs, mat, getter, enderTank.liquid_state.c_liquid); ccrs.reset(); }
Example #21
Source File: RenderTileEnderChest.java From EnderStorage with MIT License | 5 votes |
public static void renderChest(CCRenderState ccrs, MatrixStack mStack, IRenderTypeBuffer getter, int rotation, double yToCamera, Frequency freq, float lidAngle, int pearlOffset) { Matrix4 mat = new Matrix4(mStack); if (lidAngle != 0) {//Micro optimization, lid closed, dont render starfield. renderEndPortal.render(mat, getter, yToCamera); } ccrs.reset(); mStack.push(); mStack.translate(0, 1.0, 1.0); mStack.scale(1.0F, -1.0F, -1.0F); mStack.translate(0.5, 0.5, 0.5); mStack.rotate(new Quaternion(0, rotation * 90, 0, true)); mStack.translate(-0.5, -0.5, -0.5); model.chestLid.rotateAngleX = lidAngle; model.render(mStack, getter.getBuffer(chestType), ccrs.brightness, ccrs.overlay, freq.hasOwner()); mStack.pop(); //Buttons ccrs.bind(buttonType, getter); EnumColour[] colours = freq.toArray(); for (int i = 0; i < 3; i++) { CCModel button = ButtonModelLibrary.button.copy(); button.apply(BlockEnderChest.buttonT[i]); button.apply(new Translation(0.5, 0, 0.5)); button.apply(new Rotation(lidAngle, 1, 0, 0).at(new Vector3(0, 9D / 16D, 1 / 16D))); button.apply(new Rotation((-90 * (rotation)) * MathHelper.torad, Vector3.Y_POS).at(new Vector3(0.5, 0, 0.5))); button.render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4))); } mat.translate(0.5, 0, 0.5); //Pearl if (lidAngle != 0) {//Micro optimization, lid closed, dont render pearl. double time = ClientUtils.getRenderTime() + pearlOffset; Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.2 + lidAngle * -0.5 + RenderUtils.getPearlBob(time), 0), new Rotation(time / 3, new Vector3(0, 1, 0)), 0.04); ccrs.brightness = 15728880; ccrs.bind(pearlType, getter); CCModelLibrary.icosahedron4.render(ccrs, pearlMat); } ccrs.reset(); }
Example #22
Source File: TankLayerRenderer.java From EnderStorage with MIT License | 5 votes |
@Override public void render(MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, AbstractClientPlayerEntity entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { if (UUIDS.contains(entity.getUniqueID())) { CCRenderState ccrs = CCRenderState.instance(); ccrs.brightness = packedLight; ccrs.overlay = OverlayTexture.NO_OVERLAY; Matrix4 mat = new Matrix4(mStack); mat.rotate(MathHelper.torad * 180, Vector3.X_POS); mat.scale(0.5); if (entity.isShiftKeyDown()) { mat.translate(0, -0.5, 0); } if (entity.isElytraFlying()) { headPitch = -45; } mat.rotate(netHeadYaw * MathHelper.torad, Vector3.Y_NEG); mat.rotate(headPitch * MathHelper.torad, Vector3.X_POS); mat.translate(-0.5, 1, -0.5); RenderTileEnderTank.renderTank(ccrs, mat, getter, 0, (float) (MathHelper.torad * 90F), 0, BLANK, 0); FluidStack stack = FluidUtils.water.copy(); float bob = 0.45F + RenderUtils.getPearlBob(ClientUtils.getRenderTime()) * 2; stack.setAmount((int) MathHelper.map(bob, 0.2, 0.6, 1000, 14000)); mat.translate(-0.5, 0, -0.5); RenderTileEnderTank.renderFluid(ccrs, mat, getter, stack); } }
Example #23
Source File: GuiHighlightTips.java From NotEnoughItems with MIT License | 5 votes |
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 #24
Source File: EnderTankItemRender.java From EnderStorage with MIT License | 5 votes |
@Override public void renderItem(ItemStack stack, TransformType transformType, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay) { CCRenderState ccrs = CCRenderState.instance(); ccrs.reset(); ccrs.brightness = packedLight; ccrs.overlay = packedOverlay; Frequency freq = Frequency.readFromStack(stack); FluidStack fluid = TankSynchroniser.getClientLiquid(freq); Matrix4 mat = new Matrix4(mStack); RenderTileEnderTank.renderTank(ccrs, mat, getter, 2, (float) (MathHelper.torad * 90F), 0, freq, 0); mat.translate(-0.5, 0, -0.5); RenderTileEnderTank.renderFluid(ccrs, mat, getter, fluid); }
Example #25
Source File: GuiItemSorter.java From NotEnoughItems with MIT License | 5 votes |
public void drawItem(Rectangle w, SortItem item, int mx, int my, float frame) { double y = MathHelper.interpolate(item.ya, item.y, frame); GlStateManager.translate(0, y, 0); Rectangle b = new Rectangle(w.x, w.y, w.width, 20); boolean mouseOver = itemAt(w.x+mx, w.y+my) == item; GlStateManager.color(1, 1, 1, 1); LayoutManager.drawButtonBackground(b.x, b.y, b.width, b.height, true, mouseOver ? 2 : 1); drawStringC(item.e.getLocalisedName(), b.x, b.y, b.width, b.height, mouseOver ? 0xFFFFFFA0 : 0xFFE0E0E0); GlStateManager.translate(0, -y, 0); }
Example #26
Source File: GuiItemSorter.java From NotEnoughItems with MIT License | 5 votes |
public void update(int my) { ya = y; if(dragging && this == dragged) y = dragstarty+my-mouseclickedy; else y = MathHelper.approachExp(y, slotY(), 0.4, 20); }
Example #27
Source File: Colour.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
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 #28
Source File: TileEnderTank.java From EnderStorage with MIT License | 5 votes |
public void update(boolean client) { if (client) { b_rotate = a_rotate; a_rotate = MathHelper.approachExp(a_rotate, approachRotate(), 0.5, 20); } else { b_pressure = a_pressure; a_pressure = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) != invert_redstone; if (a_pressure != b_pressure) sendSyncPacket(); } }
Example #29
Source File: EnderTankRenderer.java From EnderStorage with MIT License | 5 votes |
@Override public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) { TileEnderTank tank = (TileEnderTank)tile; CCRenderState.reset(); CCRenderState.pullLightmap(); CCRenderState.useNormals = true; renderTank(tank.rotation, (float) MathHelper.interpolate(tank.pressure_state.b_rotate, tank.pressure_state.a_rotate, f)*0.01745F, tank.freq, !tank.owner.equals("global"), x, y, z, EnderStorageClientProxy.getTimeOffset(tile.xCoord, tile.yCoord, tile.zCoord)); renderLiquid(tank.liquid_state.c_liquid, x, y, z); }
Example #30
Source File: GuiScrollPane.java From CodeChickenCore with MIT License | 5 votes |
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); }