#3 Slot stuff barely works. Agonizing pain.
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
4e080ad392
commit
21ba86bbec
@ -3,6 +3,7 @@ package jesse.keeblarcraft.gui.Generics;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package jesse.keeblarcraft.gui.ShopKeeperGUI;
|
||||
|
||||
import jesse.keeblarcraft.ClientHelpers.Helper;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
|
@ -3,6 +3,7 @@ package jesse.keeblarcraft.gui.ShopKeeperGUI;
|
||||
import jesse.keeblarcraft.GuiMgr.ShopKeeperHandler;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ClientHelpers.Helper;
|
||||
import jesse.keeblarcraft.Utils.CustomSlot;
|
||||
import jesse.keeblarcraft.gui.Generics.ClickableLayer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
@ -12,7 +13,6 @@ import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ShopKeeperMenu extends HandledScreen<ShopKeeperHandler> {
|
||||
private static final Identifier MENU_TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_gui.jpeg");
|
||||
@ -50,6 +50,8 @@ 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, 32, 24);
|
||||
|
||||
// this.getScreenHandler().ShowSlot(Text.of("test"));
|
||||
|
||||
for (ClickableLayer layer : layers) {
|
||||
layer.renderButton(context, mouseX, mouseY, delta);
|
||||
|
||||
|
@ -11,7 +11,6 @@ import net.minecraft.screen.ArrayPropertyDelegate;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FactionBlockScreenHandler extends ScreenHandler {
|
||||
private final Inventory inventory;
|
||||
@ -96,11 +95,10 @@ public class FactionBlockScreenHandler extends ScreenHandler {
|
||||
private void addPlayerHotbar(PlayerInventory playerInventory) {
|
||||
int spacing = -8;
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
int index = i; // Index of hotbar (only 9 slots long in vanilla)
|
||||
// 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, index, x, y));
|
||||
this.addSlot(new Slot(playerInventory, i, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,20 @@
|
||||
package jesse.keeblarcraft.GuiMgr;
|
||||
|
||||
import jesse.keeblarcraft.Utils.CustomSlot;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.village.Merchant;
|
||||
import net.minecraft.village.MerchantInventory;
|
||||
import net.minecraft.village.SimpleMerchant;
|
||||
import net.minecraft.village.TradeOfferList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ShopKeeperHandler extends ScreenHandler {
|
||||
private Merchant merchant;
|
||||
private MerchantInventory merchantInventory;
|
||||
@ -16,6 +22,7 @@ public class ShopKeeperHandler extends ScreenHandler {
|
||||
boolean isLeveledMerchant = false;
|
||||
int levelAmount = 0;
|
||||
int merchantExperience = 0;
|
||||
Map<Text, Integer> slotIdByName = new HashMap<>();
|
||||
|
||||
public ShopKeeperHandler(int syncId, PlayerInventory playerInventory) {
|
||||
this(syncId, playerInventory, new SimpleMerchant(playerInventory.player));
|
||||
@ -26,6 +33,36 @@ public class ShopKeeperHandler extends ScreenHandler {
|
||||
this.merchant = merchant;
|
||||
this.merchantInventory = new MerchantInventory(merchant);
|
||||
// Add slots below
|
||||
// this.addSlot(new Slot(this.merchantInventory, 0, 136, 37));
|
||||
this.addSlot(new CustomSlot(this.merchantInventory, 0, Text.of("test"), 136, 37), Text.of("test"));
|
||||
}
|
||||
|
||||
public void HideSlot(Text slotName) {
|
||||
this.getSlot(Text.of("test")).setEnabled(false);
|
||||
}
|
||||
|
||||
public void ShowSlot(Text slotName) {
|
||||
this.getSlot(Text.of("test")).setEnabled(true);
|
||||
}
|
||||
|
||||
protected void addSlot(CustomSlot slot, Text name) {
|
||||
super.addSlot(slot);
|
||||
slotIdByName.put(name, slot.id);
|
||||
}
|
||||
|
||||
public CustomSlot getSlot(Text name) {
|
||||
|
||||
System.out.println("Printing slot map");
|
||||
for (Slot slot : super.slots) {
|
||||
System.out.println("Found slot with id: " + slot.id);
|
||||
}
|
||||
|
||||
System.out.println("Printing self stored map");
|
||||
for (Map.Entry<Text, Integer> entry : this.slotIdByName.entrySet()) {
|
||||
System.out.println("entry set id value: " + "K: " + entry.getKey() + " -> V: " + entry.getValue());
|
||||
}
|
||||
|
||||
return (CustomSlot) super.getSlot(slotIdByName.get(name));
|
||||
}
|
||||
|
||||
public void SetOffers(TradeOfferList offers) {
|
||||
@ -56,7 +93,6 @@ public class ShopKeeperHandler extends ScreenHandler {
|
||||
// Called every tick
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
// System.out.println("canUse called on Merchant!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
27
src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java
Normal file
27
src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java
Normal file
@ -0,0 +1,27 @@
|
||||
package jesse.keeblarcraft.Utils;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class CustomSlot extends Slot {
|
||||
private boolean slotIsEnabled = false;
|
||||
private Text slotId;
|
||||
|
||||
public CustomSlot(Inventory inventory, int index, Text slotName, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
public CustomSlot(Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return slotIsEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean value) {
|
||||
this.slotIsEnabled = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user