add itemstack moving animation

This commit is contained in:
くぁーりぃ committed 2022-09-12 20:58:33 +09:00
1 parent d451fe5aa8
commit 8aea03c251
4 files changed
+78 -16

No files matched your search

@@ -0,0 +1,42 @@
package codechicken.nei;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.item.ItemStack;
public class AnimatedItemStack {
private static final int steep = 5;
private int lastPosX;
private int lastPosY;
public ItemStack itemStack;
public AnimatedItemStack(ItemStack itemStack, int startPosX, int startPosY) {
this.itemStack = itemStack;
lastPosX = startPosX;
lastPosY = startPosY;
}
public void drawItem(int x, int y) {
drawItem(x, y, false, null);
}
public void drawItem(int x, int y, boolean smallAmount, String stackSize) {
if (x != lastPosX || y != lastPosY) {
drawMovingItem(x, y, smallAmount, stackSize);
} else {
GuiContainerManager.drawItem(x, y, itemStack, smallAmount, stackSize);
}
}
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;
}
}