#3 Scrollbar functional on GUI and feels pretty good. Added in some picture assets, shop system still not functional yet
Some checks are pending
build / build (21) (push) Waiting to run

This commit is contained in:
Jkibbels 2025-03-23 17:59:30 -04:00
parent 79600e942f
commit 1b9b90df02
24 changed files with 412 additions and 23 deletions

View File

@ -25,18 +25,23 @@ public class FactionBlockScreen extends HandledScreen<FactionBlockScreenHandler>
super.init(); super.init();
titleY = 1000; //begone from screen titleY = 1000; //begone from screen
playerInventoryTitleY = 1000; //begone from screen playerInventoryTitleY = 1000; //begone from screen
this.backgroundWidth = 256;
this.backgroundHeight = 256;
this.x = (width - backgroundWidth) / 2;
this.y = (height - backgroundHeight) / 2;
} }
@Override @Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexProgram); // RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f); // RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.setShaderTexture(0, TEXTURE); // RenderSystem.setShaderTexture(0, TEXTURE);
context.drawTexture(TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight, this.backgroundWidth, this.backgroundHeight);
this.backgroundHeight = 256; this.backgroundHeight = 256;
this.backgroundWidth = 256; this.backgroundWidth = 256;
} }
@Override @Override

View File

@ -27,6 +27,16 @@ abstract public class ClickableLayer extends ClickableWidget {
this.layerName = layerName; this.layerName = layerName;
} }
protected void ResizeLayer(int width, int height) {
this.setWidth(width);
this.setHeight(height);
}
protected void MoveLayer(int startX, int startY) {
this.setX(startX);
this.setY(startY);
}
protected void AddSubLayer(ClickableLayer newLayer) { protected void AddSubLayer(ClickableLayer newLayer) {
subLayers.add(newLayer); subLayers.add(newLayer);
} }
@ -59,7 +69,6 @@ abstract public class ClickableLayer extends ClickableWidget {
@Override @Override
public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
context.drawTexture(this.GetTexture(), this.getX(), this.getY(), 0, 0, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight()); context.drawTexture(this.GetTexture(), this.getX(), this.getY(), 0, 0, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight());
} }
public Identifier GetTexture() { public Identifier GetTexture() {

View File

@ -0,0 +1,48 @@
package jesse.keeblarcraft.gui.ShopKeeperGUI;
import jesse.keeblarcraft.Keeblarcraft;
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
// All the custom content that a store item will have. Handled by @see MerchandiseScroller.java
public class DrawableStoreItem extends ClickableLayer {
private static final Identifier ITEM_ICON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.png");
private Integer itemCost;
private String itemName;
private Integer amountSelected = 0;
public DrawableStoreItem(String itemName, Integer itemCost) {
this(itemName, itemCost, Text.of(""), 0, 0, 0, 0);
}
public DrawableStoreItem(String itemName, Integer itemCost, Text layerName, int width, int height, int startX, int startY) {
super(ITEM_ICON, layerName, width, height, startX, startY);
this.itemCost = itemCost;
this.itemName = itemName;
}
public void Add() {
++this.amountSelected;
System.out.println("Current buy amount: " + this.amountSelected);
}
public void Subtract() {
--this.amountSelected;
System.out.println("Current buy amount: " + this.amountSelected);
}
public Integer GetTotal() {
return this.amountSelected * itemCost;
}
@Override
public void onClick(double x, double y) {
System.out.println("User clicked the following coordinates: [" + x + ", " + y + "]");
}
@Override
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
}

View File

@ -0,0 +1,40 @@
package jesse.keeblarcraft.gui.ShopKeeperGUI;
import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperInventory;
import jesse.keeblarcraft.GuiMgr.ShopKeeper.StoreItem;
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
// This is the main section in the GUI that will display the stores "merchandise" -- all the items on sale.
public class MerchandiseScroller {
private final ShopKeeperInventory storeInventory;
// Key = item name
// Value = the drawable slot for it
// The KVP keeps it so duplicate items don't take up more than 1 store slot
private final HashMap<String, DrawableStoreItem> drawableInventory;
public MerchandiseScroller(ShopKeeperInventory storeInventory) {
this.storeInventory = storeInventory;
drawableInventory = new HashMap<>();
}
public Integer Size() {
return storeInventory.Size();
}
public void Add(StoreItem item) {
storeInventory.Add(item);
drawableInventory.put(item.GetUPC(), new DrawableStoreItem(item.GetName(), item.GetCost()));
}
public void Remove(String upc) {
storeInventory.Remove(upc);
}
}

View File

@ -7,7 +7,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class NewItemButton extends ClickableLayer { public class NewItemButton extends ClickableLayer {
private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); /// TODO: Does not exist
private static NewItemMenu newItemMenu; private static NewItemMenu newItemMenu;
public NewItemButton(Identifier texture, Text layerName, int width, int height, int startX, int startY) { public NewItemButton(Identifier texture, Text layerName, int width, int height, int startX, int startY) {

View File

@ -25,6 +25,10 @@ public class NewItemMenu extends ClickableLayer {
this.AddDrawableSlotByName("add_item_slot", true); this.AddDrawableSlotByName("add_item_slot", true);
} }
public void AddItem() {
}
public boolean IsOpen() { public boolean IsOpen() {
return this.isOpen; return this.isOpen;
} }

View File

@ -0,0 +1,77 @@
package jesse.keeblarcraft.gui.ShopKeeperGUI;
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
public class Scrollbar extends ClickableLayer {
private boolean isDragging = false;
private int scrollbarStart = 0;
private int scrollbarEnd = 0;
public Scrollbar(Identifier texture, Text layerName, int width, int height, int startX, int startY, int scrollbarStart, int scrollbarMaxLength) {
super(texture, layerName, width, height, startX, startY);
this.scrollbarStart = scrollbarStart;
this.scrollbarEnd = startY + scrollbarMaxLength;
}
@Override
protected void onDrag(double mX, double mY, double dX, double dY) {
// We only want to enable dragging if this feature is being toggled
if (dY > 0) {
dY = 1.0;
} else {
dY = -1.0;
}
if (isDragging && mY >= this.scrollbarStart && mY <= this.scrollbarEnd) {
this.MoveLayer(this.getX(), (int)mY - (this.getHeight() / 2));
}
}
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
// We intentionally switch the scroll direction since it is backwards
// The number set to is the speed of scrolling
if (verticalAmount > 0) {
verticalAmount = -3;
} else {
verticalAmount = 3;
}
int newY = this.getY() + (int) verticalAmount;
System.out.println("Mouse move. newY: " + newY + " -> this.getY()=" + this.getY());
if (newY >= this.scrollbarStart-12 && newY <= this.scrollbarEnd-9) {
this.MoveLayer(this.getX(), newY);
}
return true;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
SetDragging(true);
return true;
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
SetDragging(false);
return true;
}
public Boolean IsDragging() {
return this.isDragging;
}
public void SetDragging(boolean b) {
System.out.println("Toggling dragging mode on scrollbar");
this.isDragging = b;
}
@Override
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
}

View File

@ -1,12 +1,16 @@
package jesse.keeblarcraft.gui.ShopKeeperGUI; package jesse.keeblarcraft.gui.ShopKeeperGUI;
import jesse.keeblarcraft.Entities.ShopKeeper;
import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler;
import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperInventory;
import jesse.keeblarcraft.Keeblarcraft; import jesse.keeblarcraft.Keeblarcraft;
import jesse.keeblarcraft.ClientHelpers.Helper; import jesse.keeblarcraft.ClientHelpers.Helper;
import jesse.keeblarcraft.gui.Generics.ClickableLayer; import jesse.keeblarcraft.gui.Generics.ClickableLayer;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -15,12 +19,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> { public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
private static final Identifier MENU_TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_gui.jpeg"); private static final Identifier MENU_TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_gui.png");
private static final Identifier ADD_BUTTON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_add_icon.jpeg"); private static final Identifier ADD_BUTTON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/plus.png");
private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); private static final Identifier SCROLLBAR = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/scrollbar.png");
private int x = 0; private int x = 0;
private int y = 0; private int y = 0;
private final List<ClickableLayer> layers = new ArrayList<>(); private final List<ClickableLayer> layers = new ArrayList<>();
private MerchandiseScroller catalogue;
private ShopKeeperInventory serverInventory;
Scrollbar scrollbar;
public ShopKeeperMenu(ShopKeeperHandler handler, PlayerInventory inventory, Text title) { public ShopKeeperMenu(ShopKeeperHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title); super(handler, inventory, title);
@ -37,9 +44,14 @@ public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
this.backgroundHeight = 256; this.backgroundHeight = 256;
this.x = (width - backgroundWidth) / 2; this.x = (width - backgroundWidth) / 2;
this.y = (height - backgroundHeight) / 2; this.y = (height - backgroundHeight) / 2;
scrollbar = new Scrollbar(SCROLLBAR, Text.of("scrollbar"), 15, 28, x+243, y+40, y+50, 163);
// Add all layers below // Add all layers below
AddNewButton(ADD_BUTTON, Text.of("ADD ITEM BUTTON"), x, y, 64, 64); AddNewButton(ADD_BUTTON, Text.of("ADD ITEM BUTTON"), x+20, y+20, 8, 8);
AddNewLayer(scrollbar);
catalogue = new MerchandiseScroller(this.getScreenHandler().GetInventory());
System.out.println("This store catalogue has size " + catalogue.Size());
} }
@Override @Override
@ -50,17 +62,25 @@ public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
// context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24); // context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24);
// context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24, 32, 24); // context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24, 32, 24);
// this.getScreenHandler().showSlot("new_item", "add_item_slot"); this.getScreenHandler().showSlot("add_item_menu", "add_item_slot");
// TODO: Temporary to just prove a point that we can draw item icons in the menu
ItemStack tempStack = Items.ACACIA_DOOR.getDefaultStack();
// Draws primary layers first
for (ClickableLayer layer : layers) { for (ClickableLayer layer : layers) {
layer.renderButton(context, mouseX, mouseY, delta); layer.renderButton(context, mouseX, mouseY, delta);
ToggleSlots(layer.GetLayerName().getString(), layer.GetDrawableSlots()); ToggleSlots(layer.GetLayerName().getString(), layer.GetDrawableSlots());
// If a primary layer happens to want sub-layers in itself; we draw those here
for (ClickableLayer subLayer : layer.GetSubLayers()) { for (ClickableLayer subLayer : layer.GetSubLayers()) {
subLayer.renderButton(context, mouseX, mouseY, delta); subLayer.renderButton(context, mouseX, mouseY, delta);
ToggleSlots(subLayer.GetLayerName().getString(), subLayer.GetDrawableSlots()); ToggleSlots(subLayer.GetLayerName().getString(), subLayer.GetDrawableSlots());
} }
// TODO: HACK to see if this works
context.drawItem(tempStack, this.x, this.y); // TODO: REMOVE
// We only notify the parent to update sub layers. It must manage its own sub layers // We only notify the parent to update sub layers. It must manage its own sub layers
layer.UpdateSubLayers(); layer.UpdateSubLayers();
} }
@ -69,10 +89,10 @@ public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
private void ToggleSlots(String menuName, Map<String, Boolean> slotNames) { private void ToggleSlots(String menuName, Map<String, Boolean> slotNames) {
for (Map.Entry<String, Boolean> slot : slotNames.entrySet()) { for (Map.Entry<String, Boolean> slot : slotNames.entrySet()) {
if (slot.getValue()) { if (slot.getValue()) {
System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); // System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue());
this.getScreenHandler().showSlot(menuName, slot.getKey()); this.getScreenHandler().showSlot(menuName, slot.getKey());
} else { } else {
System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); // System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue());
this.getScreenHandler().hideSlot(menuName, slot.getKey()); this.getScreenHandler().hideSlot(menuName, slot.getKey());
} }
} }
@ -83,6 +103,10 @@ public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
layers.add(new NewItemButton(iconId, layerName, imgWidth, imgHeight, drawX, drawY)); layers.add(new NewItemButton(iconId, layerName, imgWidth, imgHeight, drawX, drawY));
} }
private void AddNewLayer(ClickableLayer layer) {
layers.add(layer);
}
@Override @Override
public void drawForeground(DrawContext context, int mouseX, int mouseY) { public void drawForeground(DrawContext context, int mouseX, int mouseY) {
// We override this function to intentionally do nothing // We override this function to intentionally do nothing
@ -108,6 +132,69 @@ public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
return true; return true;
} }
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
scrollbar.SetDragging(false);
for (ClickableLayer layer : layers) {
// Scrollbar gets special handling above this. Ignore in loop
if (layer.GetLayerName().getString().equals("scrollbar")) {
continue;
}
// Check main layer first
if (Helper.WithinBounds(layer.getX(), layer.getY(), layer.getWidth(), layer.getHeight(), mouseX, mouseY)) {
layer.mouseReleased(mouseX, mouseY, button);
}
for (ClickableLayer subLayer : layer.GetSubLayers()) {
if (subLayer.visible && Helper.WithinBounds(subLayer.getX(), subLayer.getY(), subLayer.getWidth(), subLayer.getHeight(), mouseX, mouseY)) {
subLayer.mouseReleased(mouseX, mouseY, button);
}
}
}
return true;
}
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
System.out.println("Mouse scrolled. Vert amount is: " + verticalAmount);
scrollbar.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
return true;
}
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
// super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
if (scrollbar.IsDragging()) {
scrollbar.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
for (ClickableLayer layer : layers) {
// Scrollbar layer gets special handling above this for loop. Skip here
if (layer.GetLayerName().getString().equals("scrollbar")) {
continue;
}
// Check main layer first
if (Helper.WithinBounds(layer.getX(), layer.getY(), layer.getWidth(), layer.getHeight(), mouseX, mouseY)) {
layer.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
for (ClickableLayer subLayer : layer.GetSubLayers()) {
if (subLayer.visible && Helper.WithinBounds(subLayer.getX(), subLayer.getY(), subLayer.getWidth(), subLayer.getHeight(), mouseX, mouseY)) {
subLayer.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
}
}
return true;
}
// Check if a click point is within the context of a square (square = x, y, w, h) // Check if a click point is within the context of a square (square = x, y, w, h)
// public static boolean WithinBounds(double x, double y, double w, double h, double clickX, double clickY) { // public static boolean WithinBounds(double x, double y, double w, double h, double clickX, double clickY) {
//// System.out.println("Mouse click X Y: " + clickX + " " + clickY); //// System.out.println("Mouse click X Y: " + clickX + " " + clickY);

View File

@ -26,6 +26,7 @@ public class ShopKeeper extends VillagerEntity {
} }
private void BeginTrades(PlayerEntity player) { private void BeginTrades(PlayerEntity player) {
System.out.println("Beginning trades with player");
super.setCustomer(player); super.setCustomer(player);
this.sendOffers(player, this.getDisplayName(), this.getVillagerData().getLevel()); this.sendOffers(player, this.getDisplayName(), this.getVillagerData().getLevel());
} }

View File

@ -79,7 +79,6 @@ public class FactionBlockScreenHandler extends ScreenHandler {
return newStack; return newStack;
} }
// From Kaupenjoe video
private void addPlayerInventory(PlayerInventory playerInventory) { private void addPlayerInventory(PlayerInventory playerInventory) {
int spacing = -8; int spacing = -8;
for (int i = 0; i < 3; ++i) { // Rows for (int i = 0; i < 3; ++i) { // Rows
@ -92,7 +91,6 @@ public class FactionBlockScreenHandler extends ScreenHandler {
} }
} }
// From Kaupenjoe video
private void addPlayerHotbar(PlayerInventory playerInventory) { private void addPlayerHotbar(PlayerInventory playerInventory) {
int spacing = -8; int spacing = -8;
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {

View File

@ -1,5 +1,6 @@
package jesse.keeblarcraft.GuiMgr.ShopKeeper; package jesse.keeblarcraft.GuiMgr.ShopKeeper;
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration; import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration;
import jesse.keeblarcraft.Utils.CustomSlot; import jesse.keeblarcraft.Utils.CustomSlot;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -18,12 +19,18 @@ import java.util.Map;
public class ShopKeeperHandler extends ScreenHandler { public class ShopKeeperHandler extends ScreenHandler {
private Merchant merchant; private Merchant merchant;
private ShopKeeperInventory shopKeeperInventory;
private MerchantInventory merchantInventory; private MerchantInventory merchantInventory;
ConfigManager config = new ConfigManager();
String shopName;
// 0 size is default to prevent null. Inventory expanded later
// private final DefaultedList<ItemStack> merchantInventory = DefaultedList.ofSize(0, ItemStack.EMPTY);
private boolean canRefreshTrades = false; private boolean canRefreshTrades = false;
private boolean isLeveledMerchant = false; private boolean isLeveledMerchant = false;
private int levelAmount = 0; private int levelAmount = 0;
private int merchantExperience = 0; private int merchantExperience = 0;
private Map<Text, Integer> slotIdByName = new HashMap<>(); private Map<Text, Integer> slotIdByName = new HashMap<>(); ///TODO: Is this deprecated? Seems unused
ShopKeeperSlots allSlots = new ShopKeeperSlots(); ShopKeeperSlots allSlots = new ShopKeeperSlots();
public ShopKeeperHandler(int syncId, PlayerInventory playerInventory) { public ShopKeeperHandler(int syncId, PlayerInventory playerInventory) {
@ -32,12 +39,26 @@ public class ShopKeeperHandler extends ScreenHandler {
public ShopKeeperHandler(int syncId, PlayerInventory playerInventory, Merchant merchant) { public ShopKeeperHandler(int syncId, PlayerInventory playerInventory, Merchant merchant) {
super(ScreenHandlerRegistration.SHOP_KEEPER_HANDLER_SCREEN_HANDLER_TYPE, syncId); super(ScreenHandlerRegistration.SHOP_KEEPER_HANDLER_SCREEN_HANDLER_TYPE, syncId);
this.shopName = playerInventory.player.getEntityName(); ///TODO: Needs to be pulled from a shop manager
this.merchant = merchant; this.merchant = merchant;
this.merchantInventory = new MerchantInventory(merchant); this.merchantInventory = new MerchantInventory(merchant);
merchantInventory.onOpen(playerInventory.player); // not sure if this is doing anything
this.shopKeeperInventory = new ShopKeeperInventory(merchantInventory);
addPlayerHotbar(playerInventory);
RegisterSlots(); RegisterSlots();
// Add slots below }
// this.addSlot(new Slot(this.merchantInventory, 0, 136, 37));
// this.addSlot(new CustomSlot(this.merchantInventory, 0, 136, 37), Text.of("test")); public ShopKeeperInventory GetInventory() {
String name = "shops/" + shopName;
if (config.DoesFileExist(name)) {
/// TODO: Add system to pull json shop stuff
System.out.println("Shop exists.");
} else {
System.out.println("[NOWARN]: ShopKeep inventory not found for this shop. Creating one...");
config.CreateFile(name);
}
return this.shopKeeperInventory;
} }
public void RegisterSlots() { public void RegisterSlots() {
@ -90,14 +111,47 @@ public class ShopKeeperHandler extends ScreenHandler {
this.canRefreshTrades = isRefreshable; this.canRefreshTrades = isRefreshable;
} }
// This is just for SHIFT+CLICK moving
@Override @Override
public ItemStack quickMove(PlayerEntity player, int slot) { public ItemStack quickMove(PlayerEntity player, int invSlot) {
return null; System.out.println("Is client: " + player.getWorld().isClient());
ItemStack newStack = ItemStack.EMPTY;
Slot slot = this.slots.get(invSlot);
if (slot.hasStack()) {
ItemStack originalStack = slot.getStack();
newStack = originalStack.copy();
// TODO: This is from the YT video and it looks atrocious. Refactor this later
if ((invSlot < this.merchantInventory.size() && !this.insertItem(originalStack, this.merchantInventory.size(), this.slots.size(), true)) ||
(!this.insertItem(originalStack, 0, this.merchantInventory.size(), false))) {
return ItemStack.EMPTY;
}
if (originalStack.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();;
}
}
return newStack;
}
private void addPlayerHotbar(PlayerInventory playerInventory) {
int spacing = -8;
for (int i = 0; i < 9; ++i) {
// int x = (8 + i * 18) + spacing; // Texture draw position
int x = i * 22 + spacing; // Texture draw position
int y = 162; // Texture draw position
this.addSlot(new Slot(playerInventory, i, x, y));
}
} }
// Called every tick // Called every tick
@Override @Override
public boolean canUse(PlayerEntity player) { public boolean canUse(PlayerEntity player) {
// System.out.println("canUse called on screen handler");
// System.out.println("Can player use? " + this.merchantInventory.canPlayerUse(player));
// System.out.println("Current customer is : " + this.merchantInventory.);
return true; return true;
} }
} }

View File

@ -0,0 +1,35 @@
package jesse.keeblarcraft.GuiMgr.ShopKeeper;
import net.minecraft.village.MerchantInventory;
import java.util.ArrayList;
import java.util.List;
public class ShopKeeperInventory {
private final List<StoreItem> items;
private final MerchantInventory merchantInventory;
public ShopKeeperInventory(MerchantInventory merchantInventory) {
items = new ArrayList<StoreItem>();
// This is temporary to see if this stuff works client->server->client etc
items.add(new StoreItem("Among Us Statue", "$$$$$$$$$$", 10000));
this.merchantInventory = merchantInventory;
}
public List<StoreItem> GetItems() {
return this.items;
}
public Integer Size() {
System.out.println("Size called...");
return this.items.size();
}
public void Add(StoreItem item) {
this.items.add(item);
}
public void Remove(String upc) {
this.items.removeIf(item -> item.equals(upc));
}
}

View File

@ -3,13 +3,14 @@ package jesse.keeblarcraft.GuiMgr.ShopKeeper;
import jesse.keeblarcraft.Utils.CustomSlot; import jesse.keeblarcraft.Utils.CustomSlot;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
// Until I find the will and way to mixin slots to be able to be removed (i.e: not backed by an Inventory) I am patching // Until I find the will and way to mixin slots to be able to be removed (i.e: not backed by an Inventory) I am patching
// slots in its own registration class (like ShopKeeperSlots). The time to do the mixin stuff far exceeds what is worth // slots in its own registration class (like ShopKeeperSlots). The time to do the mixin stuff far exceeds what is worth
// it for the time being. // it for the time being.
public class ShopKeeperSlots { public class ShopKeeperSlots {
// Key = The GUI menu the slot belongs to. Helpful in parsing
// Value = Map Key = Name of slot; Value = Slot itself. Name of slot is helpful for parsing if set
private final Map<String, HashMap<String, CustomSlot>> shopKeeperSlots = new HashMap<>(); private final Map<String, HashMap<String, CustomSlot>> shopKeeperSlots = new HashMap<>();
public ShopKeeperSlots() {} public ShopKeeperSlots() {}

View File

@ -0,0 +1,30 @@
package jesse.keeblarcraft.GuiMgr.ShopKeeper;
// All the custom content that a store item will have. Handled by @see MerchandiseScroller.java
public class StoreItem {
private Integer itemCost;
private String itemName;
private String upc;
public StoreItem(String itemName, String upc, Integer cost) {
this.itemName = itemName;
this.upc = upc;
this.itemCost = cost;
}
public String GetName() {
return itemName;
}
public String GetUPC() {
return this.upc;
}
public Integer GetCost() {
return this.itemCost;
}
public boolean equals(String other) {
return upc.equals(other);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 572 B