Skip to content

Commit

Permalink
Fix vaults, et al. (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora authored Dec 19, 2021
1 parent 180320c commit 1d8249e
Show file tree
Hide file tree
Showing 29 changed files with 175 additions and 84 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
options: --user root
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v2
with:
distribution: adopt
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
options: --user root
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v2
with:
distribution: adopt
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/snapshot_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v2
with:
distribution: adopt
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ allprojects {
jar { from "LICENSE" }

task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload) {
final String loader = project.name
onlyIf { System.getenv().MODRINTH_TOKEN }
detectLoaders = false
token = System.getenv().MODRINTH_TOKEN
projectId = "QYTT62S0"
versionNumber = mod_version + "+" + project.name
versionName = "${rootProject.release_title} (${project.name.toUpperCase().indexOf(0)})"
versionNumber = mod_version + "+" + loader
versionName = "${rootProject.release_title} (${loader.substring(0, 1).toUpperCase() + loader.substring(1)})"
changelog = rootProject.changeLog
uploadFile = project.file("build/libs/${rootProject.archivesBaseName}-${rootProject.version}.jar")
addGameVersion(mc_version)
addLoader(project.name)
addLoader(loader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonParser;
import dev.frydae.emcutils.utils.Util;
import lombok.Getter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.Vec3d;

import java.io.BufferedReader;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static List<EmpireResidence> getAllResidences() {
}

public void sendToServer() {
Util.getPlayer().sendChatMessage(getCommand());
MinecraftClient.getInstance().player.sendChatMessage(getCommand());
Util.setCurrentServer(getName());
}

Expand Down
32 changes: 19 additions & 13 deletions common/src/main/java/dev/frydae/emcutils/features/ChatChannels.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;
Expand All @@ -20,6 +23,8 @@ public class ChatChannels {
@Setter private static String targetUsername = null;
@Setter private static int targetGroupId = 0;
private static long lastClickedButtonTime = 0L;
private static final ClientPlayerEntity player = MinecraftClient.getInstance().player;
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;

public static void handleChatScreenRender(Screen screen, MatrixStack matrices) {
if (Util.isOnEMC) {
Expand All @@ -44,7 +49,8 @@ public static void handleChatScreenMouseClicked(Screen screen, double mouseX, do
currentChannel = channel;
channel.executeCommand();

Util.getClient().player.playSound(Config.getChatAlertSound().getSoundEvent(), 5, Config.getChatAlertPitch());
if (Config.getChatAlertSound() != Config.ChatAlertSound.NULL)
player.playSound(Config.getChatAlertSound().getSoundEvent(), 5, Config.getChatAlertPitch());

// Cancel private conversation if in one
inPrivateConversation = false;
Expand All @@ -56,8 +62,8 @@ public static void handleChatScreenMouseClicked(Screen screen, double mouseX, do
}

private static boolean isInBounds(Screen screen, String text, int offset, double mouseX, double mouseY) {
int width = Util.getClient().textRenderer.getWidth(text);
int height = Util.getClient().textRenderer.fontHeight;
int width = textRenderer.getWidth(text);
int height = textRenderer.fontHeight;

// Check X coordinate
if (mouseX < offset + 1 || mouseX >= offset + width) {
Expand All @@ -69,26 +75,26 @@ private static boolean isInBounds(Screen screen, String text, int offset, double
}

private static void drawButton(Screen screen, MatrixStack matrices, ChatChannel channel) {
int width = Util.getClient().textRenderer.getWidth(channel.name);
int height = Util.getClient().textRenderer.fontHeight;
int width = textRenderer.getWidth(channel.name);
int height = textRenderer.fontHeight;

if (currentChannel == channel && !inPrivateConversation) {
DrawableHelper.fill(matrices, channel.getOffset(), screen.height - 33, channel.getOffset() + width + 5, screen.height - (32 - height - 4), (0xff << 24) | channel.format.getColorValue());
}

DrawableHelper.fill(matrices, channel.getOffset() + 1, screen.height - 32, channel.getOffset() + width + 4, screen.height - (32 - height - 3), (0xc0 << 24));
Util.getClient().textRenderer.draw(matrices, new LiteralText(channel.name), channel.getOffset() + 3, screen.height - 30, channel.format.getColorValue());
textRenderer.draw(matrices, new LiteralText(channel.name), channel.getOffset() + 3, screen.height - 30, channel.format.getColorValue());
}

private static void drawPrivateConversation(Screen screen, MatrixStack matrices) {
int fullWidth = Util.getClient().textRenderer.getWidth("PM with: " + targetUsername);
int nameWidth = Util.getClient().textRenderer.getWidth(targetUsername);
int height = Util.getClient().textRenderer.fontHeight;
int fullWidth = textRenderer.getWidth("PM with: " + targetUsername);
int nameWidth = textRenderer.getWidth(targetUsername);
int height = textRenderer.fontHeight;

DrawableHelper.fill(matrices, screen.width - 3, screen.height - 33, screen.width - fullWidth - 8, screen.height - (32 - height - 4), (0xff << 24) | Formatting.LIGHT_PURPLE.getColorValue());
DrawableHelper.fill(matrices, screen.width - 4, screen.height - 32, screen.width - fullWidth - 7, screen.height - (32 - height - 3), (0xc0 << 24));
Util.getClient().textRenderer.draw(matrices, new LiteralText("PM with: "), screen.width - fullWidth - 5, screen.height - 30, Formatting.WHITE.getColorValue());
Util.getClient().textRenderer.draw(matrices, new LiteralText(targetUsername), screen.width - nameWidth - 5, screen.height - 30, groupIdToFormatting(targetGroupId).getColorValue());
textRenderer.draw(matrices, new LiteralText("PM with: "), screen.width - fullWidth - 5, screen.height - 30, Formatting.WHITE.getColorValue());
textRenderer.draw(matrices, new LiteralText(targetUsername), screen.width - nameWidth - 5, screen.height - 30, groupIdToFormatting(targetGroupId).getColorValue());
}

public static Formatting groupIdToFormatting(int groupId) {
Expand Down Expand Up @@ -131,11 +137,11 @@ public int getOffset() {
return 2;
}

return adjustAgainst.getOffset() + Util.getClient().textRenderer.getWidth(adjustAgainst.name) + 6;
return adjustAgainst.getOffset() + textRenderer.getWidth(adjustAgainst.name) + 6;
}

public void executeCommand() {
Util.getClient().player.sendChatMessage(command);
player.sendChatMessage(command);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.client.network.PlayerListEntry;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class TabListOrganizer {
Expand All @@ -21,7 +20,7 @@ public static List<PlayerListEntry> sortPlayers(List<PlayerListEntry> original)
}

for (PlayerListEntry entry : original) {
char server = Objects.requireNonNull(entry.getDisplayName()).getSiblings().get(0).getString().charAt(1);
char server = entry.getDisplayName().getSiblings().get(0).getString().charAt(1);
String playerName = entry.getDisplayName().getSiblings().get(1).getString();

EnhancedTabListEntry enhancedEntry = new EnhancedTabListEntry(EmpireServer.getByTabListDisplay(server), playerName, entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.Objects;

public class UsableItems {
public UsableItems() {
ClientTooltipEvent.ITEM.register(((itemStack, list, tooltipContext) -> {
Expand Down Expand Up @@ -47,7 +45,7 @@ public UsableItems() {
private static boolean isUsableItemWithCooldown(ItemStack item) {
if (item != null && item.getNbt() != null) {
if (item.getNbt().get("display") != null) {
String displayString = Objects.requireNonNull(item.getNbt().get("display")).toString();
String displayString = item.getNbt().get("display").toString();

JsonObject display = new JsonParser().parse(displayString).getAsJsonObject();
JsonArray originalLore = display.getAsJsonArray("OriginalLore");
Expand Down Expand Up @@ -81,7 +79,7 @@ private static boolean isUsableItemWithCooldown(ItemStack item) {
private static long getSecondsUntilUsable(ItemStack item) {
if (item != null && item.getNbt() != null) {
if (item.getNbt().get("display") != null) {
String displayString = Objects.requireNonNull(item.getNbt().get("display")).toString();
String displayString = item.getNbt().get("display").toString();

JsonObject display = new JsonParser().parse(displayString).getAsJsonObject();
JsonArray originalLore = display.getAsJsonArray("OriginalLore");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralText;
Expand All @@ -35,21 +34,21 @@
import static dev.frydae.emcutils.utils.Util.MODID;

@SuppressWarnings("SpellCheckingInspection")
public class VaultScreen extends HandledScreen<GenericContainerScreenHandler> implements ScreenHandlerProvider<GenericContainerScreenHandler> {
public static final RegistrySupplier<ScreenHandlerType<GenericContainerScreenHandler>> GENERIC_9X7;
public class VaultScreen extends HandledScreen<VaultScreenHandler> implements ScreenHandlerProvider<VaultScreenHandler> {
public static final RegistrySupplier<ScreenHandlerType<VaultScreenHandler>> GENERIC_9X7;
private static final Identifier TEXTURE = new Identifier(MODID, Config.returnVaultScreenOption());
private final int vaultPage;
private final int[] slotOffsets = {8, 26, 44, 62, 80, 98, 116, 134, 152};
private boolean shouldCallClose = true;

static {
Registrar<ScreenHandlerType<?>> screenHandlers = EmpireMinecraftUtilities.REGISTRIES.get(Registry.MENU_KEY);
GENERIC_9X7 = screenHandlers.register(new Identifier(MODID, "generic_9x7"), () -> MenuRegistry.of(CreateGeneric9x7::createGeneric9x7));
GENERIC_9X7 = screenHandlers.register(new Identifier(MODID, "generic_9x7"), () -> MenuRegistry.of(VaultScreenHandler::createGeneric9x7));
}

public static void initStatic() {}

public VaultScreen(GenericContainerScreenHandler handler, PlayerInventory inventory, Text title) {
public VaultScreen(VaultScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
super.init(MinecraftClient.getInstance(), MinecraftClient.getInstance().getWindow().getScaledWidth(), MinecraftClient.getInstance().getWindow().getScaledHeight());
this.passEvents = false;
Expand All @@ -64,10 +63,8 @@ public VaultScreen(GenericContainerScreenHandler handler, PlayerInventory invent
}
}

private static final class CreateGeneric9x7 {
static GenericContainerScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) {
return new GenericContainerScreenHandler(GENERIC_9X7.get(), syncId, playerInventory, 7);
}
public static VaultScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) {
return new VaultScreenHandler(GENERIC_9X7.get(), syncId, playerInventory, 6);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package dev.frydae.emcutils.features;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;

public class VaultScreenHandler extends ScreenHandler {
private final Inventory inventory;
private final int rows;

public VaultScreenHandler(ScreenHandlerType<VaultScreenHandler> type, int syncId, PlayerInventory playerInventory, int rows) {
this(type, syncId, playerInventory, new SimpleInventory(9 * rows), rows);
}

public VaultScreenHandler(ScreenHandlerType<VaultScreenHandler> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) {
super(type, syncId);
checkSize(inventory, rows * 9);
this.inventory = inventory;
this.rows = rows;
inventory.onOpen(playerInventory.player);
int i = (6 - 3) * 18;

for (int row = 0; row < 6; ++row) {
for (int column = 0; column < 9; ++column) {
this.addSlot(new Slot(inventory, column + row * 9, 8 + column * 18, 18 + row * 18));
}
}

for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 9; ++column) {
this.addSlot(new Slot(playerInventory, column + row * 9 + 9, 8 + column * 18, 103 + row * 18 + i));
}
}

for (int row = 0; row < 9; ++row) {
this.addSlot(new Slot(playerInventory, row, 8 + row * 18, 161 + i));
}
}

public static VaultScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) {
return new VaultScreenHandler(VaultScreen.GENERIC_9X7.get(), syncId, playerInventory, 6);
}

public boolean canUse(PlayerEntity player) {
return this.inventory.canPlayerUse(player);
}

public ItemStack transferSlot(PlayerEntity player, int index) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);

if (slot.hasStack()) {
ItemStack itemStack2 = slot.getStack();
itemStack = itemStack2.copy();

if (index < this.rows * 9) {
if (!this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(itemStack2, 0, this.rows * 9, false)) {
return ItemStack.EMPTY;
}

if (itemStack2.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();
}
}

return itemStack;
}

public void close(PlayerEntity player) {
super.close(player);
this.inventory.onClose(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;

public class ChatListener {
private static final String WELCOME_TO_EMC = "Welcome to Empire Minecraft - .*, .*!";
Expand Down Expand Up @@ -80,7 +79,7 @@ private static ActionResult handleChatChannelChange(ClientPlayerEntity player, T

private static ActionResult userGroupReceiver(ClientPlayerEntity player, Text text) {
if (text.getString().matches(WELCOME_TO_EMC)) {
int group = getGroupIdFromColor(Objects.requireNonNull(text.getSiblings().get(5).getStyle().getColor()));
int group = getGroupIdFromColor(text.getSiblings().get(5).getStyle().getColor());

Util.setPlayerGroupId(group);
}
Expand All @@ -102,11 +101,11 @@ public static int getPlayerGroupIdFromTabList(String user) {
List<PlayerListEntry> entries = Util.getPlayerListEntries();

for (PlayerListEntry entry : entries) {
if (Objects.requireNonNull(entry.getDisplayName()).getSiblings().get(1).getString().equalsIgnoreCase(user)) {
if (entry.getDisplayName().getSiblings().get(1).getString().equalsIgnoreCase(user)) {
if (entry.getDisplayName().getSiblings().size() > 1) {
Text coloredName = entry.getDisplayName().getSiblings().get(1);

return getGroupIdFromColor(Objects.requireNonNull(coloredName.getStyle().getColor()));
return getGroupIdFromColor(coloredName.getStyle().getColor());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.frydae.emcutils.features.VisitResidenceHandler;
import dev.frydae.emcutils.interfaces.CommandCallback;
import dev.frydae.emcutils.utils.Util;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.ActionResult;
import org.apache.commons.lang3.math.NumberUtils;
Expand Down Expand Up @@ -36,7 +37,7 @@ private static ActionResult handleResidenceHomeCommand(ClientPlayerEntity player
}
} else return ActionResult.PASS;

String resName = Util.getPlayer().getEntityName() + (num > 1 ? "-" + num : ""); // FIXME: this is what causes #33
String resName = MinecraftClient.getInstance().player.getEntityName() + (num > 1 ? "-" + num : ""); // FIXME: this is what causes #33

EmpireServer server = VisitResidenceHandler.getResidenceServer(resName);

Expand Down
Loading

0 comments on commit 1d8249e

Please sign in to comment.