Skip to content

Commit

Permalink
Merge branch '1.21' into 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Oct 23, 2024
2 parents f12690a + a524f48 commit d07f668
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 53 deletions.
26 changes: 5 additions & 21 deletions src/main/java/io/wispforest/owo/compat/emi/OwoEmiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
import dev.emi.emi.api.widget.Bounds;
import io.wispforest.owo.itemgroup.OwoItemGroup;
import io.wispforest.owo.mixin.itemgroup.CreativeInventoryScreenAccessor;
import io.wispforest.owo.mixin.ui.access.BaseOwoHandledScreenAccessor;
import io.wispforest.owo.ui.core.Component;
import io.wispforest.owo.ui.core.ParentComponent;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.base.BaseOwoHandledScreen;
import io.wispforest.owo.util.pond.OwoCreativeInventoryScreenExtensions;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;

import java.util.ArrayList;

public class OwoEmiPlugin implements EmiPlugin {
@Override
public void register(EmiRegistry registry) {
Expand All @@ -36,22 +31,11 @@ public void register(EmiRegistry registry) {
});

registry.addGenericExclusionArea((screen, consumer) -> {
if (screen.children().isEmpty() || !(screen instanceof BaseOwoHandledScreenAccessor accessor)) return;

var adapter = accessor.owo$getUIAdapter();
if (adapter == null) return;

var rootComponent = adapter.rootComponent;
var children = new ArrayList<Component>();
rootComponent.collectDescendants(children);
children.remove(rootComponent);

children.forEach(component -> {
if (component instanceof ParentComponent parent && parent.surface() == Surface.BLANK) return;
if (!(screen instanceof BaseOwoHandledScreen<?, ?> owoHandledScreen)) return;

var size = component.fullSize();
consumer.accept(new Bounds(component.x(), component.y(), size.width(), size.height()));
});
owoHandledScreen.componentsForExclusionAreas()
.map(component -> new Bounds(component.x(), component.y(), component.width(), component.height()))
.forEach(consumer);
});
}
}
23 changes: 3 additions & 20 deletions src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.wispforest.owo.mixin.itemgroup.CreativeInventoryScreenAccessor;
import io.wispforest.owo.mixin.ui.access.BaseOwoHandledScreenAccessor;
import io.wispforest.owo.ui.base.BaseOwoHandledScreen;
import io.wispforest.owo.ui.core.Component;
import io.wispforest.owo.ui.core.OwoUIDrawContext;
import io.wispforest.owo.ui.core.ParentComponent;
import io.wispforest.owo.ui.core.Surface;
Expand All @@ -28,7 +27,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class OwoReiPlugin implements REIClientPlugin {

Expand Down Expand Up @@ -59,24 +57,9 @@ public void registerExclusionZones(ExclusionZones zones) {
});

zones.register(BaseOwoHandledScreen.class, screen -> {
if (screen.children().isEmpty()) return List.of();

var adapter = ((BaseOwoHandledScreenAccessor) screen).owo$getUIAdapter();
if (adapter == null) return List.of();

var rootComponent = adapter.rootComponent;
var children = new ArrayList<Component>();
rootComponent.collectDescendants(children);
children.remove(rootComponent);

var rectangles = new ArrayList<Rectangle>();
children.forEach(component -> {
if (component instanceof ParentComponent parent && parent.surface() == Surface.BLANK) return;

var size = component.fullSize();
rectangles.add(new Rectangle(component.x(), component.y(), size.width(), size.height()));
});
return rectangles;
return ((BaseOwoHandledScreen<?, ?>) screen).componentsForExclusionAreas()
.map(rect -> new Rectangle(rect.x(), rect.y(), rect.width(), rect.height()))
.toList();
});
}

Expand Down
53 changes: 41 additions & 12 deletions src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.function.BiFunction;
import java.util.stream.Stream;

