Temporary fix with inventory held click

This commit is contained in:
Felix Cravic 2020-05-27 17:56:29 +02:00
parent c363b715ca
commit f97328a3bd
5 changed files with 26 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo; import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean; import java.lang.management.ThreadMXBean;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static net.minestom.server.MinecraftServer.*; import static net.minestom.server.MinecraftServer.*;
@ -27,7 +28,7 @@ public class BenchmarkManager {
private Map<Long, Long> lastUserTimeMap = new HashMap<>(); private Map<Long, Long> lastUserTimeMap = new HashMap<>();
private Map<Long, Long> lastBlockedMap = new HashMap<>(); private Map<Long, Long> lastBlockedMap = new HashMap<>();
private Map<String, ThreadResult> resultMap = new HashMap<>(); private Map<String, ThreadResult> resultMap = new ConcurrentHashMap<>();
private boolean enabled = false; private boolean enabled = false;
private volatile boolean stop = false; private volatile boolean stop = false;

View File

@ -333,21 +333,22 @@ public class Chunk implements Viewable {
} }
public ChunkDataPacket getFreshFullDataPacket() { public ChunkDataPacket getFreshFullDataPacket() {
ChunkDataPacket fullDataPacket = new ChunkDataPacket(); ChunkDataPacket fullDataPacket = getFreshPacket();
fullDataPacket.fullChunk = true; fullDataPacket.fullChunk = true;
fullDataPacket.biomes = biomes.clone();
fullDataPacket.chunkX = chunkX;
fullDataPacket.chunkZ = chunkZ;
fullDataPacket.blocksId = blocksId.clone();
fullDataPacket.customBlocksId = customBlocksId.clone();
fullDataPacket.blockEntities = new CopyOnWriteArraySet<>(blockEntities);
fullDataPacket.blocksData = new Int2ObjectOpenHashMap<>(blocksData);
return fullDataPacket; return fullDataPacket;
} }
public ChunkDataPacket getFreshPartialDataPacket() { public ChunkDataPacket getFreshPartialDataPacket() {
ChunkDataPacket fullDataPacket = new ChunkDataPacket(); ChunkDataPacket fullDataPacket = getFreshPacket();
fullDataPacket.fullChunk = false; fullDataPacket.fullChunk = false;
return fullDataPacket;
}
/**
* @return a {@link ChunkDataPacket} containing a copy this chunk data
*/
private ChunkDataPacket getFreshPacket() {
ChunkDataPacket fullDataPacket = new ChunkDataPacket();
fullDataPacket.biomes = biomes.clone(); fullDataPacket.biomes = biomes.clone();
fullDataPacket.chunkX = chunkX; fullDataPacket.chunkX = chunkX;
fullDataPacket.chunkZ = chunkZ; fullDataPacket.chunkZ = chunkZ;

View File

@ -328,6 +328,9 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
if (!clickResult.isCancel()) if (!clickResult.isCancel())
callClickEvent(player, this, slot, ClickType.CHANGE_HELD, clicked, getCursorItem(player)); callClickEvent(player, this, slot, ClickType.CHANGE_HELD, clicked, getCursorItem(player));
// Weird synchronization issue when omitted
updateFromClick(clickResult, player);
return !clickResult.isCancel(); return !clickResult.isCancel();
} }

View File

@ -219,14 +219,14 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
this.items[slot] = itemStack; this.items[slot] = itemStack;
// Refresh slot
update();
//refreshSlot(slot); seems to break things concerning +64 stacks
// Sync equipment // Sync equipment
if (equipmentSlot != null) { if (equipmentSlot != null) {
player.syncEquipment(equipmentSlot); player.syncEquipment(equipmentSlot);
} }
// Refresh slot
update();
//refreshSlot(slot); seems to break things concerning +64 stacks
} }
} }
@ -365,8 +365,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
InventoryClickResult clickResult = clickProcessor.changeHeld(null, player, slot, key, clicked, heldItem); InventoryClickResult clickResult = clickProcessor.changeHeld(null, player, slot, key, clicked, heldItem);
if (clickResult.doRefresh()) if (clickResult.doRefresh()) {
sendSlotRefresh((short) slot, clicked); sendSlotRefresh((short) slot, clicked);
}
setItemStack(slot, OFFSET, clickResult.getClicked()); setItemStack(slot, OFFSET, clickResult.getClicked());
setItemStack(key, clickResult.getCursor()); setItemStack(key, clickResult.getCursor());
@ -374,6 +375,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
if (!clickResult.isCancel()) if (!clickResult.isCancel())
callClickEvent(player, null, slot, ClickType.CHANGE_HELD, clicked, getCursorItem()); callClickEvent(player, null, slot, ClickType.CHANGE_HELD, clicked, getCursorItem());
// Weird synchronization issue when omitted
update();
return !clickResult.isCancel(); return !clickResult.isCancel();
} }

View File

@ -145,8 +145,8 @@ public class InventoryClickProcessor {
if (clicked.isAir()) { if (clicked.isAir()) {
// Set held item [key] to slot // Set held item [key] to slot
resultClicked = ItemStack.getAirItem(); resultClicked = cursor.clone();
resultHeld = clicked.clone(); resultHeld = ItemStack.getAirItem();
} else { } else {
if (cursor.isAir()) { if (cursor.isAir()) {
// if held item [key] is air then set clicked to held // if held item [key] is air then set clicked to held