summaryrefslogtreecommitdiff
path: root/src/main/java/moe
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-22 00:23:59 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-22 00:23:59 +0100
commit5824193ef95a6dc42ae77f23fc46b074333c1543 (patch)
tree930260a0cf7e31f3a902a4de71506a7d6d415083 /src/main/java/moe
parent99bf02825007f5caff8c591669d096435b75c411 (diff)
downloadfunny-teleporters-5824193ef95a6dc42ae77f23fc46b074333c1543.tar.gz
funny-teleporters-5824193ef95a6dc42ae77f23fc46b074333c1543.tar.bz2
funny-teleporters-5824193ef95a6dc42ae77f23fc46b074333c1543.zip
Finish off editing UI
Diffstat (limited to 'src/main/java/moe')
-rw-r--r--src/main/java/moe/nea/funnyteleporters/TeleporterNexusBlockEntity.java7
-rw-r--r--src/main/java/moe/nea/funnyteleporters/TeleporterNexusEditorScreen.java30
-rw-r--r--src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java14
3 files changed, 43 insertions, 8 deletions
diff --git a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusBlockEntity.java b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusBlockEntity.java
index a1c9490..ba6808a 100644
--- a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusBlockEntity.java
+++ b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusBlockEntity.java
@@ -14,8 +14,6 @@ import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
-import java.util.HashMap;
-import java.util.Map;
import java.util.TreeMap;
public class TeleporterNexusBlockEntity extends BlockEntity {
@@ -62,4 +60,9 @@ public class TeleporterNexusBlockEntity extends BlockEntity {
destinations.remove(destination);
markDirty();
}
+
+ public void setIcon(TeleporterDestination dest, Item item) {
+ destinations.put(dest, Registries.ITEM.getEntry(item));
+ markDirty();
+ }
}
diff --git a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusEditorScreen.java b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusEditorScreen.java
index 6fe445a..582ffe5 100644
--- a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusEditorScreen.java
+++ b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusEditorScreen.java
@@ -1,24 +1,48 @@
package moe.nea.funnyteleporters;
import eu.pb4.sgui.api.ClickType;
+import eu.pb4.sgui.api.elements.GuiElementBuilder;
import eu.pb4.sgui.api.gui.SimpleGui;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+import net.minecraft.registry.Registries;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.text.Text;
public class TeleporterNexusEditorScreen extends SimpleGui {
private final TeleporterNexusBlockEntity blockEntity;
private final TeleporterDestination dest;
public TeleporterNexusEditorScreen(TeleporterNexusBlockEntity blockEntity, TeleporterDestination dest, ServerPlayerEntity player) {
- super(ScreenHandlerType.GENERIC_9X3, player, true);
+ super(ScreenHandlerType.GENERIC_9X3, player, false);
this.blockEntity = blockEntity;
this.dest = dest;
+ setTitle(Text.literal("Set Icon for Teleporter"));
+ setSlots();
+ }
+
+ void setSlots() {
+ for (int i = 0; i < width * height; i++) {
+ setSlot(i, Utils.createBlankBlack());
+ }
+ setSlot(width * height / 2,
+ GuiElementBuilder.from(new ItemStack(blockEntity.destinations.getOrDefault(dest, Registries.ITEM.getEntry(Items.ENDER_PEARL)).value()))
+ .setName(Text.literal("Click item in your inventory to set icon.")));
}
@Override
public boolean onAnyClick(int index, ClickType type, SlotActionType action) {
-
- return super.onAnyClick(index, type, action);
+ System.out.println("Index: " + index);
+ var slot = getSlotRedirectOrPlayer(index);
+ if (slot == null) return true;
+ var stack = slot.getStack();
+ if (!stack.isEmpty()) {
+ blockEntity.setIcon(dest, stack.getItem());
+ new TeleporterNexusScreen(blockEntity, player).open();
+ }
+ return false;
}
}
diff --git a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java
index 6c4d9cf..302d630 100644
--- a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java
+++ b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java
@@ -9,7 +9,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.text.Style;
import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
import java.util.Map;
@@ -20,6 +22,7 @@ public class TeleporterNexusScreen extends SimpleGui {
super(ScreenHandlerType.GENERIC_9X6, player, false);
this.blockEntity = blockEntity;
setSlots();
+ setTitle(Text.literal("Teleport Nexus"));
}
void setSlots() {
@@ -42,11 +45,16 @@ public class TeleporterNexusScreen extends SimpleGui {
return GuiElementBuilder.from(new ItemStack(entry.getValue()))
.setName(Text.literal("Teleport to"))
.hideDefaultTooltip()
- .addLoreLine(Text.literal(String.format("x: %d, y: %d, z: %d", dest.blockPos().getX(), dest.blockPos().getY(), dest.blockPos().getZ())))
- .addLoreLine(Text.literal("in " + dest.target().getValue()))
+ .addLoreLine(Text.literal(String.format("x: %d, y: %d, z: %d", dest.blockPos().getX(), dest.blockPos().getY(), dest.blockPos().getZ()))
+ .setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.AQUA)))
+ .addLoreLine(Text.literal("in " + dest.target().getValue())
+ .setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.AQUA)))
+ .addLoreLine(Text.empty())
+ .addLoreLine(Text.literal("Left-Click to teleport.").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)))
+ .addLoreLine(Text.literal("Right-Click to edit item.").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)))
.setCallback((clickType) -> {
if (clickType == ClickType.MOUSE_RIGHT) {
- new TeleporterNexusEditorScreen(blockEntity, dest, player).open();
+ new TeleporterNexusEditorScreen(blockEntity, dest, player).open();
return;
}
dest.teleport(player);