Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release merge #928

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath group: 'org.parchmentmc', name: 'librarian', version: '1.+', changing: true
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.74'
classpath 'org.parchmentmc:librarian:1.2.0.7-dev-SNAPSHOT'
}
}

Expand Down Expand Up @@ -47,6 +47,9 @@ repositories {
username = System.getenv("USERNAME")
password = System.getenv("READ_PACKAGES_TOKEN")
}
content {
includeGroupByRegex "sophisticatedcore.*"
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
minecraft_version=1.19.2
forge_version=43.2.13
mod_version=3.19.1
mod_version=3.19.4
jei_mc_version=1.19.2-forge
jei_version=11.6.0.+
curios_version=1.19.2-5.1.1.+
jei_version=11.6.0.1018
curios_version=1.19.2-5.1.4.3
botania_version=1.19.2-439-FORGE-SNAPSHOT
patchouli_version=1.19.2-78-SNAPSHOT
balm_cf_file_id=3914527
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
Expand All @@ -35,9 +36,11 @@
import net.p3pp3rf1y.sophisticatedbackpacks.network.InventoryInteractionMessage;
import net.p3pp3rf1y.sophisticatedbackpacks.network.SBPPacketHandler;
import net.p3pp3rf1y.sophisticatedbackpacks.network.UpgradeToggleMessage;
import net.p3pp3rf1y.sophisticatedbackpacks.util.PlayerInventoryProvider;
import net.p3pp3rf1y.sophisticatedcore.util.WorldHelper;

import java.util.Map;
import java.util.Optional;

import static net.minecraftforge.client.settings.KeyConflictContext.GUI;

Expand All @@ -50,7 +53,8 @@ private KeybindHandler() {}
private static final int KEY_X = 88;
private static final int KEY_UNKNOWN = -1;
private static final int MIDDLE_BUTTON = 2;
private static final int CHEST_SLOT_INDEX = 6;
private static final int CHEST_SLOT_INDEX = 38;
private static final int OFFHAND_SLOT_INDEX = 40;
private static final String KEYBIND_SOPHISTICATEDBACKPACKS_CATEGORY = "keybind.sophisticatedbackpacks.category";
public static final KeyMapping BACKPACK_TOGGLE_UPGRADE_5 = new KeyMapping(SBPTranslationHelper.INSTANCE.translKeybind("toggle_upgrade_5"),
KeyConflictContext.UNIVERSAL, InputConstants.Type.KEYSYM.getOrCreate(KEY_UNKNOWN), KEYBIND_SOPHISTICATEDBACKPACKS_CATEGORY);
Expand Down Expand Up @@ -81,7 +85,7 @@ private KeybindHandler() {}

public static void register() {
IEventBus eventBus = MinecraftForge.EVENT_BUS;
eventBus.addListener(KeybindHandler::handleKeyInputEvent);
eventBus.addListener(EventPriority.HIGH, KeybindHandler::handleKeyInputEvent);
eventBus.addListener(EventPriority.HIGH, KeybindHandler::handleGuiMouseKeyPress);
eventBus.addListener(EventPriority.HIGH, KeybindHandler::handleGuiKeyPress);
}
Expand All @@ -95,17 +99,16 @@ public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
}

