mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 19:51:27 +01:00
Update
This commit is contained in:
parent
a4ade2a806
commit
212fceb142
@ -24,15 +24,15 @@ dependencies {
|
||||
apt lombokDependency
|
||||
|
||||
// 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
|
||||
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'
|
||||
implementation 'com.github.luben:zstd-jni:1.4.3-1'
|
||||
implementation 'com.esotericsoftware:reflectasm:1.11.9'
|
||||
implementation 'com.github.LynnOwens:starlite:9971b899f7'
|
||||
// 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) {
|
||||
MinecraftServer minecraftServer = MinecraftServer.init();
|
||||
|
||||
PlayerInit.init();
|
||||
|
||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||
blockManager.registerBlock(new StoneBlock());
|
||||
blockManager.registerBlock(new UpdatableBlockDemo());
|
||||
|
||||
PlayerInit.init();
|
||||
|
||||
minecraftServer.start("localhost", 55555);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class PlayerInit {
|
||||
//itemEntity.remove();
|
||||
}*/
|
||||
|
||||
ItemStack item = new ItemStack(1, (byte) 4);
|
||||
ItemStack item = new ItemStack(1, (byte) 43);
|
||||
item.setDisplayName("LE NOM PUTAIN");
|
||||
//item.getLore().add("lol le lore");
|
||||
player.getInventory().addItemStack(item);
|
||||
|
@ -186,11 +186,10 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
|
||||
ItemStack resultCursor;
|
||||
ItemStack resultClicked;
|
||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||
StackingRule clickedRule = clicked.getStackingRule();
|
||||
|
||||
if (cursorItem.isSimilar(clicked)) {
|
||||
// They should have the same stacking rule
|
||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||
StackingRule clickedRule = clicked.getStackingRule();
|
||||
if (cursorRule.canBeStacked(cursorItem, clicked)) {
|
||||
|
||||
resultCursor = cursorItem.clone();
|
||||
resultClicked = clicked.clone();
|
||||
@ -257,9 +256,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
ItemStack resultCursor;
|
||||
ItemStack resultClicked;
|
||||
|
||||
if (cursorItem.isSimilar(clicked)) {
|
||||
// They should have the same stacking rule
|
||||
|
||||
if (cursorRule.canBeStacked(cursorItem, clicked)) {
|
||||
resultClicked = clicked.clone();
|
||||
int amount = clickedRule.getAmount(clicked) + 1;
|
||||
|
||||
@ -346,7 +343,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
if (!isInWindow) {
|
||||
for (int i = 0; i < itemStacks.length; i++) {
|
||||
ItemStack item = itemStacks[i];
|
||||
if (item.isSimilar(clicked)) {
|
||||
if (clickedRule.canBeStacked(clicked, item)) {
|
||||
int amount = item.getAmount();
|
||||
if (amount == maxSize)
|
||||
continue;
|
||||
@ -378,7 +375,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
} else {
|
||||
for (int i = 44; i >= 0; i--) { // Hotbar
|
||||
ItemStack item = playerInventory.getItemStack(i, offset);
|
||||
if (item.isSimilar(clicked)) {
|
||||
if (clickedRule.canBeStacked(clicked, item)) {
|
||||
int amount = item.getAmount();
|
||||
if (amount == maxSize)
|
||||
continue;
|
||||
@ -487,12 +484,17 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragging(Player player, int slot, int button) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doubleClick(Player player, int slot) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
boolean isInWindow = isClickInWindow(slot);
|
||||
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
|
||||
InventoryCondition inventoryCondition = getInventoryCondition();
|
||||
@ -535,7 +537,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
if (amount == maxSize)
|
||||
break;
|
||||
ItemStack item = itemStacks[i];
|
||||
if (cursorItem.isSimilar(item)) {
|
||||
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||
int totalAmount = amount + item.getAmount();
|
||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||
@ -556,7 +558,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
if (amount == maxSize)
|
||||
break;
|
||||
ItemStack item = playerInventory.getItemStack(i);
|
||||
if (cursorItem.isSimilar(item)) {
|
||||
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||
int totalAmount = amount + item.getAmount();
|
||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||
@ -576,7 +578,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
if (amount == maxSize)
|
||||
break;
|
||||
ItemStack item = playerInventory.getItemStack(i);
|
||||
if (cursorItem.isSimilar(item)) {
|
||||
if (cursorRule.canBeStacked(cursorItem, item)) {
|
||||
int totalAmount = amount + item.getAmount();
|
||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||
cursorItem = cursorRule.apply(cursorItem, maxSize);
|
||||
|
@ -18,6 +18,8 @@ public interface InventoryClickHandler {
|
||||
|
||||
void dropItemStack(Player player, int slot);
|
||||
|
||||
void dragging(Player player, int slot, int button);
|
||||
|
||||
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.player.PlayerConnection;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerInventory implements InventoryModifier, InventoryClickHandler {
|
||||
|
||||
@ -286,6 +286,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
return windowItemsPacket;
|
||||
}
|
||||
|
||||
private Map<Player, Set<Integer>> leftDraggingMap = new HashMap<>();
|
||||
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void leftClick(Player player, int slot) {
|
||||
ItemStack cursorItem = getCursorItem();
|
||||
@ -323,7 +326,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||
StackingRule clickedRule = clicked.getStackingRule();
|
||||
|
||||
if (cursorItem.isSimilar(clicked)) {
|
||||
if (clickedRule.canBeStacked(clicked, cursorItem)) {
|
||||
resultCursor = cursorItem.clone();
|
||||
resultClicked = clicked.clone();
|
||||
int totalAmount = cursorItem.getAmount() + clicked.getAmount();
|
||||
@ -365,12 +368,6 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
}
|
||||
// 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())
|
||||
return;
|
||||
|
||||
@ -380,7 +377,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||
StackingRule clickedRule = clicked.getStackingRule();
|
||||
|
||||
if (cursorItem.isSimilar(clicked)) {
|
||||
if (clickedRule.canBeStacked(clicked, cursorItem)) {
|
||||
resultClicked = clicked.clone();
|
||||
int amount = clicked.getAmount() + 1;
|
||||
if (!clickedRule.canApply(resultClicked, amount)) {
|
||||
@ -391,22 +388,21 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
resultClicked = clickedRule.apply(resultClicked, amount);
|
||||
}
|
||||
} else {
|
||||
// TODO complete replace setAmount for StackingRule
|
||||
if (cursorItem.isAir()) {
|
||||
int amount = (int) Math.ceil((double) clicked.getAmount() / 2d);
|
||||
resultCursor = clicked.clone();
|
||||
resultCursor.setAmount((byte) amount);
|
||||
resultCursor = cursorRule.apply(resultCursor, amount);
|
||||
|
||||
resultClicked = clicked.clone();
|
||||
resultClicked.setAmount((byte) (clicked.getAmount() / 2));
|
||||
resultClicked = clickedRule.apply(resultClicked, clicked.getAmount() / 2);
|
||||
} else {
|
||||
if (clicked.isAir()) {
|
||||
int amount = cursorItem.getAmount();
|
||||
resultCursor = cursorItem.clone();
|
||||
resultCursor.setAmount((byte) (amount - 1));
|
||||
if (resultCursor.getAmount() < 1)
|
||||
resultCursor = ItemStack.AIR_ITEM;
|
||||
resultCursor = cursorRule.apply(resultCursor, amount - 1);
|
||||
|
||||
resultClicked = cursorItem.clone();
|
||||
resultClicked.setAmount((byte) 1);
|
||||
resultClicked = clickedRule.apply(resultClicked, 1);
|
||||
} else {
|
||||
resultCursor = clicked.clone();
|
||||
resultClicked = cursorItem.clone();
|
||||
@ -418,33 +414,72 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
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
|
||||
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())
|
||||
return;
|
||||
|
||||
StackingRule clickedRule = clicked.getStackingRule();
|
||||
|
||||
ItemStack resultClicked = clicked.clone();
|
||||
boolean filled = false;
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
int index = i < 9 ? i + 9 : i - 9;
|
||||
ItemStack item = items[index];
|
||||
StackingRule itemRule = item.getStackingRule();
|
||||
if (item.isSimilar(clicked)) {
|
||||
int amount = item.getAmount();
|
||||
if (amount == ITEM_MAX_SIZE)
|
||||
if (!clickedRule.canApply(clicked, amount + 1))
|
||||
continue;
|
||||
int totalAmount = resultClicked.getAmount() + amount;
|
||||
if (totalAmount > ITEM_MAX_SIZE) {
|
||||
item.setAmount((byte) ITEM_MAX_SIZE);
|
||||
setItemStack(index, item);
|
||||
resultClicked.setAmount((byte) (totalAmount - ITEM_MAX_SIZE));
|
||||
if (!clickedRule.canApply(clicked, totalAmount)) {
|
||||
item = itemRule.apply(item, itemRule.getMaxSize());
|
||||
setItemStack(index, OFFSET, item);
|
||||
|
||||
resultClicked = clickedRule.apply(resultClicked, totalAmount - clickedRule.getMaxSize());
|
||||
filled = false;
|
||||
continue;
|
||||
} else {
|
||||
resultClicked.setAmount((byte) totalAmount);
|
||||
resultClicked = clickedRule.apply(resultClicked, totalAmount);
|
||||
setItemStack(index, resultClicked);
|
||||
setItemStack(slot, OFFSET, ItemStack.AIR_ITEM);
|
||||
|
||||
item = itemRule.apply(item, 0);
|
||||
setItemStack(slot, OFFSET, item);
|
||||
filled = true;
|
||||
break;
|
||||
}
|
||||
@ -458,7 +493,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
}
|
||||
if (!filled) {
|
||||
setItemStack(slot, OFFSET, resultClicked);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -466,9 +501,27 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
if (!getCursorItem().isAir())
|
||||
return;
|
||||
|
||||
ItemStack cursorItem = getCursorItem();
|
||||
ItemStack heldItem = getItemStack(key);
|
||||
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 resultHeld;
|
||||
|
||||
@ -493,52 +546,152 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
}
|
||||
|
||||
@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
|
||||
public void dropOne(Player player, int slot) {
|
||||
if (result.isCancel()) {
|
||||
setItemStack(slot, OFFSET, clicked);
|
||||
setCursorItem(cursorItem);
|
||||
// Refresh client slot
|
||||
sendSlotRefresh((short) slot, clicked);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// End condition
|
||||
|
||||
}
|
||||
StackingRule stackingRule = cursorItem.getStackingRule();
|
||||
|
||||
@Override
|
||||
public void dropItemStack(Player player, int slot) {
|
||||
if (slot == -999) {
|
||||
// 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
|
||||
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())
|
||||
return;
|
||||
|
||||
StackingRule cursorRule = cursorItem.getStackingRule();
|
||||
int amount = cursorItem.getAmount();
|
||||
|
||||
if (amount == ITEM_MAX_SIZE)
|
||||
if (!cursorRule.canApply(cursorItem, amount + 1))
|
||||
return;
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
int index = i < 9 ? i + 9 : i - 9;
|
||||
if (index == slot)
|
||||
continue;
|
||||
if (amount == ITEM_MAX_SIZE)
|
||||
break;
|
||||
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();
|
||||
if (totalAmount > ITEM_MAX_SIZE) {
|
||||
cursorItem.setAmount((byte) ITEM_MAX_SIZE);
|
||||
item.setAmount((byte) (totalAmount - ITEM_MAX_SIZE));
|
||||
if (!cursorRule.canApply(cursorItem, totalAmount)) {
|
||||
cursorItem = cursorRule.apply(cursorItem, cursorRule.getMaxSize());
|
||||
|
||||
item = itemRule.apply(item, totalAmount - itemRule.getMaxSize());
|
||||
setItemStack(index, item);
|
||||
} else {
|
||||
cursorItem.setAmount((byte) totalAmount);
|
||||
setItemStack(index, ItemStack.AIR_ITEM);
|
||||
cursorItem = cursorRule.apply(cursorItem, totalAmount);
|
||||
item = itemRule.apply(item, 0);
|
||||
setItemStack(index, item);
|
||||
}
|
||||
amount = cursorItem.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
setCursorItem(cursorItem);*/
|
||||
setCursorItem(cursorItem);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,12 @@ import java.util.ArrayList;
|
||||
public class ItemStack implements DataContainer {
|
||||
|
||||
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 byte amount;
|
||||
|
@ -8,6 +8,8 @@ public abstract class StackingRule {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public abstract boolean canBeStacked(ItemStack item1, ItemStack item2);
|
||||
|
||||
public abstract boolean canApply(ItemStack item, int newAmount);
|
||||
|
||||
public abstract ItemStack apply(ItemStack item, int newAmount);
|
||||
|
@ -9,6 +9,11 @@ public class VanillaStackingRule extends StackingRule {
|
||||
super(maxSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeStacked(ItemStack item1, ItemStack item2) {
|
||||
return item1.isSimilar(item2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack item, int newAmount) {
|
||||
return newAmount > 0 && newAmount <= getMaxSize();
|
||||
|
@ -22,7 +22,7 @@ public class ChatMessageListener {
|
||||
|
||||
TextObject usernameText = TextBuilder.of(String.format("<%s>", username))
|
||||
.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 + " "))
|
||||
.append(" " + event.getMessage())
|
||||
.build();
|
||||
|
@ -58,6 +58,7 @@ public class WindowListener {
|
||||
break;
|
||||
case 5:
|
||||
// Dragging
|
||||
clickHandler.dragging(player, slot, button);
|
||||
break;
|
||||
case 6:
|
||||
clickHandler.doubleClick(player, slot);
|
||||
|
@ -35,12 +35,14 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
// TODO send encryption request OR directly login success
|
||||
UUID playerUuid = UUID.randomUUID();//UUID.fromString("OfflinePlayer:" + username);
|
||||
|
||||
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);//new LoginSuccessPacket(uuids.get(username), username);
|
||||
connection.sendPacket(successPacket);
|
||||
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
Player player = connectionManager.getPlayer(connection);
|
||||
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
Dimension dimension = Dimension.OVERWORLD;
|
||||
LevelType levelType = LevelType.DEFAULT;
|
||||
|
@ -15,10 +15,11 @@ public class PacketUtils {
|
||||
PacketWriter packetWriter = new PacketWriter(packet);
|
||||
serverPacket.write(packetWriter);
|
||||
|
||||
//System.out.println("WRITE PACKET: " + id + " " + serverPacket.getClass().getSimpleName());
|
||||
|
||||
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