mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 11:05:07 +00:00
implement pop animation
This commit is contained in:
1 parent
8aea03c251
commit
0ce4118e36
4 files changed
+50
-25
No files matched your search
@@ -1,21 +1,26 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import static codechicken.nei.ItemsGrid.SLOT_SIZE;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class AnimatedItemStack {
|
||||
|
||||
private static final int steep = 5;
|
||||
private static final float scaleSpeed = 0.1f;
|
||||
|
||||
private int lastPosX;
|
||||
private int lastPosY;
|
||||
private int lastPosX = -1;
|
||||
private int lastPosY = -1;
|
||||
private float currentScale = 0;
|
||||
private boolean doPopAnim;
|
||||
|
||||
public ItemStack itemStack;
|
||||
|
||||
public AnimatedItemStack(ItemStack itemStack, int startPosX, int startPosY) {
|
||||
public AnimatedItemStack(ItemStack itemStack, boolean doPopAnim) {
|
||||
this.itemStack = itemStack;
|
||||
lastPosX = startPosX;
|
||||
lastPosY = startPosY;
|
||||
this.doPopAnim = doPopAnim;
|
||||
}
|
||||
|
||||
public void drawItem(int x, int y) {
|
||||
@@ -23,20 +28,40 @@ public class AnimatedItemStack {
|
||||
}
|
||||
|
||||
public void drawItem(int x, int y, boolean smallAmount, String stackSize) {
|
||||
if (x != lastPosX || y != lastPosY) {
|
||||
if (doPopAnim && currentScale < 1) {
|
||||
drawPoppingItem(x, y, smallAmount, stackSize);
|
||||
} else if (lastPosX != x || lastPosY != y) {
|
||||
drawMovingItem(x, y, smallAmount, stackSize);
|
||||
} else {
|
||||
GuiContainerManager.drawItem(x, y, itemStack, smallAmount, stackSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPoppingItem(int x, int y, boolean smallAmount, String stackSize) {
|
||||
currentScale += scaleSpeed;
|
||||
GL11.glScalef(currentScale, currentScale, currentScale); // push & pop matrix crashes the game
|
||||
GuiContainerManager.drawItem(
|
||||
(int) ((x + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
|
||||
(int) ((y + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
|
||||
itemStack,
|
||||
smallAmount,
|
||||
stackSize);
|
||||
GL11.glScalef(1 / currentScale, 1 / currentScale, 1 / currentScale);
|
||||
}
|
||||
|
||||
private void drawMovingItem(int x, int y, boolean smallAmount, String stackSize) {
|
||||
int xDiff = x - lastPosX;
|
||||
int yDiff = y - lastPosY;
|
||||
int moveX = xDiff / steep + ((xDiff % steep == 0) ? 0 : (xDiff > 0 ? 1 : -1));
|
||||
int moveY = yDiff / steep + ((yDiff % steep == 0) ? 0 : (yDiff > 0 ? 1 : -1));
|
||||
GuiContainerManager.drawItem(lastPosX + moveX, lastPosY + moveY, itemStack, smallAmount, stackSize);
|
||||
lastPosX = lastPosX + moveX;
|
||||
lastPosY = lastPosY + moveY;
|
||||
if (lastPosX != -1 && lastPosY != -1) {
|
||||
int xDiff = x - lastPosX;
|
||||
int yDiff = y - lastPosY;
|
||||
int moveX = xDiff / steep + ((xDiff % steep == 0) ? 0 : (xDiff > 0 ? 1 : -1));
|
||||
int moveY = yDiff / steep + ((yDiff % steep == 0) ? 0 : (yDiff > 0 ? 1 : -1));
|
||||
GuiContainerManager.drawItem(lastPosX + moveX, lastPosY + moveY, itemStack, smallAmount, stackSize);
|
||||
lastPosX = lastPosX + moveX;
|
||||
lastPosY = lastPosY + moveY;
|
||||
} else {
|
||||
lastPosX = x;
|
||||
lastPosY = y;
|
||||
GuiContainerManager.drawItem(x, y, itemStack, smallAmount, stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user