Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ViewConfig {
private final Set<Modifier> modifiers;
private final long updateIntervalInTicks, interactionDelayInMillis;
private final boolean transitiveInitialData;
private final boolean entityContainerInteractionsAllowed;
private final TimerState updateIntervalState;

public ViewConfig(
Expand All @@ -43,6 +44,7 @@ public ViewConfig(
long updateIntervalInTicks,
long interactionDelayInMillis,
boolean transitiveInitialData,
boolean entityContainerInteractionsAllowed,
TimerState updateIntervalState) {
this.title = title;
this.size = size;
Expand All @@ -53,6 +55,7 @@ public ViewConfig(
this.updateIntervalInTicks = updateIntervalInTicks;
this.interactionDelayInMillis = interactionDelayInMillis;
this.transitiveInitialData = transitiveInitialData;
this.entityContainerInteractionsAllowed = entityContainerInteractionsAllowed;
this.updateIntervalState = updateIntervalState;
}

Expand Down Expand Up @@ -92,6 +95,17 @@ public boolean isTransitiveInitialData() {
return transitiveInitialData;
}

/**
* Whether interactions coming from the actor's own container (e.g. their inventory) are
* allowed to happen even when this view is configured to cancel interactions with its own
* container.
*
* @return If interactions on the actor's container are allowed.
*/
public boolean isEntityContainerInteractionsAllowed() {
return entityContainerInteractionsAllowed;
}

@Nullable
public TimerState getUpdateIntervalState() {
return updateIntervalState;
Expand Down Expand Up @@ -154,6 +168,7 @@ public ViewConfig merge(ViewConfig other) {
merge(other, ViewConfig::getUpdateIntervalInTicks, value -> value != 0),
merge(other, ViewConfig::getInteractionDelayInMillis, value -> value != 0),
merge(other, ViewConfig::isTransitiveInitialData),
merge(other, ViewConfig::isEntityContainerInteractionsAllowed),
merge(other, ViewConfig::getUpdateIntervalState, Objects::nonNull));
}

Expand Down Expand Up @@ -245,6 +260,7 @@ && getInteractionDelayInMillis() == that.getInteractionDelayInMillis()
&& Arrays.equals(getLayout(), that.getLayout())
&& Objects.equals(getModifiers(), that.getModifiers())
&& isTransitiveInitialData() == that.isTransitiveInitialData()
&& isEntityContainerInteractionsAllowed() == that.isEntityContainerInteractionsAllowed()
&& Objects.equals(getUpdateIntervalState(), that.getUpdateIntervalState());
}

Expand All @@ -259,6 +275,7 @@ public int hashCode() {
getUpdateIntervalInTicks(),
getInteractionDelayInMillis(),
isTransitiveInitialData(),
isEntityContainerInteractionsAllowed(),
getUpdateIntervalState());
result = 31 * result + Arrays.hashCode(getLayout());
return result;
Expand All @@ -275,7 +292,8 @@ public String toString() {
+ modifiers + ", updateIntervalInTicks="
+ updateIntervalInTicks + ", interactionDelayInMillis="
+ interactionDelayInMillis + ", transitiveInitialData="
+ transitiveInitialData + ", updateIntervalState="
+ transitiveInitialData + ", entityContainerInteractionsAllowed="
+ entityContainerInteractionsAllowed + ", updateIntervalState="
+ updateIntervalState + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class ViewConfigBuilder {
private long updateIntervalInTicks, interactionDelayInMillis;
private TimerState updateIntervalState;
private boolean transitiveInitialData;
private boolean entityContainerInteractionsAllowed;

/**
* Inherits all configuration from another {@link ViewConfigBuilder} value.
Expand All @@ -53,6 +54,7 @@ public ViewConfigBuilder inheritFrom(@NotNull ViewConfigBuilder other) {
if (other.updateIntervalState != null) this.updateIntervalState = other.updateIntervalState;
if (other.interactionDelayInMillis != 0) this.interactionDelayInMillis = other.interactionDelayInMillis;
if (other.transitiveInitialData) this.transitiveInitialData = true;
if (other.entityContainerInteractionsAllowed) this.entityContainerInteractionsAllowed = true;
this.options.addAll(other.options);
this.modifiers.addAll(other.modifiers);
return this;
Expand Down Expand Up @@ -205,6 +207,21 @@ public ViewConfigBuilder cancelOnDrag() {
return addOption(ViewConfig.CANCEL_ON_DRAG);
}

/**
* Allows interactions on the actor's own container (e.g. their inventory) to happen even
* though this view cancels interactions with its own container.
* <p>
* This only affects interactions on the actor's container, interactions with the view's
* container are unaffected and follow {@link #cancelOnClick()} and other cancel options
* normally.
*
* @return This configuration builder.
*/
public ViewConfigBuilder allowEntityContainerInteractions() {
this.entityContainerInteractionsAllowed = true;
return this;
}

/**
* Schedules the view to update every fixed interval.
*
Expand Down Expand Up @@ -295,6 +312,7 @@ public ViewConfig build() {
getUpdateIntervalInTicks(),
getInteractionDelayInMillis(),
transitiveInitialData,
entityContainerInteractionsAllowed,
getUpdateIntervalState());
}

Expand Down Expand Up @@ -341,4 +359,8 @@ long getInteractionDelayInMillis() {
public boolean isTransitiveInitialData() {
return transitiveInitialData;
}

boolean isEntityContainerInteractionsAllowed() {
return entityContainerInteractionsAllowed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public void intercept(@NotNull PipelineContext<VirtualView> pipeline, @NotNull V
final SlotClickContext context = (SlotClickContext) subject;
final InventoryClickEvent event = context.getClickOrigin();

final boolean allowedOnEntityContainer =
context.isOnEntityContainer() && context.getConfig().isEntityContainerInteractionsAllowed();

// inherit cancellation so we can un-cancel it
context.setCancelled(event.isCancelled() || context.getConfig().isOptionSet(CANCEL_ON_CLICK, true));
context.setCancelled(event.isCancelled()
|| (context.getConfig().isOptionSet(CANCEL_ON_CLICK, true) && !allowedOnEntityContainer));
context.getRoot().onClick(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class GlobalClickInterceptor : PipelineInterceptor<VirtualView> {

val event: InventoryPreClickEvent = subject.clickOrigin

val allowedOnEntityContainer =
subject.isOnEntityContainer && subject.config.isEntityContainerInteractionsAllowed
val cancelOnClick = subject.config.isOptionSet(ViewConfig.CANCEL_ON_CLICK, true)

// inherit cancellation so we can un-cancel it
subject.isCancelled =
event.isCancelled ||
subject.config.isOptionSet(ViewConfig.CANCEL_ON_CLICK, true)
subject.isCancelled = event.isCancelled || (cancelOnClick && !allowedOnEntityContainer)
subject.root.onClick(subject)
}
}
Loading