use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories by Hugobros3.
the class Ingame method handleInput.
@Override
public boolean handleInput(Input input) {
// Block inputs if chatting
if (input.equals("chat")) {
gameWindow.setLayer(chatManager.new ChatPanelOverlay(gameWindow, this));
focus(false);
guiHidden = false;
return true;
} else if (input.equals("hideGui")) {
guiHidden = !guiHidden;
return true;
} else if (input.equals("screenshot")) {
chatManager.insert(world.getWorldRenderer().screenShot());
} else if (input.equals("toggleDebugInfo")) {
OptionBoolean debugInfo = (OptionBoolean) client.getConfiguration().getOption("client.debug.showDebugInfo");
debugInfo.toggle();
guiHidden = false;
return true;
} else if (input.equals("takeCubemap")) {
// shouldTakeACubemap = true;
return true;
// CTRL-F12 reloads
} else if (input.equals("reloadContent")) {
// Rebuild the mod FS
gameWindow.getClient().reloadAssets();
// Reload plugins
world.getPluginManager().reloadPlugins();
// Mark some caches dirty
world.getWorldRenderer().reloadContentSpecificStuff();
return true;
// CTRL-R redraws chunks
} else if (input.equals("redrawChunks")) {
((ClientParticlesRenderer) world.getParticlesManager()).cleanAllParticles();
world.redrawEverything();
world.getWorldRenderer().flagChunksModified();
return true;
// Item slots selection
} else if (input.getName().startsWith("inventorySlot")) {
int requestedInventorySlot = Integer.parseInt(input.getName().replace("inventorySlot", ""));
// Match zero onto last slot
if (requestedInventorySlot == 0)
requestedInventorySlot = 10;
// Map to zero-indexed inventory
requestedInventorySlot--;
if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
// Do not accept request to select non-existent inventories slots
if (requestedInventorySlot > ((EntityWithInventory) playerEntity).getInventory().getWidth())
return false;
ItemPile p = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(requestedInventorySlot, 0);
if (p != null)
requestedInventorySlot = p.getX();
((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(requestedInventorySlot);
}
return true;
} else if (input.equals("exit")) /* Exit brings up the pause menu */
{
focus(false);
guiHidden = false;
gameWindow.setLayer(new PauseMenu(gameWindow, this));
return true;
} else if (input instanceof MouseScroll) {
MouseScroll ms = (MouseScroll) input;
if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
ItemPile selected = null;
int selectedInventorySlot = ((EntityWithSelectedItem) playerEntity).getSelectedItemIndex();
int originalSlot = selectedInventorySlot;
if (ms.amount() < 0) {
selectedInventorySlot %= ((EntityWithInventory) playerEntity).getInventory().getWidth();
selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
if (selected != null)
selectedInventorySlot += selected.getItem().getDefinition().getSlotsWidth();
else
selectedInventorySlot++;
} else {
selectedInventorySlot--;
if (selectedInventorySlot < 0)
selectedInventorySlot += ((EntityWithInventory) playerEntity).getInventory().getWidth();
selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
if (selected != null)
selectedInventorySlot = selected.getX();
}
// Switch slot
if (originalSlot != selectedInventorySlot)
((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(selectedInventorySlot);
return true;
}
}
return false;
}
use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories by Hugobros3.
the class InventoryView method render.
@Override
public void render(RenderingInterface renderer) {
parentLayer.render(renderer);
Mouse mouse = renderer.getClient().getInputsManager().getMouse();
int totalWidth = 0;
for (Inventory inv : inventories) totalWidth += 2 + inv.getWidth();
totalWidth -= 2;
int widthAccumulation = 0;
for (int i = 0; i < drawers.length; i++) {
int thisWidth = inventories[i].getWidth();
drawers[i].drawInventoryCentered(renderer, renderer.getWindow().getWidth() / 2 - totalWidth * 24 + thisWidth * 24 + widthAccumulation * 48, renderer.getWindow().getHeight() / 2, 2, false, 4 - i * 4);
widthAccumulation += 1 + thisWidth;
int[] highlightedSlot = drawers[i].getSelectedSlot();
if (highlightedSlot != null) {
ItemPile pileHighlighted = inventories[i].getItemPileAt(highlightedSlot[0], highlightedSlot[1]);
if (pileHighlighted != null) {
float mx = (float) mouse.getCursorX();
float my = (float) mouse.getCursorY();
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), mx, my, pileHighlighted.getItem().getName(), 2, 2, new Vector4f(1.0f));
// System.out.println(pileHighlighted);
}
}
}
if (selectedItem != null) {
int slotSize = 24 * 2;
int width = slotSize * selectedItem.getItem().getDefinition().getSlotsWidth();
int height = slotSize * selectedItem.getItem().getDefinition().getSlotsHeight();
selectedItem.getItem().getDefinition().getRenderer().renderItemInInventory(renderer, selectedItem, (float) mouse.getCursorX() - width / 2, (float) mouse.getCursorY() - height / 2, 2);
if (selectedItemAmount != 1)
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), (float) mouse.getCursorX() - width / 2 + (selectedItem.getItem().getDefinition().getSlotsWidth() - 1.0f) * slotSize, (float) mouse.getCursorY() - height / 2, selectedItemAmount + "", 2, 2, new Vector4f(1, 1, 1, 1));
}
}
use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories by Hugobros3.
the class InventoryGridRenderer method drawInventory.
public void drawInventory(RenderingInterface renderer, int x, int y, int scale, boolean summary, int blankLines, int highlightSlot) {
Mouse mouse = renderer.getClient().getInputsManager().getMouse();
if (getInventory() == null)
return;
int cornerSize = 8 * scale;
int internalWidth = getInventory().getWidth() * 24 * scale;
int height = summary ? 1 : getInventory().getHeight();
int internalHeight = (height + (summary ? 0 : 1) + blankLines) * 24 * scale;
int slotSize = 24 * scale;
Texture2D inventoryTexture = renderer.textures().getTexture("./textures/gui/inventory/inventory.png");
inventoryTexture.setLinearFiltering(false);
Vector4f color = new Vector4f(1f, 1f, 1f, summary ? 0.5f : 1f);
// All 8 corners
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + internalHeight + cornerSize, cornerSize, cornerSize, 0, 0.03125f, 0.03125f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + internalHeight + cornerSize, internalWidth, cornerSize, 0.03125f, 0.03125f, 0.96875f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + internalHeight + cornerSize, cornerSize, cornerSize, 0.96875f, 0.03125f, 1f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y, cornerSize, cornerSize, 0, 1f, 0.03125f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y, internalWidth, cornerSize, 0.03125f, 1f, 0.96875f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y, cornerSize, cornerSize, 0.96875f, 1f, 1f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + cornerSize, cornerSize, internalHeight, 0, 248f / 256f, 0.03125f, 8f / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + cornerSize, cornerSize, internalHeight, 248 / 256f, 248f / 256f, 1f, 8f / 256f, inventoryTexture, true, true, color);
// Actual inventory slots
int sumSlots2HL = 0;
selectedSlot = null;
for (int i = 0; i < getInventory().getWidth(); i++) {
for (int j = 0; j < height; j++) {
boolean mouseOver = mouse.getCursorX() > x + cornerSize + i * slotSize && mouse.getCursorX() <= x + cornerSize + i * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + j * slotSize && mouse.getCursorY() <= y + cornerSize + j * slotSize + slotSize;
// Just a dirt hack to always keep selected slot values where we want them
if (mouseOver && selectedSlot == null) {
selectedSlot = new int[] { i, j };
}
ItemPile selectedPile = null;
if (selectedSlot != null)
selectedPile = getInventory().getItemPileAt(selectedSlot[0], selectedSlot[1]);
ItemPile thisPile = getInventory().getItemPileAt(i, j);
if (summary) {
ItemPile summaryBarSelected = getInventory().getItemPileAt(highlightSlot, 0);
if (summaryBarSelected != null && i == summaryBarSelected.getX()) {
sumSlots2HL = summaryBarSelected.getItem().getDefinition().getSlotsWidth();
}
if (sumSlots2HL > 0 || (summaryBarSelected == null && highlightSlot == i)) {
sumSlots2HL--;
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else {
if (mouseOver || (selectedPile != null && thisPile != null && selectedPile.getX() == thisPile.getX() && selectedPile.getY() == thisPile.getY())) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
}
}
}
// Blank part ( usefull for special inventories, ie player )
for (int j = getInventory().getHeight(); j < getInventory().getHeight() + blankLines; j++) {
for (int i = 0; i < getInventory().getWidth(); i++) {
if (j == getInventory().getHeight()) {
if (i == getInventory().getWidth() - 1)
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 152 / 256f, 248 / 256f, 128 / 256f, inventoryTexture, true, true, color);
else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 152 / 256f, 32f / 256f, 128 / 256f, inventoryTexture, true, true, color);
} else {
if (i == getInventory().getWidth() - 1)
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 56 / 256f, 248 / 256f, 32 / 256f, inventoryTexture, true, true, color);
else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 56 / 256f, 32f / 256f, 32 / 256f, inventoryTexture, true, true, color);
}
}
}
// Top part
if (!summary) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 8f / 256f, 32f / 256f, 32f / 256f, 8f / 256f, inventoryTexture, true, true, color);
for (int i = 1; i < getInventory().getWidth() - 2; i++) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 32f / 256f, 32f / 256f, 56f / 256f, 8f / 256f, inventoryTexture, true, true, color);
}
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 2) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 200f / 256f, 32f / 256f, 224 / 256f, 8f / 256f, inventoryTexture, true, true, color);
closedButton = mouse.getCursorX() > x + cornerSize + (getInventory().getWidth() - 1) * slotSize && mouse.getCursorX() <= x + cornerSize + (getInventory().getWidth() - 1) * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + internalHeight - slotSize && mouse.getCursorY() <= y + cornerSize + internalHeight;
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 1) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 224f / 256f, 32f / 256f, 248f / 256f, 8f / 256f, inventoryTexture, true, true, color);
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Bold", 12), x + cornerSize + 6, y + cornerSize + internalHeight - slotSize + 2 * scale, getInventory().getInventoryName(), scale, scale, new Vector4f(1, 1, 1, 1));
}
// Get rid of any remaining GUI elements or else they will draw on top of the
// items
renderer.getGuiRenderer().drawBuffer();
// Draw the actual items
for (ItemPile pile : getInventory()) {
int i = pile.getX();
int j = pile.getY();
if (pile != null && (!summary || j == 0)) {
int center = summary ? slotSize * (pile.getItem().getDefinition().getSlotsHeight() - 1) / 2 : 0;
pile.getItem().getDefinition().getRenderer().renderItemInInventory(renderer, pile, x + cornerSize + i * slotSize, y - center + cornerSize + j * slotSize, scale);
}
}
// )
for (ItemPile pile : getInventory()) {
int i = pile.getX();
int j = pile.getY();
if (pile != null && (!summary || j == 0)) {
int amountToDisplay = pile.getAmount();
// If we selected this item
if ((InventoryView.selectedItem != null && InventoryView.selectedItem.getInventory() != null && getInventory().equals(InventoryView.selectedItem.getInventory()) && InventoryView.selectedItem.getX() == i && InventoryView.selectedItem.getY() == j)) {
amountToDisplay -= InventoryView.selectedItemAmount;
}
// Draw amount of items in the pile
if (amountToDisplay > 1)
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), x + cornerSize + ((pile.getItem().getDefinition().getSlotsWidth() - 1.0f) + i) * slotSize, y + cornerSize + j * slotSize, amountToDisplay + "", scale, scale, new Vector4f(1, 1, 1, 1));
}
}
}
use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories by Hugobros3.
the class GiveCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!emitter.hasPermission("server.give")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
if (!(emitter instanceof Player)) {
emitter.sendMessage("You need to be a player to use this command.");
return true;
}
Content gameContent = server.getContent();
Player player = (Player) emitter;
if (arguments.length == 0) {
player.sendMessage("#FF969BSyntax : /give <item> [amount] [to]");
return true;
}
int amount = 1;
Player to = player;
String itemName = arguments[0];
// Look for the item first
ItemDefinition type = gameContent.items().getItemDefinition(itemName);
// If the type was found we are simply trying to spawn an item
Item item = null;
if (type != null)
item = type.newItem();
else {
String voxelName = itemName;
int voxelMeta = 0;
if (voxelName.contains(":")) {
voxelMeta = Integer.parseInt(voxelName.split(":")[1]);
voxelName = voxelName.split(":")[0];
}
// Try to find a matching voxel
Voxel voxel = gameContent.voxels().getVoxel(itemName);
if (voxel != null) {
// Spawn new itemPile in his inventory
ItemVoxel itemVoxel = (ItemVoxel) gameContent.items().getItemDefinition("item_voxel").newItem();
itemVoxel.voxel = voxel;
itemVoxel.voxelMeta = voxelMeta;
item = itemVoxel;
}
}
if (item == null) {
player.sendMessage("#FF969BItem or voxel \"" + arguments[0] + " can't be found.");
return true;
}
if (arguments.length >= 2) {
amount = Integer.parseInt(arguments[1]);
}
if (arguments.length >= 3) {
if (gameContent instanceof ServerInterface)
to = ((ServerInterface) gameContent).getPlayerByName(arguments[2]);
else {
player.sendMessage("#FF969BThis is a singleplayer world - there are no other players");
return true;
}
}
if (to == null) {
player.sendMessage("#FF969BPlayer \"" + arguments[2] + " can't be found.");
return true;
}
ItemPile itemPile = new ItemPile(item);
itemPile.setAmount(amount);
((EntityWithInventory) to.getControlledEntity()).getInventory().addItemPile(itemPile);
player.sendMessage("#FF969BGave " + (amount > 1 ? amount + "x " : "") + "#4CFF00" + itemPile.getItem().getName() + " #FF969Bto " + to.getDisplayName());
return true;
}
use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-api by Hugobros3.
the class Voxel method getLoot.
/**
* Returns what's dropped when a cell using this voxel type is destroyed
*/
public ItemPile[] getLoot(CellData cell, WorldModificationCause cause) {
ItemVoxel itemVoxel = (ItemVoxel) this.getDefinition().store().parent().items().getItemDefinition("item_voxel").newItem();
itemVoxel.voxel = this;
itemVoxel.voxelMeta = cell.getMetaData();
ItemPile pile = new ItemPile(itemVoxel);
return new ItemPile[] { pile };
}
Aggregations