mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix anvils
This commit is contained in:
parent
db0e506e3b
commit
ba0b898da9
2 changed files with 29 additions and 14 deletions
|
@ -131,22 +131,18 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||
InventoryAction anvilResult = null;
|
||||
InventoryAction anvilInput = null;
|
||||
for (InventoryAction action : packet.getActions()) {
|
||||
if (action.getSource().getContainerId() == ContainerId.ANVIL_RESULT) {
|
||||
if (action.getSource().getContainerId() == ContainerId.ANVIL_MATERIAL) {
|
||||
//useless packet
|
||||
return;
|
||||
} else if (action.getSource().getContainerId() == ContainerId.ANVIL_RESULT) {
|
||||
anvilResult = action;
|
||||
} else if (action.getSource().getContainerId() == ContainerId.CONTAINER_INPUT) {
|
||||
} else if (translator.bedrockSlotToJava(action) == 0) {
|
||||
anvilInput = action;
|
||||
}
|
||||
}
|
||||
ItemData itemName = null;
|
||||
if (anvilResult != null) {
|
||||
itemName = anvilResult.getFromItem();
|
||||
actions = new ArrayList<>(2);
|
||||
for (InventoryAction action : packet.getActions()) { //packet sent by client when grabbing anvil output needs useless actions stripped
|
||||
if (!(action.getSource().getContainerId() == ContainerId.CONTAINER_INPUT ||
|
||||
action.getSource().getContainerId() == ContainerId.ANVIL_MATERIAL)) {
|
||||
actions.add(action);
|
||||
}
|
||||
}
|
||||
} else if (anvilInput != null) {
|
||||
itemName = anvilInput.getToItem();
|
||||
}
|
||||
|
@ -161,6 +157,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||
ClientRenameItemPacket renameItemPacket = new ClientRenameItemPacket(rename);
|
||||
session.getDownstream().getSession().send(renameItemPacket);
|
||||
}
|
||||
if (anvilResult != null) {
|
||||
//client will send another packet to grab anvil output
|
||||
//this packet was only used to send rename packet
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.size() == 2) {
|
||||
|
@ -494,7 +495,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||
ItemStack clickedItem = inventory.getItem(action.slot);
|
||||
short actionId = (short) inventory.getTransactionId().getAndIncrement();
|
||||
boolean craftingOutput = (inventory.getId() == 0 || inventory.getWindowType() == WindowType.CRAFTING) && action.slot == 0;
|
||||
if (craftingOutput)
|
||||
if (craftingOutput || translator.isOutputSlot(action.slot))
|
||||
refresh = true;
|
||||
ClientWindowActionPacket clickPacket = new ClientWindowActionPacket(inventory.getId(),
|
||||
actionId, action.slot, !planIter.hasNext() && refresh ? refreshItem : fixStack(clickedItem),
|
||||
|
|
|
@ -28,6 +28,14 @@ package org.geysermc.connector.network.translators.inventory;
|
|||
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
||||
import com.nukkitx.protocol.bedrock.data.ContainerType;
|
||||
import com.nukkitx.protocol.bedrock.data.InventoryAction;
|
||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
||||
public AnvilInventoryTranslator() {
|
||||
|
@ -45,13 +53,19 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
|||
return slotnum + this.size + 27;
|
||||
}
|
||||
} else {
|
||||
if (action.getSource().getContainerId() == ContainerId.ANVIL_RESULT) {
|
||||
if (action.getSource().getContainerId() == ContainerId.CURSOR) {
|
||||
switch (slotnum) {
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return 1;
|
||||
case 50:
|
||||
return 2;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
return slotnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputSlot(int slot) {
|
||||
|
|
Loading…
Reference in a new issue