mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-28 16:06:03 +00:00
add itemstack moving animation
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
final BookmarkStackMeta meta = getMetadata(idx);
|
||||
if ((recipeId == null && meta.recipeId == null
|
||||
|| recipeId != null && meta.recipeId != null && recipeId.equals(meta.recipeId))
|
||||
&& StackInfo.equalItemAndNBT(stackA, realItems.get(idx), useNBT)) {
|
||||
&& StackInfo.equalItemAndNBT(stackA, getItem(idx), useNBT)) {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
public void addItem(ItemStack stackA, BookmarkStackMeta meta) {
|
||||
realItems.add(stackA);
|
||||
addRealItem(stackA);
|
||||
metadata.add(meta);
|
||||
onGridChanged();
|
||||
}
|
||||
@@ -233,13 +233,13 @@ public class BookmarkPanel extends PanelWidget {
|
||||
addItem(stackA, meta);
|
||||
return;
|
||||
}
|
||||
realItems.add(index, stackA);
|
||||
addRealItem(index, stackA);
|
||||
metadata.add(index, meta);
|
||||
onGridChanged();
|
||||
}
|
||||
|
||||
public void replaceItem(int idx, ItemStack stack) {
|
||||
realItems.set(idx, stack);
|
||||
setRealItem(idx, stack);
|
||||
onGridChanged();
|
||||
}
|
||||
|
||||
@@ -331,12 +331,13 @@ public class BookmarkPanel extends PanelWidget {
|
||||
final ItemStack stack = getItem(idx);
|
||||
final BookmarkStackMeta meta = getMetadata(idx);
|
||||
|
||||
GuiContainerManager.drawItem(
|
||||
rect.x + 1,
|
||||
rect.y + 1,
|
||||
stack,
|
||||
true,
|
||||
meta.factor < 0 || meta.fluidDisplay ? "" : String.valueOf(stack.stackSize));
|
||||
realItems
|
||||
.get(idx)
|
||||
.drawItem(
|
||||
rect.x + 1,
|
||||
rect.y + 1,
|
||||
true,
|
||||
meta.factor < 0 || meta.fluidDisplay ? "" : String.valueOf(stack.stackSize));
|
||||
|
||||
if (meta.recipeId != null && !meta.ingredient && NEIClientConfig.showRecipeMarker()) {
|
||||
drawRecipeMarker(rect.x, rect.y, GuiContainerManager.getFontRenderer(stack));
|
||||
|
||||
@@ -57,7 +57,8 @@ public class ItemPanel extends PanelWidget {
|
||||
public void refresh(GuiContainer gui) {
|
||||
|
||||
if (newItems != null) {
|
||||
realItems = newItems;
|
||||
realItems.clear();
|
||||
addRealItems(newItems);
|
||||
newItems = null;
|
||||
onGridChanged();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
@@ -31,7 +33,7 @@ public class ItemsGrid {
|
||||
|
||||
protected int paddingLeft;
|
||||
|
||||
protected ArrayList<ItemStack> realItems = new ArrayList<>();
|
||||
protected ArrayList<AnimatedItemStack> realItems = new ArrayList<>();
|
||||
|
||||
protected int page;
|
||||
protected int perPage;
|
||||
@@ -49,11 +51,27 @@ public class ItemsGrid {
|
||||
protected boolean refreshBuffer = true;
|
||||
|
||||
public ArrayList<ItemStack> getItems() {
|
||||
return realItems;
|
||||
return realItems.stream().map(e -> e.itemStack).collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
public ItemStack getItem(int idx) {
|
||||
return realItems.get(idx);
|
||||
return realItems.get(idx).itemStack;
|
||||
}
|
||||
|
||||
protected void addRealItems(Collection<ItemStack> itemStack) {
|
||||
itemStack.forEach(this::addRealItem);
|
||||
}
|
||||
|
||||
protected void addRealItem(ItemStack itemStack) {
|
||||
realItems.add(new AnimatedItemStack(itemStack, marginLeft, marginTop));
|
||||
}
|
||||
|
||||
protected void addRealItem(int index, ItemStack itemStack) {
|
||||
realItems.add(index, new AnimatedItemStack(itemStack, marginLeft, marginTop));
|
||||
}
|
||||
|
||||
protected void setRealItem(int index, ItemStack itemStack) {
|
||||
realItems.set(index, new AnimatedItemStack(itemStack, marginLeft, marginTop));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
@@ -63,7 +81,7 @@ public class ItemsGrid {
|
||||
public int indexOf(ItemStack stackA, boolean useNBT) {
|
||||
|
||||
for (int idx = 0; idx < realItems.size(); idx++) {
|
||||
if (StackInfo.equalItemAndNBT(stackA, realItems.get(idx), useNBT)) {
|
||||
if (StackInfo.equalItemAndNBT(stackA, getItem(idx), useNBT)) {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
@@ -317,7 +335,7 @@ public class ItemsGrid {
|
||||
}
|
||||
|
||||
protected void drawItem(Rectangle4i rect, int idx) {
|
||||
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, getItem(idx));
|
||||
realItems.get(idx).drawItem(rect.x + 1, rect.y + 1);
|
||||
}
|
||||
|
||||
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
|
||||
|
||||
Reference in new issue
Block a user