Skip to content

Commit

Permalink
feat: manually merge changes from my branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed Jul 15, 2024
1 parent 0339285 commit 9a16324
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 36 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
- Update to 1.21
- Switch to using the [Accessories](https://modrinth.com/mod/accessories) mod. See its mod page for information on compatibility with existing mods using Trinkets and Curios.
- Fix hotbar rendering even when F1 is pressed.
- Fix server crash (#48).
- Move config client side, since all of its options were only applicable there.
- Fix issue with using enchanted items in the belt (#49).
- General stability improvements.

Thanks to blodhgarm, developer of the Accessories mod, for finding and fixing the illusive enchantment issue.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dev.architectury.utils.EnvExecutor;
import io.github.jamalam360.jamlib.JamLib;
import io.github.jamalam360.jamlib.JamLibPlatform;
import io.github.jamalam360.jamlib.config.ConfigManager;
import io.github.jamalam360.utility_belt.client.UtilityBeltClient;
import io.github.jamalam360.utility_belt.screen.UtilityBeltMenu;
import io.github.jamalam360.utility_belt.server.ServerNetworking;
Expand All @@ -32,7 +31,6 @@ public class UtilityBelt {
public static final String MOD_ID = "utility_belt";
public static final String MOD_NAME = "Utility Belt";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
public static final ConfigManager<Config> CONFIG = new ConfigManager<>(MOD_ID, Config.class);
public static final TagKey<Item> ALLOWED_IN_UTILITY_BELT = TagKey.create(Registries.ITEM, id("allowed_in_utility_belt"));

private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(MOD_ID, Registries.ITEM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public static boolean isValidItem(ItemStack stack) {
return stack.getItem() instanceof TieredItem || stack.getItem() instanceof ProjectileWeaponItem || stack.getItem() instanceof FishingRodItem || stack.getItem() instanceof SpyglassItem || stack.getItem() instanceof TridentItem || stack.getItem() instanceof FlintAndSteelItem || stack.getItem() instanceof ShearsItem || stack.getItem() instanceof BrushItem || stack.isEmpty() || stack.is(UtilityBelt.ALLOWED_IN_UTILITY_BELT);
}

// Going to keep this name as is until 1.20.4 support is dropped, to keep the diffs smaller
public static UtilityBeltInventory getInventoryFromTag(ItemStack stack) {
public static UtilityBeltInventory getInventory(ItemStack stack) {
if (!stack.has(UtilityBelt.UTILITY_BELT_INVENTORY_COMPONENT_TYPE.get())) {
stack.set(UtilityBelt.UTILITY_BELT_INVENTORY_COMPONENT_TYPE.get(), UtilityBeltInventory.EMPTY);
}
Expand All @@ -98,12 +97,12 @@ public static ItemStack getBelt(Player player) {

@Override
public boolean isBarVisible(ItemStack itemStack) {
return getInventoryFromTag(itemStack).items().stream().anyMatch(s -> !s.isEmpty());
return getInventory(itemStack).items().stream().anyMatch(s -> !s.isEmpty());
}

@Override
public int getBarWidth(ItemStack itemStack) {
long size = getInventoryFromTag(itemStack).items().stream().filter((s) -> !s.isEmpty()).count();
long size = getInventory(itemStack).items().stream().filter((s) -> !s.isEmpty()).count();
return size == 4L ? 13 : (int) (size * 3);
}

Expand All @@ -114,7 +113,7 @@ public int getBarColor(ItemStack itemStack) {

@Override
public void appendHoverText(ItemStack itemStack, TooltipContext tooltipContext, List<Component> list, TooltipFlag tooltipFlag) {
UtilityBeltInventory inv = getInventoryFromTag(itemStack);
UtilityBeltInventory inv = getInventory(itemStack);

for (int i = 0; i < inv.getContainerSize(); i++) {
ItemStack stack = inv.getItem(i);
Expand All @@ -131,7 +130,7 @@ public boolean overrideStackedOnOther(ItemStack belt, Slot slot, ClickAction cli
}

ItemStack slotStack = slot.getItem();
UtilityBeltInventory.Mutable inv = new Mutable(getInventoryFromTag(belt));
UtilityBeltInventory.Mutable inv = new Mutable(getInventory(belt));

if (!handleStack(slotStack, inv, slot::set)) {
return false;
Expand All @@ -148,7 +147,7 @@ public boolean overrideOtherStackedOnMe(ItemStack belt, ItemStack otherStack, Sl
return false;
}

UtilityBeltInventory.Mutable inv = new Mutable(getInventoryFromTag(belt));
UtilityBeltInventory.Mutable inv = new Mutable(getInventory(belt));

if (!handleStack(otherStack, inv, slotAccess::set)) {
return false;
Expand All @@ -174,7 +173,7 @@ public void onUnequip(ItemStack stack, SlotReference reference) {
@Override
public void onEquip(ItemStack stack, SlotReference reference) {
if (reference.entity() instanceof Player player && !player.level().isClientSide) {
StateManager.getStateManager(player).setInventory(player, new Mutable(getInventoryFromTag(stack)));
StateManager.getStateManager(player).setInventory(player, new Mutable(getInventory(stack)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public record S2CUpdateBeltInventory(UtilityBeltInventory inventory) implements

@Override
public Type<? extends CustomPacketPayload> type() {
return new CustomPacketPayload.Type<>(UtilityBelt.id("update_belt_inventory"));
return S2C_UPDATE_BELT_INVENTORY;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class BeltHotbarRenderer {

public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
Player player = Minecraft.getInstance().player;

if(player == null) return;


if (Minecraft.getInstance().options.hideGui || player == null) {
return;
}

StateManager stateManager = StateManager.getStateManager(player);

if (stateManager.hasBelt(player) && (stateManager.isInBelt(player)
|| UtilityBelt.CONFIG.get().displayUtilityBeltWhenNotSelected)) {
|| UtilityBeltClient.CONFIG.get().displayUtilityBeltWhenNotSelected)) {
int scaledHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight();
int x = switch (UtilityBelt.CONFIG.get().hotbarPosition) {
int x = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
case TOP_LEFT, MIDDLE_LEFT, BOTTOM_LEFT -> 2;
case TOP_RIGHT, MIDDLE_RIGHT, BOTTOM_RIGHT -> Minecraft.getInstance().getWindow().getGuiScaledWidth() - 24;
};
int y = switch (UtilityBelt.CONFIG.get().hotbarPosition) {
int y = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
case TOP_LEFT, TOP_RIGHT -> 2;
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - 44;
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - 84;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.architectury.networking.NetworkManager;
import io.github.jamalam360.utility_belt.StateManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory.Mutable;
import io.github.jamalam360.utility_belt.UtilityBeltPackets;
import io.github.jamalam360.utility_belt.UtilityBeltPackets.C2SOpenScreen;
Expand All @@ -24,7 +23,7 @@ public static void init() {
}

public static void sendNewStateToServer(boolean inBelt, int slot, boolean swapItems) {
if (swapItems && !UtilityBelt.CONFIG.get().useSneakSwapping) {
if (swapItems && !UtilityBeltClient.CONFIG.get().useSneakSwapping) {
swapItems = false;
}

Expand All @@ -37,18 +36,20 @@ public static void sendOpenScreenToServer() {
}

private static void handleSetBeltSlot(S2CSetBeltSlot payload, NetworkManager.PacketContext ctx) {
Player player = ctx.getPlayer();

StateManager.getStateManager(player).setSelectedBeltSlot(player, payload.slot());
ctx.queue(() -> {
Player player = ctx.getPlayer();
StateManager.getStateManager(player).setSelectedBeltSlot(player, payload.slot());
});
}

private static void handleSetHotbarSlot(S2CSetHotbarSlot payload, NetworkManager.PacketContext ctx) {
ctx.getPlayer().getInventory().selected = payload.slot();
ctx.queue(() -> ctx.getPlayer().getInventory().selected = payload.slot());
}

private static void handleUpdateBeltInventory(S2CUpdateBeltInventory payload, NetworkManager.PacketContext ctx) {
Player player = ctx.getPlayer();

StateManager.getStateManager(player).setInventory(player, new Mutable(payload.inventory()));
ctx.queue(() -> {
Player player = ctx.getPlayer();
StateManager.getStateManager(player).setInventory(player, new Mutable(payload.inventory()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public UtilityBeltInventory getInventory(Player player) {
if (belt == null) {
return UtilityBeltInventory.EMPTY;
} else {
return UtilityBeltItem.getInventoryFromTag(belt);
return UtilityBeltItem.getInventory(belt);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.github.jamalam360.utility_belt;
package io.github.jamalam360.utility_belt.client;

import io.github.jamalam360.jamlib.config.ConfigExtensions;
import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;

@Environment(EnvType.CLIENT)
public class Config implements ConfigExtensions<Config> {
public boolean displayUtilityBeltWhenNotSelected = true;
public boolean invertScrolling = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.architectury.platform.Platform;
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import dev.architectury.registry.menu.MenuRegistry;
import io.github.jamalam360.jamlib.config.ConfigManager;
import io.github.jamalam360.utility_belt.StateManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltItem;
Expand All @@ -28,6 +29,7 @@

@Environment(EnvType.CLIENT)
public class UtilityBeltClient {
public static final ConfigManager<Config> CONFIG = new ConfigManager<>(UtilityBelt.MOD_ID, Config.class);
private static final KeyMapping SWAP_TOGGLE = new KeyMapping("key.utility_belt.swap_toggle", GLFW.GLFW_KEY_B, "key.category.utility_belt");
private static final KeyMapping SWAP_HOLD = new KeyMapping("key.utility_belt.swap_hold", GLFW.GLFW_KEY_N, "key.category.utility_belt");
private static final KeyMapping OPEN_SCREEN = new KeyMapping("key.utility_belt.open_screen", GLFW.GLFW_KEY_APOSTROPHE, "key.category.utility_belt");
Expand Down Expand Up @@ -127,7 +129,7 @@ private static EventResult onMouseScrolled(Minecraft client, double scrollX, dou

int beltSize = stateManager.getInventory(player).getContainerSize();

if (UtilityBelt.CONFIG.get().invertScrolling) {
if (CONFIG.get().invertScrolling) {
scrollY = -scrollY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import io.github.jamalam360.utility_belt.StateManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltItem;
import io.github.jamalam360.utility_belt.client.ClientNetworking;
import io.github.jamalam360.utility_belt.client.UtilityBeltClient;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class MinecraftMixin {
private boolean utilitybelt$useHotbarKeysInBelt(boolean pressed, @Local int i) {
StateManager stateManager = StateManager.getStateManager(true);
if (stateManager.isInBelt(this.player) && pressed) {
switch (UtilityBelt.CONFIG.get().hotbarKeyBehaviour) {
switch (UtilityBeltClient.CONFIG.get().hotbarKeyBehaviour) {
case SWITCH_BACK_TO_HOTBAR:
stateManager.setInBelt(this.player, false);
ClientNetworking.sendNewStateToServer(false, stateManager.getSelectedBeltSlot(this.player), this.player.isCrouching());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static class Factory implements MenuProvider {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
return new UtilityBeltMenu(i, inventory, new Mutable(UtilityBeltItem.getInventoryFromTag(UtilityBeltItem.getBelt(player))));
return new UtilityBeltMenu(i, inventory, new Mutable(UtilityBeltItem.getInventory(UtilityBeltItem.getBelt(player))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public UtilityBeltInventory getInventory(Player player) {
return UtilityBeltInventory.EMPTY;
}

state.inventory = UtilityBeltItem.getInventoryFromTag(belt);
state.inventory = UtilityBeltItem.getInventory(belt);
}

return state.inventory;
Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ processResources {
expand "minecraft_version": project.minecraft_version,
"architectury_version": libs.versions.architectury.get(),
"jamlib_version": libs.versions.jamlib.get(),
"accessories_version": libs.versions.curios.get()
"accessories_version": libs.versions.accessories.get()
}

inputs.property "minecraft_version", project.minecraft_version
Expand Down

0 comments on commit 9a16324

Please sign in to comment.