mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 20:21:53 +01:00
Update
This commit is contained in:
parent
a4ade2a806
commit
212fceb142
@ -24,15 +24,15 @@ dependencies {
|
|||||||
apt lombokDependency
|
apt lombokDependency
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.github.jhg023/SimpleNet
|
// https://mvnrepository.com/artifact/com.github.jhg023/SimpleNet
|
||||||
compile group: 'com.github.jhg023', name: 'SimpleNet', version: '1.6.2'
|
implementation group: 'com.github.jhg023', name: 'SimpleNet', version: '1.6.2'
|
||||||
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
||||||
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
|
implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
|
||||||
|
|
||||||
compile 'com.github.Querz:NBT:4.1'
|
compile 'com.github.Querz:NBT:4.1'
|
||||||
implementation 'com.github.luben:zstd-jni:1.4.3-1'
|
implementation 'com.github.luben:zstd-jni:1.4.3-1'
|
||||||
implementation 'com.esotericsoftware:reflectasm:1.11.9'
|
implementation 'com.esotericsoftware:reflectasm:1.11.9'
|
||||||
implementation 'com.github.LynnOwens:starlite:9971b899f7'
|
implementation 'com.github.LynnOwens:starlite:9971b899f7'
|
||||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
MinecraftServer minecraftServer = MinecraftServer.init();
|
MinecraftServer minecraftServer = MinecraftServer.init();
|
||||||
|
|
||||||
PlayerInit.init();
|
|
||||||
|
|
||||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||||
blockManager.registerBlock(new StoneBlock());
|
blockManager.registerBlock(new StoneBlock());
|
||||||
blockManager.registerBlock(new UpdatableBlockDemo());
|
blockManager.registerBlock(new UpdatableBlockDemo());
|
||||||
|
|
||||||
|
PlayerInit.init();
|
||||||
|
|
||||||
minecraftServer.start("localhost", 55555);
|
minecraftServer.start("localhost", 55555);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class PlayerInit {
|
|||||||
//itemEntity.remove();
|
//itemEntity.remove();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
ItemStack item = new ItemStack(1, (byte) 4);
|
ItemStack item = new ItemStack(1, (byte) 43);
|
||||||
item.setDisplayName("LE NOM PUTAIN");
|
item.setDisplayName("LE NOM PUTAIN");
|
||||||
//item.getLore().add("lol le lore");
|
//item.getLore().add("lol le lore");
|
||||||
player.getInventory().addItemStack(item);
|
player.getInventory().addItemStack(item);
|
||||||
|
@ -186,11 +186,10 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
|
|
||||||
ItemStack resultCursor;
|
ItemStack resultCursor;
|
||||||
ItemStack resultClicked;
|
ItemStack resultClicked;
|
||||||
|
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||||
|
StackingRule clickedRule = clicked.getStackingRule();
|
||||||
|
|
||||||
if (cursorItem.isSimilar(clicked)) {
|
if (cursorRule.canBeStacked(cursorItem, clicked)) {
|
||||||
// They should have the same stacking rule
|
|
||||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
|
||||||
StackingRule clickedRule = clicked.getStackingRule();
|
|
||||||
|
|
||||||
resultCursor = cursorItem.clone();
|
resultCursor = cursorItem.clone();
|
||||||
resultClicked = clicked.clone();
|
resultClicked = clicked.clone();
|
||||||
@ -257,9 +256,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
ItemStack resultCursor;
|
ItemStack resultCursor;
|
||||||
ItemStack resultClicked;
|
ItemStack resultClicked;
|
||||||
|
|
||||||
if (cursorItem.isSimilar(clicked)) {
|
if (cursorRule.canBeStacked(cursorItem, clicked)) {
|
||||||
// They should have the same stacking rule
|
|
||||||
|
|
||||||
resultClicked = clicked.clone();
|
resultClicked = clicked.clone();
|
||||||
int amount = clickedRule.getAmount(clicked) + 1;
|
int amount = clickedRule.getAmount(clicked) + 1;
|
||||||
|
|
||||||
@ -346,7 +343,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
if (!isInWindow) {
|
if (!isInWindow) {
|
||||||
for (int i = 0; i < itemStacks.length; i++) {
|
for (int i = 0; i < itemStacks.length; i++) {
|
||||||
ItemStack item = itemStacks[i];
|
ItemStack item = itemStacks[i];
|
||||||
if (item.isSimilar(clicked)) {
|
if (clickedRule.canBeStacked(clicked, item)) {
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
if (amount == maxSize)
|
if (amount == maxSize)
|
||||||
continue;
|
continue;
|
||||||
@ -378,7 +375,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
} else {
|
} else {
|
||||||
for (int i = 44; i >= 0; i--) { // Hotbar
|
for (int i = 44; i >= 0; i--) { // Hotbar
|
||||||
ItemStack item = playerInventory.getItemStack(i, offset);
|
ItemStack item = playerInventory.getItemStack(i, offset);
|
||||||
if (item.isSimilar(clicked)) {
|
if (clickedRule.canBeStacked(clicked, item)) {
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
if (amount == maxSize)
|
if (amount == maxSize)
|
||||||
continue;
|
continue;
|
||||||
@ -487,12 +484,17 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dragging(Player player, int slot, int button) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doubleClick(Player player, int slot) {
|
public void doubleClick(Player player, int slot) {
|
||||||
PlayerInventory playerInventory = player.getInventory();
|
PlayerInventory playerInventory = player.getInventory();
|
||||||
boolean isInWindow = isClickInWindow(slot);
|
boolean isInWindow = isClickInWindow(slot);
|
||||||
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset); // Isn't used in the algorithm
|
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset); // Isn't used in the algorithm
|
||||||
ItemStack cursorItem = getCursorItem(player).clone();
|
ItemStack cursorItem = getCursorItem(player);
|
||||||
|
|
||||||
// Start condition
|
// Start condition
|
||||||
InventoryCondition inventoryCondition = getInventoryCondition();
|
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||||
@ -535,7 +537,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
if (amount == maxSize)
|
if (amount == maxSize)
|
||||||
break;
|
break;
|
||||||
ItemStack item = itemStacks[i];
|
ItemStack item = itemStacks[i];
|
||||||
if (cursorItem.isSimilar(item)) {
|
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||||
int totalAmount = amount + item.getAmount();
|
int totalAmount = amount + item.getAmount();
|
||||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||||
@ -556,7 +558,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
if (amount == maxSize)
|
if (amount == maxSize)
|
||||||
break;
|
break;
|
||||||
ItemStack item = playerInventory.getItemStack(i);
|
ItemStack item = playerInventory.getItemStack(i);
|
||||||
if (cursorItem.isSimilar(item)) {
|
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||||
int totalAmount = amount + item.getAmount();
|
int totalAmount = amount + item.getAmount();
|
||||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||||
@ -576,7 +578,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
if (amount == maxSize)
|
if (amount == maxSize)
|
||||||
break;
|
break;
|
||||||
ItemStack item = playerInventory.getItemStack(i);
|
ItemStack item = playerInventory.getItemStack(i);
|
||||||
if (cursorItem.isSimilar(item)) {
|
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||||
int totalAmount = amount + item.getAmount();
|
int totalAmount = amount + item.getAmount();
|
||||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||||
|
@ -18,6 +18,8 @@ public interface InventoryClickHandler {
|
|||||||
|
|
||||||
void dropItemStack(Player player, int slot);
|
void dropItemStack(Player player, int slot);
|
||||||
|
|
||||||
|
void dragging(Player player, int slot, int button);
|
||||||
|
|
||||||
void doubleClick(Player player, int slot);
|
void doubleClick(Player player, int slot);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import fr.themode.minestom.net.packet.server.play.SetSlotPacket;
|
|||||||
import fr.themode.minestom.net.packet.server.play.WindowItemsPacket;
|
import fr.themode.minestom.net.packet.server.play.WindowItemsPacket;
|
||||||
import fr.themode.minestom.net.player.PlayerConnection;
|
import fr.themode.minestom.net.player.PlayerConnection;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
|
|
||||||
public class PlayerInventory implements InventoryModifier, InventoryClickHandler {
|
public class PlayerInventory implements InventoryModifier, InventoryClickHandler {
|
||||||
|
|
||||||
@ -286,6 +286,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
return windowItemsPacket;
|
return windowItemsPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<Player, Set<Integer>> leftDraggingMap = new HashMap<>();
|
||||||
|
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leftClick(Player player, int slot) {
|
public void leftClick(Player player, int slot) {
|
||||||
ItemStack cursorItem = getCursorItem();
|
ItemStack cursorItem = getCursorItem();
|
||||||
@ -323,7 +326,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||||
StackingRule clickedRule = clicked.getStackingRule();
|
StackingRule clickedRule = clicked.getStackingRule();
|
||||||
|
|
||||||
if (cursorItem.isSimilar(clicked)) {
|
if (clickedRule.canBeStacked(clicked, cursorItem)) {
|
||||||
resultCursor = cursorItem.clone();
|
resultCursor = cursorItem.clone();
|
||||||
resultClicked = clicked.clone();
|
resultClicked = clicked.clone();
|
||||||
int totalAmount = cursorItem.getAmount() + clicked.getAmount();
|
int totalAmount = cursorItem.getAmount() + clicked.getAmount();
|
||||||
@ -365,12 +368,6 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
}
|
}
|
||||||
// End condition
|
// End condition
|
||||||
|
|
||||||
/*if (!cursorItem.isAir()) {
|
|
||||||
if (slot == 0 || slot == 6 || slot == 7 || slot == 8) {
|
|
||||||
return; // Disable putting item on CRAFTING_RESULT and on helmet/chestplate/leggings/boots slots
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (cursorItem.isAir() && clicked.isAir())
|
if (cursorItem.isAir() && clicked.isAir())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -380,7 +377,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||||
StackingRule clickedRule = clicked.getStackingRule();
|
StackingRule clickedRule = clicked.getStackingRule();
|
||||||
|
|
||||||
if (cursorItem.isSimilar(clicked)) {
|
if (clickedRule.canBeStacked(clicked, cursorItem)) {
|
||||||
resultClicked = clicked.clone();
|
resultClicked = clicked.clone();
|
||||||
int amount = clicked.getAmount() + 1;
|
int amount = clicked.getAmount() + 1;
|
||||||
if (!clickedRule.canApply(resultClicked, amount)) {
|
if (!clickedRule.canApply(resultClicked, amount)) {
|
||||||
@ -391,22 +388,21 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
resultClicked = clickedRule.apply(resultClicked, amount);
|
resultClicked = clickedRule.apply(resultClicked, amount);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO complete replace setAmount for StackingRule
|
|
||||||
if (cursorItem.isAir()) {
|
if (cursorItem.isAir()) {
|
||||||
int amount = (int) Math.ceil((double) clicked.getAmount() / 2d);
|
int amount = (int) Math.ceil((double) clicked.getAmount() / 2d);
|
||||||
resultCursor = clicked.clone();
|
resultCursor = clicked.clone();
|
||||||
resultCursor.setAmount((byte) amount);
|
resultCursor = cursorRule.apply(resultCursor, amount);
|
||||||
|
|
||||||
resultClicked = clicked.clone();
|
resultClicked = clicked.clone();
|
||||||
resultClicked.setAmount((byte) (clicked.getAmount() / 2));
|
resultClicked = clickedRule.apply(resultClicked, clicked.getAmount() / 2);
|
||||||
} else {
|
} else {
|
||||||
if (clicked.isAir()) {
|
if (clicked.isAir()) {
|
||||||
int amount = cursorItem.getAmount();
|
int amount = cursorItem.getAmount();
|
||||||
resultCursor = cursorItem.clone();
|
resultCursor = cursorItem.clone();
|
||||||
resultCursor.setAmount((byte) (amount - 1));
|
resultCursor = cursorRule.apply(resultCursor, amount - 1);
|
||||||
if (resultCursor.getAmount() < 1)
|
|
||||||
resultCursor = ItemStack.AIR_ITEM;
|
|
||||||
resultClicked = cursorItem.clone();
|
resultClicked = cursorItem.clone();
|
||||||
resultClicked.setAmount((byte) 1);
|
resultClicked = clickedRule.apply(resultClicked, 1);
|
||||||
} else {
|
} else {
|
||||||
resultCursor = clicked.clone();
|
resultCursor = clicked.clone();
|
||||||
resultClicked = cursorItem.clone();
|
resultClicked = cursorItem.clone();
|
||||||
@ -418,33 +414,72 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
setCursorItem(resultCursor);
|
setCursorItem(resultCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void middleClick(Player player, int slot) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropOne(Player player, int slot) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropItemStack(Player player, int slot) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shiftClick(Player player, int slot) {
|
public void shiftClick(Player player, int slot) {
|
||||||
/*ItemStack clicked = getItemStack(slot, OFFSET);
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
ItemStack cursorItem = getCursorItem(); // Not used
|
||||||
|
|
||||||
|
// Start condition
|
||||||
|
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||||
|
if (inventoryCondition != null) {
|
||||||
|
InventoryConditionResult result = inventoryCondition.accept(slot, null, clicked, cursorItem);
|
||||||
|
cursorItem = result.getCursorItem();
|
||||||
|
clicked = result.getClickedItem();
|
||||||
|
|
||||||
|
if (result.isCancel()) {
|
||||||
|
setItemStack(slot, OFFSET, clicked);
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
// Refresh client slot
|
||||||
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End condition
|
||||||
|
|
||||||
if (clicked.isAir())
|
if (clicked.isAir())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
StackingRule clickedRule = clicked.getStackingRule();
|
||||||
|
|
||||||
ItemStack resultClicked = clicked.clone();
|
ItemStack resultClicked = clicked.clone();
|
||||||
boolean filled = false;
|
boolean filled = false;
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
int index = i < 9 ? i + 9 : i - 9;
|
int index = i < 9 ? i + 9 : i - 9;
|
||||||
ItemStack item = items[index];
|
ItemStack item = items[index];
|
||||||
|
StackingRule itemRule = item.getStackingRule();
|
||||||
if (item.isSimilar(clicked)) {
|
if (item.isSimilar(clicked)) {
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
if (amount == ITEM_MAX_SIZE)
|
if (!clickedRule.canApply(clicked, amount + 1))
|
||||||
continue;
|
continue;
|
||||||
int totalAmount = resultClicked.getAmount() + amount;
|
int totalAmount = resultClicked.getAmount() + amount;
|
||||||
if (totalAmount > ITEM_MAX_SIZE) {
|
if (!clickedRule.canApply(clicked, totalAmount)) {
|
||||||
item.setAmount((byte) ITEM_MAX_SIZE);
|
item = itemRule.apply(item, itemRule.getMaxSize());
|
||||||
setItemStack(index, item);
|
setItemStack(index, OFFSET, item);
|
||||||
resultClicked.setAmount((byte) (totalAmount - ITEM_MAX_SIZE));
|
|
||||||
|
resultClicked = clickedRule.apply(resultClicked, totalAmount - clickedRule.getMaxSize());
|
||||||
filled = false;
|
filled = false;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
resultClicked.setAmount((byte) totalAmount);
|
resultClicked = clickedRule.apply(resultClicked, totalAmount);
|
||||||
setItemStack(index, resultClicked);
|
setItemStack(index, resultClicked);
|
||||||
setItemStack(slot, OFFSET, ItemStack.AIR_ITEM);
|
|
||||||
|
item = itemRule.apply(item, 0);
|
||||||
|
setItemStack(slot, OFFSET, item);
|
||||||
filled = true;
|
filled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -458,7 +493,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
}
|
}
|
||||||
if (!filled) {
|
if (!filled) {
|
||||||
setItemStack(slot, OFFSET, resultClicked);
|
setItemStack(slot, OFFSET, resultClicked);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -466,9 +501,27 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
if (!getCursorItem().isAir())
|
if (!getCursorItem().isAir())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ItemStack cursorItem = getCursorItem();
|
||||||
ItemStack heldItem = getItemStack(key);
|
ItemStack heldItem = getItemStack(key);
|
||||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
|
// Start condition
|
||||||
|
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||||
|
if (inventoryCondition != null) {
|
||||||
|
InventoryConditionResult result = inventoryCondition.accept(slot, null, clicked, cursorItem);
|
||||||
|
cursorItem = result.getCursorItem();
|
||||||
|
clicked = result.getClickedItem();
|
||||||
|
|
||||||
|
if (result.isCancel()) {
|
||||||
|
setItemStack(slot, OFFSET, clicked);
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
// Refresh client slot
|
||||||
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End condition
|
||||||
|
|
||||||
ItemStack resultClicked;
|
ItemStack resultClicked;
|
||||||
ItemStack resultHeld;
|
ItemStack resultHeld;
|
||||||
|
|
||||||
@ -493,52 +546,152 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void middleClick(Player player, int slot) {
|
public void dragging(Player player, int slot, int button) {
|
||||||
|
ItemStack cursorItem = getCursorItem();
|
||||||
|
ItemStack clicked = null;
|
||||||
|
if (slot != -999)
|
||||||
|
clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
}
|
// Start condition
|
||||||
|
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||||
|
if (inventoryCondition != null) {
|
||||||
|
InventoryConditionResult result = inventoryCondition.accept(slot, null, clicked, cursorItem);
|
||||||
|
cursorItem = result.getCursorItem();
|
||||||
|
clicked = result.getClickedItem();
|
||||||
|
|
||||||
@Override
|
if (result.isCancel()) {
|
||||||
public void dropOne(Player player, int slot) {
|
setItemStack(slot, OFFSET, clicked);
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
// Refresh client slot
|
||||||
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End condition
|
||||||
|
|
||||||
}
|
StackingRule stackingRule = cursorItem.getStackingRule();
|
||||||
|
|
||||||
@Override
|
if (slot == -999) {
|
||||||
public void dropItemStack(Player player, int slot) {
|
// Start or end left/right drag
|
||||||
|
if (button == 0) {
|
||||||
|
// Start left
|
||||||
|
this.leftDraggingMap.put(player, new HashSet<>());
|
||||||
|
} else if (button == 4) {
|
||||||
|
// Start right
|
||||||
|
this.rightDraggingMap.put(player, new HashSet<>());
|
||||||
|
} else if (button == 2) {
|
||||||
|
// End left
|
||||||
|
if (!leftDraggingMap.containsKey(player))
|
||||||
|
return;
|
||||||
|
Set<Integer> slots = leftDraggingMap.get(player);
|
||||||
|
int size = slots.size();
|
||||||
|
int cursorAmount = stackingRule.getAmount(cursorItem);
|
||||||
|
if (size > cursorAmount)
|
||||||
|
return;
|
||||||
|
int slotSize = (int) ((float) cursorAmount / (float) size);
|
||||||
|
|
||||||
|
for (Integer s : slots) {
|
||||||
|
ItemStack draggedItem = cursorItem.clone();
|
||||||
|
draggedItem = stackingRule.apply(draggedItem, slotSize);
|
||||||
|
setItemStack(s, OFFSET, draggedItem);
|
||||||
|
}
|
||||||
|
cursorItem = stackingRule.apply(cursorItem, cursorAmount - (slotSize * size));
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
|
||||||
|
leftDraggingMap.remove(player);
|
||||||
|
} else if (button == 6) {
|
||||||
|
// End right
|
||||||
|
if (!rightDraggingMap.containsKey(player))
|
||||||
|
return;
|
||||||
|
Set<Integer> slots = rightDraggingMap.get(player);
|
||||||
|
int size = slots.size();
|
||||||
|
int cursorAmount = stackingRule.getAmount(cursorItem);
|
||||||
|
if (size > cursorAmount)
|
||||||
|
return;
|
||||||
|
for (Integer s : slots) {
|
||||||
|
ItemStack draggedItem = cursorItem.clone();
|
||||||
|
draggedItem = stackingRule.apply(draggedItem, 1);
|
||||||
|
setItemStack(s, OFFSET, draggedItem);
|
||||||
|
}
|
||||||
|
cursorItem = stackingRule.apply(cursorItem, cursorAmount - size);
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
|
||||||
|
rightDraggingMap.remove(player);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add slot
|
||||||
|
if (button == 1) {
|
||||||
|
// Add left slot
|
||||||
|
if (!leftDraggingMap.containsKey(player))
|
||||||
|
return;
|
||||||
|
leftDraggingMap.get(player).add(slot);
|
||||||
|
|
||||||
|
} else if (button == 5) {
|
||||||
|
// Add right slot
|
||||||
|
if (!rightDraggingMap.containsKey(player))
|
||||||
|
return;
|
||||||
|
rightDraggingMap.get(player).add(slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doubleClick(Player player, int slot) {
|
public void doubleClick(Player player, int slot) {
|
||||||
/*ItemStack cursorItem = getCursorItem().clone();
|
ItemStack cursorItem = getCursorItem();
|
||||||
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
|
// Start condition
|
||||||
|
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||||
|
if (inventoryCondition != null) {
|
||||||
|
InventoryConditionResult result = inventoryCondition.accept(slot, null, clicked, cursorItem);
|
||||||
|
cursorItem = result.getCursorItem();
|
||||||
|
clicked = result.getClickedItem();
|
||||||
|
|
||||||
|
if (result.isCancel()) {
|
||||||
|
setItemStack(slot, OFFSET, clicked);
|
||||||
|
setCursorItem(cursorItem);
|
||||||
|
// Refresh client slot
|
||||||
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End condition
|
||||||
|
|
||||||
if (cursorItem.isAir())
|
if (cursorItem.isAir())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||||
int amount = cursorItem.getAmount();
|
int amount = cursorItem.getAmount();
|
||||||
|
|
||||||
if (amount == ITEM_MAX_SIZE)
|
if (!cursorRule.canApply(cursorItem, amount + 1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
int index = i < 9 ? i + 9 : i - 9;
|
int index = i < 9 ? i + 9 : i - 9;
|
||||||
if (index == slot)
|
if (index == slot)
|
||||||
continue;
|
continue;
|
||||||
if (amount == ITEM_MAX_SIZE)
|
|
||||||
break;
|
|
||||||
ItemStack item = items[index];
|
ItemStack item = items[index];
|
||||||
if (cursorItem.isSimilar(item)) {
|
StackingRule itemRule = item.getStackingRule();
|
||||||
|
if (!cursorRule.canApply(cursorItem, amount + 1))
|
||||||
|
break;
|
||||||
|
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||||
int totalAmount = amount + item.getAmount();
|
int totalAmount = amount + item.getAmount();
|
||||||
if (totalAmount > ITEM_MAX_SIZE) {
|
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||||
cursorItem.setAmount((byte) ITEM_MAX_SIZE);
|
cursorItem = cursorRule.apply(cursorItem, cursorRule.getMaxSize());
|
||||||
item.setAmount((byte) (totalAmount - ITEM_MAX_SIZE));
|
|
||||||
|
item = itemRule.apply(item, totalAmount - itemRule.getMaxSize());
|
||||||
setItemStack(index, item);
|
setItemStack(index, item);
|
||||||
} else {
|
} else {
|
||||||
cursorItem.setAmount((byte) totalAmount);
|
cursorItem = cursorRule.apply(cursorItem, totalAmount);
|
||||||
setItemStack(index, ItemStack.AIR_ITEM);
|
item = itemRule.apply(item, 0);
|
||||||
|
setItemStack(index, item);
|
||||||
}
|
}
|
||||||
amount = cursorItem.getAmount();
|
amount = cursorItem.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorItem(cursorItem);*/
|
setCursorItem(cursorItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,12 @@ import java.util.ArrayList;
|
|||||||
public class ItemStack implements DataContainer {
|
public class ItemStack implements DataContainer {
|
||||||
|
|
||||||
public static final ItemStack AIR_ITEM = new ItemStack(0, (byte) 1);
|
public static final ItemStack AIR_ITEM = new ItemStack(0, (byte) 1);
|
||||||
private static StackingRule defaultStackingRule = new VanillaStackingRule(64);
|
private static StackingRule defaultStackingRule;
|
||||||
|
|
||||||
|
{
|
||||||
|
if (defaultStackingRule == null)
|
||||||
|
defaultStackingRule = new VanillaStackingRule(64);
|
||||||
|
}
|
||||||
|
|
||||||
private Material material;
|
private Material material;
|
||||||
private byte amount;
|
private byte amount;
|
||||||
|
@ -8,6 +8,8 @@ public abstract class StackingRule {
|
|||||||
this.maxSize = maxSize;
|
this.maxSize = maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean canBeStacked(ItemStack item1, ItemStack item2);
|
||||||
|
|
||||||
public abstract boolean canApply(ItemStack item, int newAmount);
|
public abstract boolean canApply(ItemStack item, int newAmount);
|
||||||
|
|
||||||
public abstract ItemStack apply(ItemStack item, int newAmount);
|
public abstract ItemStack apply(ItemStack item, int newAmount);
|
||||||
|
@ -9,6 +9,11 @@ public class VanillaStackingRule extends StackingRule {
|
|||||||
super(maxSize);
|
super(maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeStacked(ItemStack item1, ItemStack item2) {
|
||||||
|
return item1.isSimilar(item2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canApply(ItemStack item, int newAmount) {
|
public boolean canApply(ItemStack item, int newAmount) {
|
||||||
return newAmount > 0 && newAmount <= getMaxSize();
|
return newAmount > 0 && newAmount <= getMaxSize();
|
||||||
|
@ -22,7 +22,7 @@ public class ChatMessageListener {
|
|||||||
|
|
||||||
TextObject usernameText = TextBuilder.of(String.format("<%s>", username))
|
TextObject usernameText = TextBuilder.of(String.format("<%s>", username))
|
||||||
.color(ChatColor.WHITE)
|
.color(ChatColor.WHITE)
|
||||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatColor.AQUA + "Its " + username))
|
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatColor.GRAY + "Its " + username))
|
||||||
.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
||||||
.append(" " + event.getMessage())
|
.append(" " + event.getMessage())
|
||||||
.build();
|
.build();
|
||||||
|
@ -58,6 +58,7 @@ public class WindowListener {
|
|||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Dragging
|
// Dragging
|
||||||
|
clickHandler.dragging(player, slot, button);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
clickHandler.doubleClick(player, slot);
|
clickHandler.doubleClick(player, slot);
|
||||||
|
@ -35,12 +35,14 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
|||||||
|
|
||||||
// TODO send encryption request OR directly login success
|
// TODO send encryption request OR directly login success
|
||||||
UUID playerUuid = UUID.randomUUID();//UUID.fromString("OfflinePlayer:" + username);
|
UUID playerUuid = UUID.randomUUID();//UUID.fromString("OfflinePlayer:" + username);
|
||||||
|
|
||||||
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);//new LoginSuccessPacket(uuids.get(username), username);
|
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);//new LoginSuccessPacket(uuids.get(username), username);
|
||||||
connection.sendPacket(successPacket);
|
connection.sendPacket(successPacket);
|
||||||
|
|
||||||
connection.setConnectionState(ConnectionState.PLAY);
|
connection.setConnectionState(ConnectionState.PLAY);
|
||||||
connectionManager.createPlayer(playerUuid, username, connection);
|
connectionManager.createPlayer(playerUuid, username, connection);
|
||||||
Player player = connectionManager.getPlayer(connection);
|
Player player = connectionManager.getPlayer(connection);
|
||||||
|
|
||||||
GameMode gameMode = GameMode.SURVIVAL;
|
GameMode gameMode = GameMode.SURVIVAL;
|
||||||
Dimension dimension = Dimension.OVERWORLD;
|
Dimension dimension = Dimension.OVERWORLD;
|
||||||
LevelType levelType = LevelType.DEFAULT;
|
LevelType levelType = LevelType.DEFAULT;
|
||||||
|
@ -15,10 +15,11 @@ public class PacketUtils {
|
|||||||
PacketWriter packetWriter = new PacketWriter(packet);
|
PacketWriter packetWriter = new PacketWriter(packet);
|
||||||
serverPacket.write(packetWriter);
|
serverPacket.write(packetWriter);
|
||||||
|
|
||||||
//System.out.println("WRITE PACKET: " + id + " " + serverPacket.getClass().getSimpleName());
|
|
||||||
|
|
||||||
callback.accept(packet.prepend(p -> {
|
callback.accept(packet.prepend(p -> {
|
||||||
Utils.writeVarInt(packet, packet.getSize());
|
int size = packet.getSize();
|
||||||
|
Utils.writeVarInt(packet, size);
|
||||||
|
|
||||||
|
System.out.println("WRITE PACKET: " + id + " " + serverPacket.getClass().getSimpleName() + " size: " + size);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user