-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
304 additions
and
15 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Airflow-API/src/main/java/me/glicz/airflow/api/event/Cancellable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.glicz.airflow.api.event; | ||
|
||
public interface Cancellable { | ||
boolean isCancelled(); | ||
|
||
void setCancelled(boolean cancelled); | ||
} |
33 changes: 33 additions & 0 deletions
33
Airflow-API/src/main/java/me/glicz/airflow/api/event/inventory/InventoryClickEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.glicz.airflow.api.event.inventory; | ||
|
||
import me.glicz.airflow.api.entity.living.Humanoid; | ||
import me.glicz.airflow.api.event.Cancellable; | ||
import me.glicz.airflow.api.inventory.Inventory; | ||
import me.glicz.airflow.api.inventory.menu.view.MenuView; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class InventoryClickEvent extends InventoryEvent implements Cancellable { | ||
private final int slot; | ||
private boolean cancelled; | ||
|
||
@ApiStatus.Internal | ||
public InventoryClickEvent(@NotNull Humanoid viewer, @NotNull MenuView menuView, Inventory inventory, int slot) { | ||
super(viewer, menuView, inventory); | ||
this.slot = slot; | ||
} | ||
|
||
public int getSlot() { | ||
return slot; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Airflow-API/src/main/java/me/glicz/airflow/api/event/inventory/InventoryEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.glicz.airflow.api.event.inventory; | ||
|
||
import me.glicz.airflow.api.entity.living.Humanoid; | ||
import me.glicz.airflow.api.event.inventory.menu.MenuEvent; | ||
import me.glicz.airflow.api.inventory.Inventory; | ||
import me.glicz.airflow.api.inventory.menu.view.MenuView; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.UnknownNullability; | ||
|
||
public abstract class InventoryEvent extends MenuEvent { | ||
private final Inventory inventory; | ||
|
||
public InventoryEvent(@NotNull Humanoid viewer, @NotNull MenuView menuView, Inventory inventory) { | ||
super(viewer, menuView); | ||
this.inventory = inventory; | ||
} | ||
|
||
public @UnknownNullability Inventory getInventory() { | ||
return inventory; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Airflow-API/src/main/java/me/glicz/airflow/api/event/inventory/menu/MenuCloseEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.glicz.airflow.api.event.inventory.menu; | ||
|
||
import me.glicz.airflow.api.entity.living.Humanoid; | ||
import me.glicz.airflow.api.inventory.menu.view.MenuView; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MenuCloseEvent extends MenuEvent { | ||
@ApiStatus.Internal | ||
public MenuCloseEvent(@NotNull Humanoid viewer, @NotNull MenuView menuView) { | ||
super(viewer, menuView); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Airflow-API/src/main/java/me/glicz/airflow/api/event/inventory/menu/MenuEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package me.glicz.airflow.api.event.inventory.menu; | ||
|
||
import me.glicz.airflow.api.entity.living.Humanoid; | ||
import me.glicz.airflow.api.event.Event; | ||
import me.glicz.airflow.api.inventory.menu.view.MenuView; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class MenuEvent extends Event { | ||
private final Humanoid viewer; | ||
private final MenuView menuView; | ||
|
||
public MenuEvent(@NotNull Humanoid viewer, @NotNull MenuView menuView) { | ||
this.viewer = viewer; | ||
this.menuView = menuView; | ||
} | ||
|
||
public @NotNull Humanoid getViewer() { | ||
return viewer; | ||
} | ||
|
||
public @NotNull MenuView getMenuView() { | ||
return menuView; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Airflow-API/src/main/java/me/glicz/airflow/api/event/inventory/menu/MenuOpenEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.glicz.airflow.api.event.inventory.menu; | ||
|
||
import me.glicz.airflow.api.entity.living.Humanoid; | ||
import me.glicz.airflow.api.event.Cancellable; | ||
import me.glicz.airflow.api.inventory.menu.view.MenuView; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MenuOpenEvent extends MenuEvent implements Cancellable { | ||
private boolean cancelled; | ||
|
||
@ApiStatus.Internal | ||
public MenuOpenEvent(@NotNull Humanoid viewer, @NotNull MenuView menuView) { | ||
super(viewer, menuView); | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
Airflow-API/src/main/java/me/glicz/airflow/api/inventory/ComposedInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package me.glicz.airflow.api.inventory; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
|
||
public interface ComposedInventory extends Inventory { | ||
Collection<Inventory> getInventories(); | ||
@NotNull Collection<Inventory> getInventories(); | ||
|
||
@NotNull Inventory getInventoryForSlot(int slot); | ||
} |
3 changes: 2 additions & 1 deletion
3
Airflow-API/src/main/java/me/glicz/airflow/api/inventory/menu/view/ItemCombinerView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package me.glicz.airflow.api.inventory.menu.view; | ||
|
||
import me.glicz.airflow.api.inventory.Inventory; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface ItemCombinerView extends MenuView { | ||
Inventory getResultInventory(); | ||
@NotNull Inventory getResultInventory(); | ||
} |
3 changes: 2 additions & 1 deletion
3
Airflow-API/src/main/java/me/glicz/airflow/api/inventory/menu/view/LoomView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package me.glicz.airflow.api.inventory.menu.view; | ||
|
||
import me.glicz.airflow.api.inventory.Inventory; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface LoomView extends MenuView { | ||
Inventory getOutputInventory(); | ||
@NotNull Inventory getOutputInventory(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: GliczDev <67753196+GliczDev@users.noreply.github.com> | ||
Date: Sat, 28 Sep 2024 17:04:56 +0200 | ||
Subject: [PATCH] Inventory Events | ||
|
||
|
||
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java | ||
index d6a0cd9c22785edb7e7966141b301c02c456d076..45653fe04137c5eca009b108f04bd2812af54348 100644 | ||
--- a/net/minecraft/server/level/ServerPlayer.java | ||
+++ b/net/minecraft/server/level/ServerPlayer.java | ||
@@ -1083,6 +1083,11 @@ public class ServerPlayer extends Player { | ||
} else { | ||
// Airflow start - Inventory API | ||
abstractContainerMenu.getAirMenuView().setTitle(menu.getDisplayName()); | ||
+ // Airflow start - Inventory Events | ||
+ me.glicz.airflow.api.event.inventory.menu.MenuOpenEvent event = getServer().getDedicatedServer().airflow.serverEventBus | ||
+ .dispatchMenuOpen(this, abstractContainerMenu); | ||
+ if (event.isCancelled()) return OptionalInt.empty(); | ||
+ // Airflow end - Inventory Events | ||
abstractContainerMenu.getAirMenuView().openScreen(); | ||
/* | ||
this.connection | ||
@@ -1138,6 +1143,7 @@ public class ServerPlayer extends Player { | ||
|
||
@Override | ||
public void doCloseContainer() { | ||
+ getServer().getDedicatedServer().airflow.serverEventBus.dispatchMenuClose(this, this.containerMenu); // Airflow start - Inventory Events | ||
this.containerMenu.removed(this); | ||
this.inventoryMenu.transferState(this.containerMenu); | ||
this.containerMenu = this.inventoryMenu; | ||
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java | ||
index 7522c722e65db2e97b926b3e74291512f2d23954..796bac3ac2dbc6caae23b523687321519a17e19a 100644 | ||
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java | ||
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java | ||
@@ -296,6 +296,11 @@ public abstract class AbstractContainerMenu { | ||
public abstract ItemStack quickMoveStack(Player player, int index); | ||
|
||
public void clicked(int slotId, int button, ClickType clickType, Player player) { | ||
+ // Airflow start - Inventory Events | ||
+ me.glicz.airflow.api.event.inventory.InventoryClickEvent event = player.getServer().getDedicatedServer().airflow.serverEventBus | ||
+ .dispatchInventoryClick(player, this, slotId); | ||
+ if (event.isCancelled()) return; | ||
+ // Airflow end - Inventory Events | ||
try { | ||
this.doClick(slotId, button, clickType, player); | ||
} catch (Exception var8) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.