Skip to content

Instantly share code, notes, and snippets.

@matyklug18
Created December 21, 2019 12:21
Show Gist options
  • Save matyklug18/a66b3e1b814e3696a1e3b1332d6b0f36 to your computer and use it in GitHub Desktop.
Save matyklug18/a66b3e1b814e3696a1e3b1332d6b0f36 to your computer and use it in GitHub Desktop.
event = new MousePressEvent() {
@Override
public void call(int key, int action) {
if(action == GLFW.GLFW_PRESS && key == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
for(ItemRenderHolder holder:items) {
holder.setOldSlot();
if(MathUtils.isClose(range, (float) Input.getMouseX(), holder.pos.x)) {
if(MathUtils.isClose(range, (float) (win.getYSize() - Input.getMouseY()), holder.pos.y))
holder.isHolding = true;
}
}
} else if(action == GLFW.GLFW_RELEASE && key == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
items.forEach(holder -> {
if(holder.isHolding) {
holder.isHolding = false;
holder.pos.x = MathUtils.mapMulti(holder.pos.x-offset.x, offset2) + offset.x;
holder.pos.y = MathUtils.mapMulti(holder.pos.y-offset.y, offset2) + offset.y;
holder.recalcSlot();
items.forEach(holder1 -> {
if(!holder.equals(holder1)) {
if(holder.slot.x == holder1.slot.x && holder.slot.y == holder1.slot.y) {
if(holder.itemStack.item.id == holder1.itemStack.item.id) {
holder.itemStack.count += holder1.itemStack.count;
toRemove = items.indexOf(holder1);
shouldRemove = true;
} else {
holder.returnBack();
}
}
}
});
if(holder.slot.x > 8 || holder.slot.y > 2 || holder.slot.x < 0 || holder.slot.y < 0) {
holder.returnBack();
}
}
});
if(shouldRemove) {
items.remove(toRemove);
shouldRemove = false;
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment