@@ -24,13 +24,15 @@ final class AnvilWindowImpl extends AbstractSplitWindow<CustomAnvilMenu> impleme
2424 private final AbstractGui upperGui ;
2525 private final AbstractGui lowerGui ;
2626 private Property <? extends Boolean > textFieldAlwaysEnabled ;
27+ private Property <? extends Boolean > resultAlwaysValid ;
2728
2829 public AnvilWindowImpl (
2930 Player player ,
3031 Supplier <? extends Component > title ,
3132 AbstractGui upperGui ,
3233 AbstractGui lowerGui ,
3334 Property <? extends Boolean > textFieldAlwaysEnabled ,
35+ Property <? extends Boolean > resultAlwaysValid ,
3436 Property <? extends Boolean > closeable
3537 ) {
3638 super (player , title , lowerGui , upperGui .getSize () + lowerGui .getSize (), new CustomAnvilMenu (player ), closeable );
@@ -40,6 +42,7 @@ public AnvilWindowImpl(
4042 this .upperGui = upperGui ;
4143 this .lowerGui = lowerGui ;
4244 this .textFieldAlwaysEnabled = textFieldAlwaysEnabled ;
45+ this .resultAlwaysValid = resultAlwaysValid ;
4346
4447 textFieldAlwaysEnabled .observeWeak (this , thisRef -> thisRef .notifyUpdate (0 ));
4548 menu .setRenameHandler (this ::handleRename );
@@ -53,8 +56,8 @@ private void handleRename(String text) {
5356
5457 @ Override
5558 protected void setMenuItem (int slot , @ Nullable ItemStack itemStack ) {
56- if (slot == 0 && textFieldAlwaysEnabled .get ()) {
57- menu .setItem (0 , ItemUtils .takeOrPlaceholder (itemStack ));
59+ if (( slot == 0 && textFieldAlwaysEnabled .get ()) || ( slot == 2 && resultAlwaysValid . get () )) {
60+ menu .setItem (slot , ItemUtils .takeOrPlaceholder (itemStack ));
5861 } else {
5962 super .setMenuItem (slot , itemStack );
6063 }
@@ -87,6 +90,18 @@ public void setTextFieldAlwaysEnabled(boolean textFieldAlwaysEnabled) {
8790 notifyUpdate (0 );
8891 }
8992
93+ @ Override
94+ public boolean getResultAlwaysValid () {
95+ return resultAlwaysValid .get ();
96+ }
97+
98+ @ Override
99+ public void setResultAlwaysValid (boolean resultAlwaysValid ) {
100+ this .resultAlwaysValid .unobserveWeak (this );
101+ this .resultAlwaysValid = Property .of (resultAlwaysValid );
102+ notifyUpdate (2 );
103+ }
104+
90105 @ Override
91106 public void addRenameHandler (Consumer <? super String > handler ) {
92107 renameHandlers .add (handler );
@@ -121,6 +136,7 @@ public static final class BuilderImpl
121136 private final List <Consumer <? super String >> renameHandlers = new ArrayList <>();
122137 private Supplier <? extends Gui > upperGuiSupplier = () -> Gui .empty (3 , 1 );
123138 private Property <? extends Boolean > textFieldAlwaysEnabled = Property .of (true );
139+ private Property <? extends Boolean > resultAlwaysValid = Property .of (false );
124140
125141 @ Override
126142 public BuilderImpl setUpperGui (Supplier <? extends Gui > guiSupplier ) {
@@ -147,6 +163,12 @@ public AnvilWindow.Builder setTextFieldAlwaysEnabled(Property<? extends Boolean>
147163 return this ;
148164 }
149165
166+ @ Override
167+ public AnvilWindow .Builder setResultAlwaysValid (Property <? extends Boolean > resultAlwaysValid ) {
168+ this .resultAlwaysValid = resultAlwaysValid ;
169+ return this ;
170+ }
171+
150172 @ SuppressWarnings ({"unchecked" , "rawtypes" })
151173 @ Override
152174 public AnvilWindow build (Player viewer ) {
@@ -156,6 +178,7 @@ public AnvilWindow build(Player viewer) {
156178 (AbstractGui ) upperGuiSupplier .get (),
157179 supplyLowerGui (viewer ),
158180 textFieldAlwaysEnabled ,
181+ resultAlwaysValid ,
159182 closeable
160183 );
161184
0 commit comments