Don't confirm if the inventory is the same type

This commit is contained in:
Camotoy 2021-03-04 14:04:11 -05:00
parent ca3f9550dd
commit 16e8dd0df1
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
22 changed files with 53 additions and 33 deletions

View file

@ -25,11 +25,13 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
/**
* Used to determine if rename packets should be sent.
*/
public class AnvilContainer extends Container {
public AnvilContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public AnvilContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
}

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
import lombok.Setter;
@ -34,7 +35,7 @@ public class BeaconContainer extends Container {
private int primaryId;
private int secondaryId;
public BeaconContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public BeaconContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
}

View file

@ -25,8 +25,10 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
public class CartographyContainer extends Container {
public CartographyContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public CartographyContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
}

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
import lombok.NonNull;
import org.geysermc.connector.network.session.GeyserSession;
@ -43,8 +44,8 @@ public class Container extends Inventory {
*/
private boolean isUsingRealBlock = false;
public Container(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size);
public Container(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType);
this.playerInventory = playerInventory;
this.containerSize = this.size + InventoryTranslator.PLAYER_INVENTORY_SIZE;
}

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import com.nukkitx.protocol.bedrock.data.inventory.EnchantOptionData;
import lombok.Getter;
@ -40,8 +41,8 @@ public class EnchantingContainer extends Container {
@Getter
private final GeyserEnchantOption[] geyserEnchantOptions;
public EnchantingContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public EnchantingContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
enchantOptions = new EnchantOptionData[3];
geyserEnchantOptions = new GeyserEnchantOption[3];

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
public class Generic3X3Container extends Container {
@ -34,8 +35,8 @@ public class Generic3X3Container extends Container {
@Getter
private boolean isDropper = false;
public Generic3X3Container(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public Generic3X3Container(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
@Override

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import com.nukkitx.math.vector.Vector3i;
import lombok.Getter;
import lombok.NonNull;
@ -41,6 +42,12 @@ public class Inventory {
@Getter
protected final int size;
/**
* Used for smooth transitions between two windows of the same type.
*/
@Getter
protected final WindowType windowType;
@Getter
@Setter
protected String title;
@ -65,14 +72,15 @@ public class Inventory {
@Setter
private boolean pending = false;
protected Inventory(int id, int size) {
this("Inventory", id, size);
protected Inventory(int id, int size, WindowType windowType) {
this("Inventory", id, size, windowType);
}
protected Inventory(String title, int id, int size) {
protected Inventory(String title, int id, int size, WindowType windowType) {
this.title = title;
this.id = id;
this.size = size;
this.windowType = windowType;
this.items = new GeyserItemStack[size];
Arrays.fill(items, GeyserItemStack.EMPTY);
}

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.NbtMap;
import lombok.Getter;
@ -38,7 +39,7 @@ public class LecternContainer extends Container {
@Getter @Setter
private Vector3i position;
public LecternContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public LecternContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
}

View file

@ -26,6 +26,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.entity.Entity;
@ -36,7 +37,7 @@ public class MerchantContainer extends Container {
private Entity villager;
private VillagerTrade[] villagerTrades;
public MerchantContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public MerchantContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
}

View file

@ -45,7 +45,7 @@ public class PlayerInventory extends Inventory {
private GeyserItemStack cursor = GeyserItemStack.EMPTY;
public PlayerInventory() {
super(0, 46);
super(0, 46, null);
heldItemSlot = 0;
}

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.inventory;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
@ -38,8 +39,8 @@ public class StonecutterContainer extends Container {
@Setter
private int stonecutterButton = -1;
public StonecutterContainer(String title, int id, int size, PlayerInventory playerInventory) {
super(title, id, size, playerInventory);
public StonecutterContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) {
super(title, id, size, windowType, playerInventory);
}
@Override

View file

@ -139,6 +139,6 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new AnvilContainer(name, windowId, this.size, playerInventory);
return new AnvilContainer(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -96,6 +96,6 @@ public abstract class BaseInventoryTranslator extends InventoryTranslator {
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new Container(name, windowId, this.size, playerInventory);
return new Container(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -127,6 +127,6 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new BeaconContainer(name, windowId, this.size, playerInventory);
return new BeaconContainer(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -98,6 +98,6 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new CartographyContainer(name, windowId, this.size, playerInventory);
return new CartographyContainer(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -164,7 +164,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new EnchantingContainer(name, windowId, this.size, playerInventory);
return new EnchantingContainer(name, windowId, this.size, windowType, playerInventory);
}
/**

View file

@ -47,7 +47,7 @@ public class Generic3X3InventoryTranslator extends AbstractBlockInventoryTransla
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new Generic3X3Container(name, windowId, this.size, playerInventory);
return new Generic3X3Container(name, windowId, this.size, windowType, playerInventory);
}
@Override

View file

@ -151,7 +151,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new LecternContainer(name, windowId, this.size, playerInventory);
return new LecternContainer(name, windowId, this.size, windowType, playerInventory);
}
public static NbtMapBuilder getBaseLecternTag(int x, int y, int z, int totalPages) {

View file

@ -157,6 +157,6 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new MerchantContainer(name, windowId, this.size, playerInventory);
return new MerchantContainer(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -133,6 +133,6 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
@Override
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
return new StonecutterContainer(name, windowId, this.size, playerInventory);
return new StonecutterContainer(name, windowId, this.size, windowType, playerInventory);
}
}

View file

@ -132,6 +132,6 @@ public class JavaOpenHorseWindowTranslator extends PacketTranslator<ServerOpenHo
session.sendUpstreamPacket(updateEquipPacket);
session.setInventoryTranslator(inventoryTranslator);
InventoryUtils.openInventory(session, new Container(entity.getMetadata().getString(EntityData.NAMETAG), packet.getWindowId(), packet.getNumberOfSlots(), session.getPlayerInventory()));
InventoryUtils.openInventory(session, new Container(entity.getMetadata().getString(EntityData.NAMETAG), packet.getWindowId(), packet.getNumberOfSlots(), null, session.getPlayerInventory()));
}
}

View file

@ -64,7 +64,8 @@ public class JavaOpenWindowTranslator extends PacketTranslator<ServerOpenWindowP
Inventory newInventory = newTranslator.createInventory(name, packet.getWindowId(), packet.getType(), session.getPlayerInventory());
if (openInventory != null) {
// Sometimes the server can double-open an inventory with the same ID - don't confirm in that instance.
InventoryUtils.closeInventory(session, openInventory.getId(), openInventory.getId() != packet.getWindowId());
// If the window type is the same, don't confirm; in rare cases, inventories can do funny things where it keeps the same window type up but change the contents.
InventoryUtils.closeInventory(session, openInventory.getId(), (openInventory.getId() != packet.getWindowId() && openInventory.getWindowType() != packet.getType()));
}
session.setInventoryTranslator(newTranslator);