public abstract class BaseOwoHandledScreen<R extends ParentComponent, S extends ScreenHandler> extends HandledScreen<S> implements DisposableScreen {

Expand Down Expand Up @@ -95,7 +98,7 @@ protected void init() {
* @param index The index of the slot to disable
*/
protected void disableSlot(int index) {
((OwoSlotExtension) this.handler.slots.get(index)).owo$setDisabledOverride(true);
this.disableSlot(this.handler.slots.get(index));
}

/**
Expand All @@ -115,7 +118,7 @@ protected void disableSlot(Slot slot) {
* @param index The index of the slot to enable
*/
protected void enableSlot(int index) {
((OwoSlotExtension) this.handler.slots.get(index)).owo$setDisabledOverride(false);
this.enableSlot(this.handler.slots.get(index));
}

/**
Expand All @@ -124,15 +127,23 @@ protected void enableSlot(int index) {
* a slot that is disabled through its own will
*/
protected void enableSlot(Slot slot) {
((OwoSlotExtension) slot).owo$setDisabledOverride(true);
((OwoSlotExtension) slot).owo$setDisabledOverride(false);
}

/**
* @return whether the given slot is enabled or disabled
* using the {@link OwoSlotExtension} disabling functionality
*/
protected boolean isSlotEnabled(int index) {
return ((OwoSlotExtension) this.handler.slots.get(index)).owo$getDisabledOverride();
return isSlotEnabled(this.handler.slots.get(index));
}

/**
* @return whether the given slot is enabled or disabled
* using the {@link OwoSlotExtension} disabling functionality
*/
protected boolean isSlotEnabled(Slot slot) {
return ((OwoSlotExtension) slot).owo$getDisabledOverride();
return !((OwoSlotExtension) slot).owo$getDisabledOverride();
}

/**
Expand All @@ -154,6 +165,24 @@ protected <C extends Component> C component(Class<C> expectedClass, String id) {
return this.uiAdapter.rootComponent.childById(expectedClass, id);
}

/**
* Compute a stream of all components for which to
* generate exclusion areas in a recipe viewer overlay.
* Called by the REI and EMI plugins
*/
@ApiStatus.OverrideOnly
public Stream<Component> componentsForExclusionAreas() {
if (this.children().isEmpty()) return Stream.of();

var rootComponent = uiAdapter.rootComponent;
var children = new ArrayList<Component>();

rootComponent.collectDescendants(children);
children.remove(rootComponent);

return children.stream().filter(component -> !(component instanceof ParentComponent parent) || parent.surface() != Surface.BLANK);
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {}

Expand All @@ -171,12 +200,12 @@ public void render(DrawContext vanillaContext, int mouseX, int mouseY, float del
if (!slot.isEnabled()) continue;

context.drawText(Text.literal("H:" + i),
this.x + slot.x + 15, this.y + slot.y + 9, .5f, 0x0096FF,
OwoUIDrawContext.TextAnchor.BOTTOM_RIGHT
this.x + slot.x + 15, this.y + slot.y + 9, .5f, 0x0096FF,
OwoUIDrawContext.TextAnchor.BOTTOM_RIGHT
);
context.drawText(Text.literal("I:" + slot.getIndex()),
this.x + slot.x + 15, this.y + slot.y + 15, .5f, 0x5800FF,
OwoUIDrawContext.TextAnchor.BOTTOM_RIGHT
this.x + slot.x + 15, this.y + slot.y + 15, .5f, 0x5800FF,
OwoUIDrawContext.TextAnchor.BOTTOM_RIGHT
);
}

Expand All @@ -192,8 +221,8 @@ public void render(DrawContext vanillaContext, int mouseX, int mouseY, float del
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if ((modifiers & GLFW.GLFW_MOD_CONTROL) == 0
&& this.uiAdapter.rootComponent.focusHandler().focused() instanceof GreedyInputComponent inputComponent
&& inputComponent.onKeyPress(keyCode, scanCode, modifiers)) {
&& this.uiAdapter.rootComponent.focusHandler().focused() instanceof GreedyInputComponent inputComponent
&& inputComponent.onKeyPress(keyCode, scanCode, modifiers)) {
return true;
}

Expand Down Expand Up @@ -249,7 +278,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
GL11.glGetIntegerv(GL11.GL_SCISSOR_BOX, scissor);

((OwoSlotExtension) this.slot).owo$setScissorArea(PositionedRectangle.of(
scissor[0], scissor[1], scissor[2], scissor[3]
scissor[0], scissor[1], scissor[2], scissor[3]
));
}

Expand Down

0 comments on commit d07f668

Please sign in to comment.