public static void handleGuiKeyPress(ScreenEvent.KeyPressed.Pre event) {
if (SORT_KEYBIND.isActiveAndMatches(InputConstants.getKey(event.getKeyCode(), event.getScanCode())) && tryCallSort(event.getScreen())) {
InputConstants.Key key = InputConstants.getKey(event.getKeyCode(), event.getScanCode());
if (SORT_KEYBIND.isActiveAndMatches(key) && tryCallSort(event.getScreen()) || BACKPACK_OPEN_KEYBIND.isActiveAndMatches(key) && sendBackpackOpenOrCloseMessage()) {
event.setCanceled(true);
}
}

public static void handleGuiMouseKeyPress(ScreenEvent.MouseButtonPressed.Pre event) {
InputConstants.Key input = InputConstants.Type.MOUSE.getOrCreate(event.getButton());
if (SORT_KEYBIND.isActiveAndMatches(input) && tryCallSort(event.getScreen())) {
if (SORT_KEYBIND.isActiveAndMatches(input) && tryCallSort(event.getScreen()) || BACKPACK_OPEN_KEYBIND.isActiveAndMatches(input) && sendBackpackOpenOrCloseMessage()) {
event.setCanceled(true);
} else if (BACKPACK_OPEN_KEYBIND.isActiveAndMatches(input)) {
sendBackpackOpenOrCloseMessage();
}
}

Expand Down Expand Up @@ -178,45 +181,50 @@ private static void sendInteractWithInventoryMessage() {
}

@SuppressWarnings({"java:S2440", "InstantiationOfUtilityClass"})
private static void sendBackpackOpenOrCloseMessage() {
private static boolean sendBackpackOpenOrCloseMessage() {
if (!GUI.isActive()) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage());
return;
return false;
}

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof BackpackScreen backpackScreen) {
Slot slot = backpackScreen.getSlotUnderMouse();
if (slot != null && slot.getItem().getItem() instanceof BackpackItem) {
if (slot.getItem().getCount() == 1) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage(slot.index));
if (screen instanceof AbstractContainerScreen<?> containerScreen) {
Slot slot = containerScreen.getSlotUnderMouse();

if (slot != null && slot.container instanceof Inventory) {
Optional<String> handlerName = getPlayerInventoryHandlerName(slot.getSlotIndex());

if (handlerName.isPresent() && slot.getItem().getItem() instanceof BackpackItem) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage(slot.getSlotIndex(), "", handlerName.get()));
return true;
}
} else {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackCloseMessage());
}
} else if (screen instanceof InventoryScreen inventoryScreen) {
Slot slot = inventoryScreen.getSlotUnderMouse();

if (slot != null && isSupportedPlayerInventorySlot(slot.index) && slot.getItem().getItem() instanceof BackpackItem) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage(slot.getSlotIndex()));
if (screen instanceof BackpackScreen && slot != null && slot.getItem().getItem() instanceof BackpackItem && slot.getItem().getCount() == 1) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage(slot.index));
return true;
}
}
return false;
}

