diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-07-05 15:31:12 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-07-05 15:31:12 +0800 |
| commit | 17150bedcdf80944a64e165976cf2491d409b1c0 (patch) | |
| tree | f71725bf6c37fd2bc82fbf8bf07a4b98ba2d1584 /src/main/java/me/shedaniel/rei/impl | |
| parent | af1b3f780d8edb361c00421cdd991f3f2b86849c (diff) | |
| download | RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.gz RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.bz2 RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.zip | |
Fix #370 and changes to how screens are handled
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/impl')
6 files changed, 74 insertions, 38 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java index 679041fa8..eacc92a96 100644 --- a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java @@ -27,6 +27,9 @@ import com.google.common.collect.Lists; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.BaseBoundsHandler; import me.shedaniel.rei.api.DisplayHelper; +import me.shedaniel.rei.gui.config.DisplayPanelLocation; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.ActionResult; @@ -38,6 +41,7 @@ import java.util.List; import java.util.function.Supplier; @ApiStatus.Internal +@Environment(EnvType.CLIENT) public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private static final Comparator<? super Rectangle> RECTANGLE_COMPARER = Comparator.comparingLong(Rectangle::hashCode); @@ -46,18 +50,8 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private List<Pair<Pair<Class<?>, Float>, Supplier<List<Rectangle>>>> list = Lists.newArrayList(); @Override - public Class<?> getBaseSupportedClass() { - return Screen.class; - } - - @Override - public Rectangle getLeftBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public Rectangle getRightBounds(Screen screen) { - return new Rectangle(); + public boolean isHandingScreen(Class<?> screen) { + return Screen.class.isAssignableFrom(screen); } @Override @@ -78,30 +72,16 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { } @Override - public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { - long current = currentHashCode(isOnRightSide); + public boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { + long current = currentHashCode(location); if (lastArea == current) return false; lastArea = current; return true; } - private long currentHashCode(boolean isOnRightSide) { - DisplayHelper.DisplayBoundsHandler<Screen> handler = (DisplayHelper.DisplayBoundsHandler<Screen>) DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - return areasHashCode(isOnRightSide ? handler.getRightBounds(MinecraftClient.getInstance().currentScreen) : handler.getLeftBounds(MinecraftClient.getInstance().currentScreen), getExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), false)); - } - - @Override - public ActionResult canItemSlotWidgetFit(int left, int top, Screen screen, Rectangle fullBounds) { - Class<? extends Screen> screenClass = screen.getClass(); - for (Pair<Pair<Class<?>, Float>, Supplier<List<Rectangle>>> pair : list) { - if (pair.getLeft().getLeft().isAssignableFrom(screenClass)) - for (Rectangle zone : pair.getRight().get()) { - if (left + 18 >= zone.x && top + 18 >= zone.y && left <= zone.getMaxX() && top <= zone.getMaxY()) - return ActionResult.FAIL; - } - } - return ActionResult.PASS; + private long currentHashCode(DisplayPanelLocation location) { + return areasHashCode(DisplayHelper.getInstance().getOverlayBounds(location, MinecraftClient.getInstance().currentScreen), getExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), false)); } @Override diff --git a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index 2334f4340..e67e52590 100644 --- a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -170,6 +170,11 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { inventory.setCursorStack(stack.getItemStack().copy()); return true; } else if (RoughlyEnoughItemsCore.canUsePackets()) { + PlayerInventory inventory = MinecraftClient.getInstance().player.inventory; + EntryStack stack = entry.copy(); + if (!inventory.getCursorStack().isEmpty() && !EntryStack.create(inventory.getCursorStack()).equalsIgnoreAmount(stack)) { + return false; + } try { ClientSidePacketRegistry.INSTANCE.sendToServer(ConfigObject.getInstance().isGrabbingItems() ? RoughlyEnoughItemsNetwork.CREATE_ITEMS_GRAB_PACKET : RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()).writeItemStack(cheatedStack)); return true; diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java index b15fac22b..df030349a 100644 --- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java @@ -139,8 +139,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } @Override - public boolean isLeftHandSidePanel() { - return advanced.accessibility.displayPanelLocation == DisplayPanelLocation.LEFT; + public DisplayPanelLocation getDisplayPanelLocation() { + return advanced.accessibility.displayPanelLocation; } @Override diff --git a/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java index 0744f91f3..a4132e043 100644 --- a/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java @@ -29,7 +29,12 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.BaseBoundsHandler; import me.shedaniel.rei.api.DisplayHelper; import me.shedaniel.rei.api.OverlayDecider; +import me.shedaniel.rei.gui.config.DisplayPanelLocation; import me.shedaniel.rei.utils.CollectionUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.Window; import org.jetbrains.annotations.ApiStatus; import java.util.Collections; @@ -38,9 +43,10 @@ import java.util.List; import java.util.Map; @ApiStatus.Internal +@Environment(EnvType.CLIENT) public class DisplayHelperImpl implements DisplayHelper { - private static final Comparator<OverlayDecider> BOUNDS_HANDLER_COMPARATOR; + private static final Comparator<OverlayDecider> BOUNDS_HANDLER_COMPARATOR = Comparator.comparingDouble(OverlayDecider::getPriority).reversed(); private static final DisplayBoundsHandler<Object> EMPTY = new DisplayBoundsHandler<Object>() { @Override public Class<Object> getBaseSupportedClass() { @@ -63,13 +69,9 @@ public class DisplayHelperImpl implements DisplayHelper { } }; - static { - Comparator<OverlayDecider> comparator = Comparator.comparingDouble(OverlayDecider::getPriority); - BOUNDS_HANDLER_COMPARATOR = comparator.reversed(); - } - private List<OverlayDecider> screenDisplayBoundsHandlers = Lists.newArrayList(); private Map<Class<?>, DisplayBoundsHandler<?>> handlerCache = Maps.newHashMap(); + private Map<Class<?>, List<OverlayDecider>> deciderSortedCache = Maps.newHashMap(); private Map<Class<?>, List<DisplayBoundsHandler<?>>> handlerSortedCache = Maps.newHashMap(); private BaseBoundsHandler baseBoundsHandler; private Class<?> tempScreen; @@ -86,6 +88,16 @@ public class DisplayHelperImpl implements DisplayHelper { } @Override + public List<OverlayDecider> getSortedOverlayDeciders(Class<?> screenClass) { + List<OverlayDecider> possibleCached = deciderSortedCache.get(screenClass); + if (possibleCached != null) + return possibleCached; + tempScreen = screenClass; + deciderSortedCache.put(screenClass, (List) CollectionUtils.filter(screenDisplayBoundsHandlers, this::filterResponsible)); + return deciderSortedCache.get(screenClass); + } + + @Override public List<OverlayDecider> getAllOverlayDeciders() { return Collections.unmodifiableList(screenDisplayBoundsHandlers); } @@ -100,6 +112,28 @@ public class DisplayHelperImpl implements DisplayHelper { return handlerCache.get(screenClass); } + @Override + public <T> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen) { + Window window = MinecraftClient.getInstance().getWindow(); + int scaledWidth = window.getScaledWidth(); + int scaledHeight = window.getScaledHeight(); + for (OverlayDecider decider : getSortedOverlayDeciders(screen.getClass())) { + if (decider instanceof DisplayBoundsProvider) { + Rectangle containerBounds = ((DisplayBoundsProvider<T>) decider).getScreenBounds(screen); + if (location == DisplayPanelLocation.LEFT) { + if (containerBounds.x < 10) continue; + return new Rectangle(2, 0, containerBounds.x - 2, scaledHeight); + } else { + if (scaledWidth - containerBounds.getMaxX() < 10) continue; + return new Rectangle(containerBounds.getMaxX() + 2, 0, scaledWidth - containerBounds.getMaxX() - 4, scaledHeight); + } + } else if (decider instanceof DisplayBoundsHandler) { + return location == DisplayPanelLocation.LEFT ? ((DisplayBoundsHandler<T>) decider).getLeftBounds(screen) : ((DisplayBoundsHandler<T>) decider).getRightBounds(screen); + } + } + return new Rectangle(); + } + private boolean filterResponsible(OverlayDecider handler) { return handler.isHandingScreen(tempScreen); } diff --git a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java index 1cf5b705f..bcdea853d 100644 --- a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java @@ -34,6 +34,8 @@ import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.api.subsets.SubsetsRegistry; import me.shedaniel.rei.impl.subsets.SubsetsRegistryImpl; import me.shedaniel.rei.utils.CollectionUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; @@ -49,6 +51,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; @ApiStatus.Internal +@Environment(EnvType.CLIENT) public class RecipeHelperImpl implements RecipeHelper { private static final Comparator<DisplayVisibilityHandler> VISIBILITY_HANDLER_COMPARATOR; diff --git a/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java index a46bddc50..7068e15ce 100644 --- a/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java +++ b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java @@ -28,6 +28,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import me.shedaniel.cloth.api.client.events.v0.ClothClientHooks; import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; import me.shedaniel.math.api.Executor; import me.shedaniel.rei.RoughlyEnoughItemsState; import me.shedaniel.rei.api.ConfigManager; @@ -38,8 +39,11 @@ import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.OverlaySearchField; import me.shedaniel.rei.gui.RecipeScreen; import me.shedaniel.rei.gui.WarningAndErrorScreen; +import me.shedaniel.rei.gui.config.SearchFieldLocation; import me.shedaniel.rei.gui.widget.TextFieldWidget; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.event.client.ClientTickCallback; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; @@ -58,6 +62,7 @@ import java.util.List; import java.util.Optional; @ApiStatus.Internal +@Environment(EnvType.CLIENT) public class ScreenHelper implements ClientModInitializer, REIHelper { private OverlaySearchField searchField; @@ -203,6 +208,15 @@ public class ScreenHelper implements ClientModInitializer, REIHelper { ScreenHelper.instance = this; } + public static Rectangle getItemListArea(Rectangle bounds) { + return new Rectangle(bounds.x, bounds.y + 2 + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22), bounds.width, bounds.height - (ConfigObject.getInstance().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22)); + } + + public static Rectangle getFavoritesListArea(Rectangle bounds) { + int offset = 6 + (!ConfigObject.getInstance().isLowerConfigButton() ? 25 : 0) + (ConfigObject.getInstance().doesShowUtilsButtons() ? 25 : 0); + return new Rectangle(bounds.x, bounds.y + 2 + offset, bounds.width, bounds.height - 5 - offset); + } + @Override public void onInitializeClient() { ClothClientHooks.SCREEN_INIT_PRE.register((client, screen, screenHooks) -> { |
