Skip to content

Commit

Permalink
Add a system to inherit existing items
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed May 3, 2024
1 parent bab92d5 commit ddd07cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val javaVersion: Int = 21

allprojects {
group = "com.noxcrew.interfaces"
version = "1.1.3-SNAPSHOT"
version = "1.1.4-SNAPSHOT"

tasks.withType<JavaCompile> {
sourceCompatibility = javaVersion.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AbstractInterfaceBuilder<P : Pane, I : Interface<P>> inter
public var itemPostProcessor: ((ItemStack) -> Unit)? = null

/** Whether clicking on empty slots should be cancelled. */
public var preventClickingEmptySlots: Boolean = false
public var preventClickingEmptySlots: Boolean = true

/**
* Persists items added to this pane in a previous instance.
Expand All @@ -39,6 +39,9 @@ public abstract class AbstractInterfaceBuilder<P : Pane, I : Interface<P>> inter
*/
public var persistAddedItems: Boolean = false

/** Keeps items that were previously in the inventory before opening the view. */
public val inheritExistingItems: Boolean = false

/** The properties object to use for the created interface. */
public val properties: InterfaceProperties<P>
get() = InterfaceProperties(
Expand All @@ -48,7 +51,8 @@ public abstract class AbstractInterfaceBuilder<P : Pane, I : Interface<P>> inter
itemPostProcessor,
preventClickingEmptySlots,
preventedInteractions,
persistAddedItems
persistAddedItems,
inheritExistingItems
)

/** Adds a new transform to the interface that updates whenever [triggers] change. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public data class InterfaceProperties<P : Pane>(
/** A post-processor applied to all items placed in the inventory. */
public val itemPostProcessor: ((ItemStack) -> Unit)? = {},
/** Whether clicking on empty slots should be cancelled. */
public val preventClickingEmptySlots: Boolean = false,
public val preventClickingEmptySlots: Boolean = true,
/** All interactions that will be ignored on this view and cancelled on pane items without calling the handler. */
public val preventedInteractions: Collection<Action> = emptySet(),
/** Persists items added to this pane in a previous instance. */
public val persistAddedItems: Boolean = false
public val persistAddedItems: Boolean = false,
/** Keeps items that were previously in the inventory before opening this. */
public val inheritExistingItems: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,14 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
}
}

// Empty any slots that are not otherwise edited
for ((row, column) in leftovers) {
val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
if ((!drawNormalInventory && !isPlayerInventory) || (!drawPlayerInventory && isPlayerInventory)) continue
currentInventory.set(row, column, ItemStack(Material.AIR))
// If we inherit existing items we don't clear here!
if (!backing.properties.inheritExistingItems) {
// Empty any slots that are not otherwise edited
for ((row, column) in leftovers) {
val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
if ((!drawNormalInventory && !isPlayerInventory) || (!drawPlayerInventory && isPlayerInventory)) continue
currentInventory.set(row, column, ItemStack(Material.AIR))
}
}

if (madeChanges) {
Expand Down

0 comments on commit ddd07cd

Please sign in to comment.