From 23c820ea583052744232e84a6c99114223c43a69 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 25 Mar 2021 02:50:16 +0800 Subject: Refactor MenuInfo, split client and server apis, new dual PluginManager system, remove @NotNull Signed-off-by: shedaniel --- .../me/shedaniel/rei/impl/ScreenRegistryImpl.java | 235 --------------------- 1 file changed, 235 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java deleted file mode 100644 index 781f78bae..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.mojang.blaze3d.platform.Window; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.gui.config.DisplayPanelLocation; -import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.util.EntryStacks; -import me.shedaniel.rei.api.plugins.REIPlugin; -import me.shedaniel.rei.api.registry.screen.*; -import me.shedaniel.rei.api.util.CollectionUtils; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.inventory.AbstractContainerMenu; -import org.apache.commons.lang3.mutable.Mutable; -import org.apache.commons.lang3.mutable.MutableObject; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.stream.Collectors; - -@ApiStatus.Internal -@Environment(EnvType.CLIENT) -public class ScreenRegistryImpl implements ScreenRegistry { - private Multimap, ClickArea> clickAreas = HashMultimap.create(); - private List focusedStackProviders = new ArrayList<>(); - private List deciders = new ArrayList<>(); - private Map, List> cache = new HashMap<>(); - private ExclusionZones exclusionZones; - private Class tmpScreen; - - @Override - public void acceptPlugin(REIPlugin plugin) { - plugin.registerScreens(this); - plugin.registerExclusionZones(exclusionZones()); - } - - @Override - public List getDeciders(R screen) { - Class screenClass = screen.getClass(); - List possibleCached = cache.get(screenClass); - if (possibleCached != null) { - return possibleCached; - } - - tmpScreen = screenClass; - List deciders = CollectionUtils.filterToList(this.deciders, this::filterResponsible); - cache.put(screenClass, deciders); - tmpScreen = null; - return deciders; - } - - private boolean filterResponsible(OverlayDecider handler) { - return handler.isHandingScreen(tmpScreen); - } - - @Override - public List getDeciders() { - return Collections.unmodifiableList(deciders); - } - - @Override - public Rectangle getScreenBounds(T screen) { - for (OverlayDecider decider : getDeciders(screen)) { - if (decider instanceof DisplayBoundsProvider) { - return ((DisplayBoundsProvider) decider).getScreenBounds(screen); - } - } - return new Rectangle(); - } - - @Override - public Rectangle getOverlayBounds(DisplayPanelLocation location, T screen) { - Window window = Minecraft.getInstance().getWindow(); - int scaledWidth = window.getGuiScaledWidth(); - int scaledHeight = window.getGuiScaledHeight(); - Rectangle screenBounds = getScreenBounds(screen); - if (screenBounds.isEmpty()) return new Rectangle(); - if (location == DisplayPanelLocation.LEFT) { - if (screenBounds.x < 10) return new Rectangle(); - return new Rectangle(2, 0, screenBounds.x - 2, scaledHeight); - } else { - if (scaledWidth - screenBounds.getMaxX() < 10) return new Rectangle(); - return new Rectangle(screenBounds.getMaxX() + 2, 0, scaledWidth - screenBounds.getMaxX() - 4, scaledHeight); - } - } - - @Nullable - @Override - public EntryStack getFocusedStack(T screen, Point mouse) { - for (FocusedStackProvider provider : focusedStackProviders) { - InteractionResultHolder> result = Objects.requireNonNull(provider.provide(screen, mouse)); - if (result.getResult() == InteractionResult.SUCCESS) { - if (result != null && !result.getObject().isEmpty()) - return result.getObject(); - return null; - } else if (result.getResult() == InteractionResult.FAIL) - return null; - } - - return null; - } - - @Override - public void registerDecider(OverlayDecider decider) { - deciders.add(decider); - deciders.sort(Comparator.reverseOrder()); - clickAreas.clear(); - cache.clear(); - tmpScreen = null; - } - - @Override - public void registerFocusedStack(FocusedStackProvider provider) { - focusedStackProviders.add(provider); - focusedStackProviders.sort(Comparator.reverseOrder()); - } - - @Override - public ExclusionZones exclusionZones() { - return exclusionZones; - } - - @Override - public > void registerContainerClickArea(SimpleClickArea area, Class screenClass, ResourceLocation... categories) { - registerClickArea(screen -> { - Rectangle rectangle = area.provide(screen).clone(); - rectangle.translate(screen.leftPos, screen.topPos); - return rectangle; - }, screenClass, categories); - } - - @Override - public void registerClickArea(Class screenClass, ClickArea area) { - clickAreas.put(screenClass, area); - } - - @Override - @Nullable - public Set handleClickArea(Class screenClass, ClickArea.ClickAreaContext context) { - Mutable> categories = new MutableObject<>(null); - for (ClickArea area : this.clickAreas.get(screenClass)) { - ClickArea.Result result = ((ClickArea) area).handle(context); - - if (result.isSuccessful()) { - if (categories.getValue() == null) { - categories.setValue(new LinkedHashSet<>()); - } - result.getCategories().collect(Collectors.toCollection(categories::getValue)); - } - } - return categories.getValue(); - } - - @Override - public void startReload() { - clickAreas.clear(); - deciders.clear(); - cache.clear(); - focusedStackProviders.clear(); - tmpScreen = null; - - registerDefault(); - } - - private void registerDefault() { - registerDecider(this.exclusionZones = new ExclusionZonesImpl()); - registerDecider(new OverlayDecider() { - @Override - public boolean isHandingScreen(Class screen) { - return true; - } - - @Override - public InteractionResult shouldScreenBeOverlaid(Class screen) { - return AbstractContainerScreen.class.isAssignableFrom(screen) ? InteractionResult.SUCCESS : InteractionResult.PASS; - } - - @Override - public float getPriority() { - return -10; - } - }); - registerFocusedStack(new FocusedStackProvider() { - @Override - @NotNull - public InteractionResultHolder> provide(Screen screen, Point mouse) { - if (screen instanceof AbstractContainerScreen) { - AbstractContainerScreen containerScreen = (AbstractContainerScreen) screen; - if (containerScreen.hoveredSlot != null && !containerScreen.hoveredSlot.getItem().isEmpty()) - return InteractionResultHolder.success(EntryStacks.of(containerScreen.hoveredSlot.getItem())); - } - return InteractionResultHolder.pass(EntryStack.empty()); - } - - @Override - public double getPriority() { - return -10.0; - } - }); - } -} -- cgit