private static boolean isSupportedPlayerInventorySlot(int slotIndex) {
return slotIndex == CHEST_SLOT_INDEX || (slotIndex > 8 && slotIndex < 46);
private static Optional<String> getPlayerInventoryHandlerName(int slotIndex) {
if (slotIndex == CHEST_SLOT_INDEX) {
return Optional.of(PlayerInventoryProvider.ARMOR_INVENTORY);
} else if (slotIndex == OFFHAND_SLOT_INDEX) {
return Optional.of(PlayerInventoryProvider.OFFHAND_INVENTORY);
} else if (slotIndex >= 0 && slotIndex < 36) {
return Optional.of(PlayerInventoryProvider.MAIN_INVENTORY);
}

return Optional.empty();
}

private static class BackpackKeyConflictContext implements IKeyConflictContext {
public static final BackpackKeyConflictContext INSTANCE = new BackpackKeyConflictContext();

@Override
public boolean isActive() {
if (!GUI.isActive()) {
return true;
}
Screen screen = Minecraft.getInstance().screen;
return screen instanceof BackpackScreen || screen instanceof InventoryScreen;
return !GUI.isActive() || Minecraft.getInstance().screen instanceof AbstractContainerScreen<?>;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ public BackpackScreen(BackpackContainer screenContainer, Inventory inv, Componen
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 || KeybindHandler.BACKPACK_OPEN_KEYBIND.isActiveAndMatches(InputConstants.getKey(keyCode, scanCode))) {
if (getMenu().isFirstLevelStorage() && getMenu().getBackpackContext().wasOpenFromInventory() && mouseNotOverBackpack()) {
getMinecraft().player.closeContainer();
getMinecraft().setScreen(new InventoryScreen(getMinecraft().player));
if (getMenu().isFirstLevelStorage() && (keyCode == 256 || mouseNotOverBackpack())) {
if (getMenu().getBackpackContext().wasOpenFromInventory()) {
getMinecraft().player.closeContainer();
getMinecraft().setScreen(new InventoryScreen(getMinecraft().player));
} else {
onClose();
}
return true;
} else if (!getMenu().isFirstLevelStorage()) {
SBPPacketHandler.INSTANCE.sendToServer(new BackpackOpenMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BackpackOpenMessage {
private static final int OFFHAND_SLOT = 40;
private final int slotIndex;
private final String identifier;
private final String handlerName;

public BackpackOpenMessage() {
this(-1);
Expand All @@ -28,18 +29,24 @@ public BackpackOpenMessage(int backpackSlot) {
this(backpackSlot, "");
}

public BackpackOpenMessage(int backpackSlot, String identifier) {
public BackpackOpenMessage(int backpackSlot, String identifier, String handlerName) {
slotIndex = backpackSlot;
this.identifier = identifier;
this.handlerName = handlerName;
}

public BackpackOpenMessage(int backpackSlot, String identifier) {
this(backpackSlot, identifier, "");
}

public static void encode(BackpackOpenMessage msg, FriendlyByteBuf packetBuffer) {
packetBuffer.writeInt(msg.slotIndex);
packetBuffer.writeUtf(msg.identifier);
packetBuffer.writeUtf(msg.handlerName);
}

public static BackpackOpenMessage decode(FriendlyByteBuf packetBuffer) {
return new BackpackOpenMessage(packetBuffer.readInt(), packetBuffer.readUtf());
return new BackpackOpenMessage(packetBuffer.readInt(), packetBuffer.readUtf(), packetBuffer.readUtf());
}

static void onMessage(BackpackOpenMessage msg, Supplier<NetworkEvent.Context> contextSupplier) {
Expand All @@ -53,7 +60,17 @@ private static void handleMessage(@Nullable ServerPlayer player, BackpackOpenMes
return;
}

if (player.containerMenu instanceof BackpackContainer backpackContainer) {
if (!msg.handlerName.isEmpty()) {
int slotIndex = msg.slotIndex;
if (msg.slotIndex == CHEST_SLOT) {
slotIndex -= 36;
} else if (msg.slotIndex == OFFHAND_SLOT) {
slotIndex = 0;
}
BackpackContext.Item backpackContext = new BackpackContext.Item(msg.handlerName, msg.identifier, slotIndex,
player.containerMenu instanceof InventoryMenu || (player.containerMenu instanceof BackpackContainer backpackContainer && backpackContainer.getBackpackContext().wasOpenFromInventory()));
openBackpack(player, backpackContext);
} else if (player.containerMenu instanceof BackpackContainer backpackContainer) {
BackpackContext backpackContext = backpackContainer.getBackpackContext();
if (msg.slotIndex == -1) {
openBackpack(player, backpackContext.getParentBackpackContext());
Expand All @@ -63,18 +80,6 @@ private static void handleMessage(@Nullable ServerPlayer player, BackpackOpenMes
} else if (player.containerMenu instanceof IContextAwareContainer contextAwareContainer) {
BackpackContext backpackContext = contextAwareContainer.getBackpackContext();
openBackpack(player, backpackContext);
} else if (msg.slotIndex > -1 && player.containerMenu instanceof InventoryMenu) {
int slotIndex = msg.slotIndex;
String inventoryProvider = PlayerInventoryProvider.MAIN_INVENTORY;
if (msg.slotIndex == CHEST_SLOT) {
inventoryProvider = PlayerInventoryProvider.ARMOR_INVENTORY;
} else if (msg.slotIndex == OFFHAND_SLOT) {
inventoryProvider = PlayerInventoryProvider.OFFHAND_INVENTORY;
slotIndex = 0;
}

BackpackContext.Item backpackContext = new BackpackContext.Item(inventoryProvider, msg.identifier, slotIndex, true);
openBackpack(player, backpackContext);
} else {
findAndOpenFirstBackpack(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.AtomicDouble;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -50,6 +53,7 @@
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
Expand All @@ -60,7 +64,14 @@
public class ToolSwapperUpgradeWrapper extends UpgradeWrapperBase<ToolSwapperUpgradeWrapper, ToolSwapperUpgradeItem>
implements IBlockClickResponseUpgrade, IAttackEntityResponseUpgrade, IBlockToolSwapUpgrade, IEntityToolSwapUpgrade {

private static final Set<Item> notTools = new HashSet<>();
private static final LoadingCache<ItemStack, Boolean> isToolCache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build(
new CacheLoader<>() {
@Override
public Boolean load(ItemStack key) {
return canPerformToolAction(key);
}
}
);

private final FilterLogic filterLogic;
@Nullable
Expand Down Expand Up @@ -163,26 +174,16 @@ public boolean onAttackEntity(Player player) {
}

private boolean isNotTool(ItemStack stack) {
if (notTools.contains(stack.getItem())) {
return true;
}

if (canPerformToolAction(stack)) {
return false;
}

notTools.add(stack.getItem());

return true;
return !isToolCache.getUnchecked(stack);
}

private boolean canPerformToolAction(ItemStack stack) {
private static boolean canPerformToolAction(ItemStack stack) {
return canPerformAnyAction(stack, ToolActions.DEFAULT_AXE_ACTIONS) || canPerformAnyAction(stack, ToolActions.DEFAULT_HOE_ACTIONS)
|| canPerformAnyAction(stack, ToolActions.DEFAULT_PICKAXE_ACTIONS) || canPerformAnyAction(stack, ToolActions.DEFAULT_SHOVEL_ACTIONS)
|| canPerformAnyAction(stack, ToolActions.DEFAULT_SHEARS_ACTIONS);
}

private boolean canPerformAnyAction(ItemStack stack, Set<ToolAction> toolActions) {
private static boolean canPerformAnyAction(ItemStack stack, Set<ToolAction> toolActions) {
for (ToolAction toolAction : toolActions) {
if (stack.canPerformAction(toolAction)) {
return true;
Expand Down
Loading