mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 03:27:56 +01:00
Added dropping functions + fixes
This commit is contained in:
parent
f596a8fa84
commit
7cbb964e21
@ -142,7 +142,7 @@ public class PlayerInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
player.setEventCallback(PlayerSpawnEvent.class, event -> {
|
player.setEventCallback(PlayerSpawnEvent.class, event -> {
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
player.teleport(new Position(0, 75, 0));
|
player.teleport(new Position(0, 75, 0));
|
||||||
|
|
||||||
/*Random random = new Random();
|
/*Random random = new Random();
|
||||||
@ -168,7 +168,8 @@ public class PlayerInit {
|
|||||||
player.getInventory().addItemStack(item);
|
player.getInventory().addItemStack(item);
|
||||||
|
|
||||||
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||||
inventory.setInventoryCondition((p, slot, inventoryConditionResult) -> {
|
inventory.setInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||||
|
player.sendMessage("click type: " + clickType);
|
||||||
inventoryConditionResult.setCancel(false);
|
inventoryConditionResult.setCancel(false);
|
||||||
});
|
});
|
||||||
inventory.setItemStack(0, item.clone());
|
inventory.setItemStack(0, item.clone());
|
||||||
|
@ -322,6 +322,7 @@ public class Player extends LivingEntity {
|
|||||||
}
|
}
|
||||||
boolean isLast = counter.get() == length - 1;
|
boolean isLast = counter.get() == length - 1;
|
||||||
if (isLast) {
|
if (isLast) {
|
||||||
|
System.out.println("DEBUG CHUNK: " + chunk);
|
||||||
// This is the last chunk to be loaded , spawn player
|
// This is the last chunk to be loaded , spawn player
|
||||||
super.setInstance(instance);
|
super.setInstance(instance);
|
||||||
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance);
|
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance);
|
||||||
|
@ -266,13 +266,30 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dropOne(Player player, int slot) {
|
public void drop(Player player, int mode, int slot, int button) {
|
||||||
|
PlayerInventory playerInventory = player.getInventory();
|
||||||
|
boolean isInWindow = isClickInWindow(slot);
|
||||||
|
ItemStack clicked = slot == -999 ?
|
||||||
|
null : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset));
|
||||||
|
ItemStack cursor = getCursorItem(player);
|
||||||
|
|
||||||
|
InventoryClickResult clickResult = clickProcessor.drop(getInventoryCondition(), player,
|
||||||
|
mode, slot, button, clicked, cursor);
|
||||||
|
|
||||||
|
if (clickResult.doRefresh())
|
||||||
|
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||||
|
|
||||||
|
ItemStack resultClicked = clickResult.getClicked();
|
||||||
|
if (isInWindow) {
|
||||||
|
if (resultClicked != null)
|
||||||
|
setItemStack(slot, resultClicked);
|
||||||
|
setCursorPlayerItem(player, clickResult.getCursor());
|
||||||
|
} else {
|
||||||
|
if (resultClicked != null)
|
||||||
|
playerInventory.setItemStack(slot, offset, resultClicked);
|
||||||
|
setCursorPlayerItem(player, clickResult.getCursor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dropItemStack(Player player, int slot) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,9 +14,7 @@ public interface InventoryClickHandler {
|
|||||||
|
|
||||||
void middleClick(Player player, int slot);
|
void middleClick(Player player, int slot);
|
||||||
|
|
||||||
void dropOne(Player player, int slot);
|
void drop(Player player, int mode, int slot, int button);
|
||||||
|
|
||||||
void dropItemStack(Player player, int slot);
|
|
||||||
|
|
||||||
void dragging(Player player, int slot, int button);
|
void dragging(Player player, int slot, int button);
|
||||||
|
|
||||||
|
@ -312,13 +312,20 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dropOne(Player player, int slot) {
|
public void drop(Player player, int mode, int slot, int button) {
|
||||||
|
ItemStack cursor = getCursorItem();
|
||||||
|
ItemStack clicked = slot == -999 ? null : getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
}
|
InventoryClickResult clickResult = clickProcessor.drop(getInventoryCondition(), player,
|
||||||
|
mode, slot, button, clicked, cursor);
|
||||||
|
|
||||||
@Override
|
if (clickResult.doRefresh())
|
||||||
public void dropItemStack(Player player, int slot) {
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
|
||||||
|
ItemStack resultClicked = clickResult.getClicked();
|
||||||
|
if (resultClicked != null)
|
||||||
|
setItemStack(slot, OFFSET, resultClicked);
|
||||||
|
setCursorItem(clickResult.getCursor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package fr.themode.minestom.inventory.click;
|
||||||
|
|
||||||
|
public enum ClickType {
|
||||||
|
|
||||||
|
LEFT_CLICK,
|
||||||
|
RIGHT_CLICK,
|
||||||
|
CHANGE_HELD,
|
||||||
|
SHIFT_CLICK,
|
||||||
|
DRAGGING,
|
||||||
|
DOUBLE_CLICK,
|
||||||
|
DROP
|
||||||
|
|
||||||
|
}
|
@ -20,7 +20,7 @@ public class InventoryClickProcessor {
|
|||||||
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
||||||
|
|
||||||
public InventoryClickResult leftClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult leftClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -63,7 +63,7 @@ public class InventoryClickProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult rightClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult rightClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -120,7 +120,7 @@ public class InventoryClickProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult changeHeld(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult changeHeld(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -186,7 +186,7 @@ public class InventoryClickProcessor {
|
|||||||
StackingRule itemRule = item.getStackingRule();
|
StackingRule itemRule = item.getStackingRule();
|
||||||
if (itemRule.canBeStacked(item, clicked)) {
|
if (itemRule.canBeStacked(item, clicked)) {
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
|
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ public class InventoryClickProcessor {
|
|||||||
}
|
}
|
||||||
} else if (item.isAir()) {
|
} else if (item.isAir()) {
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
|
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ public class InventoryClickProcessor {
|
|||||||
ItemStack draggedItem = cursor.clone();
|
ItemStack draggedItem = cursor.clone();
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, s, slotItem, cursor);
|
clickResult = startCondition(clickResult, inventoryCondition, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ public class InventoryClickProcessor {
|
|||||||
ItemStack draggedItem = cursor.clone();
|
ItemStack draggedItem = cursor.clone();
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, s, slotItem, cursor);
|
clickResult = startCondition(clickResult, inventoryCondition, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ public class InventoryClickProcessor {
|
|||||||
if (!cursorRule.canApply(cursor, amount + 1))
|
if (!cursorRule.canApply(cursor, amount + 1))
|
||||||
break;
|
break;
|
||||||
if (cursorRule.canBeStacked(cursor, item)) {
|
if (cursorRule.canBeStacked(cursor, item)) {
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
|
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.DOUBLE_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -401,10 +401,70 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(InventoryClickResult clickResult, InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult drop(InventoryCondition inventoryCondition, Player player,
|
||||||
|
int mode, int slot, int button,
|
||||||
|
ItemStack clicked, ItemStack cursor) {
|
||||||
|
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.DROP, clicked, cursor);
|
||||||
|
|
||||||
|
if (clickResult.isCancel()) {
|
||||||
|
return clickResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
StackingRule clickedRule = clicked == null ? null : clicked.getStackingRule();
|
||||||
|
StackingRule cursorRule = cursor.getStackingRule();
|
||||||
|
|
||||||
|
ItemStack resultClicked = clicked == null ? null : clicked.clone();
|
||||||
|
ItemStack resultCursor = cursor.clone();
|
||||||
|
|
||||||
|
|
||||||
|
if (slot == -999) {
|
||||||
|
// Click outside
|
||||||
|
if (button == 0) {
|
||||||
|
// Left (drop all)
|
||||||
|
int amount = cursorRule.getAmount(resultCursor);
|
||||||
|
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), amount);
|
||||||
|
if (player.dropItem(dropItem)) {
|
||||||
|
resultCursor = cursorRule.apply(resultCursor, 0);
|
||||||
|
}
|
||||||
|
} else if (button == 1) {
|
||||||
|
// Right (drop 1)
|
||||||
|
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), 1);
|
||||||
|
if (player.dropItem(dropItem)) {
|
||||||
|
int amount = cursorRule.getAmount(resultCursor);
|
||||||
|
int newAmount = amount - 1;
|
||||||
|
resultCursor = cursorRule.apply(resultCursor, newAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (mode == 4) {
|
||||||
|
if (button == 0) {
|
||||||
|
// Drop key Q (drop 1)
|
||||||
|
ItemStack dropItem = cursorRule.apply(resultClicked.clone(), 1);
|
||||||
|
if (player.dropItem(dropItem)) {
|
||||||
|
int amount = clickedRule.getAmount(resultClicked);
|
||||||
|
int newAmount = amount - 1;
|
||||||
|
resultClicked = cursorRule.apply(resultClicked, newAmount);
|
||||||
|
}
|
||||||
|
} else if (button == 1) {
|
||||||
|
// Ctrl + Drop key Q (drop all)
|
||||||
|
int amount = cursorRule.getAmount(resultClicked);
|
||||||
|
ItemStack dropItem = clickedRule.apply(resultClicked.clone(), amount);
|
||||||
|
if (player.dropItem(dropItem)) {
|
||||||
|
resultClicked = cursorRule.apply(resultClicked, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clickResult.setClicked(resultClicked);
|
||||||
|
clickResult.setCursor(resultCursor);
|
||||||
|
|
||||||
|
return clickResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InventoryClickResult startCondition(InventoryClickResult clickResult, InventoryCondition inventoryCondition, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
if (inventoryCondition != null) {
|
if (inventoryCondition != null) {
|
||||||
InventoryConditionResult result = new InventoryConditionResult(clicked, cursor);
|
InventoryConditionResult result = new InventoryConditionResult(clicked, cursor);
|
||||||
inventoryCondition.accept(player, slot, result);
|
inventoryCondition.accept(player, slot, clickType, result);
|
||||||
|
|
||||||
cursor = result.getCursorItem();
|
cursor = result.getCursorItem();
|
||||||
clicked = result.getClickedItem();
|
clicked = result.getClickedItem();
|
||||||
@ -419,9 +479,9 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
private InventoryClickResult startCondition(InventoryCondition inventoryCondition, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
||||||
return startCondition(clickResult, inventoryCondition, player, slot, clicked, cursor);
|
return startCondition(clickResult, inventoryCondition, player, slot, clickType, clicked, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package fr.themode.minestom.inventory.condition;
|
package fr.themode.minestom.inventory.condition;
|
||||||
|
|
||||||
import fr.themode.minestom.entity.Player;
|
import fr.themode.minestom.entity.Player;
|
||||||
|
import fr.themode.minestom.inventory.click.ClickType;
|
||||||
|
|
||||||
public interface InventoryCondition {
|
public interface InventoryCondition {
|
||||||
|
|
||||||
void accept(Player player, int slot, InventoryConditionResult inventoryConditionResult);
|
void accept(Player player, int slot, ClickType clickType, InventoryConditionResult inventoryConditionResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package fr.themode.minestom.listener;
|
|||||||
|
|
||||||
import fr.themode.minestom.MinecraftServer;
|
import fr.themode.minestom.MinecraftServer;
|
||||||
import fr.themode.minestom.data.Data;
|
import fr.themode.minestom.data.Data;
|
||||||
|
import fr.themode.minestom.entity.Entity;
|
||||||
import fr.themode.minestom.entity.GameMode;
|
import fr.themode.minestom.entity.GameMode;
|
||||||
import fr.themode.minestom.entity.Player;
|
import fr.themode.minestom.entity.Player;
|
||||||
import fr.themode.minestom.event.PlayerBlockInteractEvent;
|
import fr.themode.minestom.event.PlayerBlockInteractEvent;
|
||||||
@ -21,6 +22,8 @@ import fr.themode.minestom.net.packet.client.play.ClientPlayerDiggingPacket;
|
|||||||
import fr.themode.minestom.utils.BlockPosition;
|
import fr.themode.minestom.utils.BlockPosition;
|
||||||
import fr.themode.minestom.utils.ChunkUtils;
|
import fr.themode.minestom.utils.ChunkUtils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class BlockPlacementListener {
|
public class BlockPlacementListener {
|
||||||
|
|
||||||
private Instance instance;
|
private Instance instance;
|
||||||
@ -35,6 +38,7 @@ public class BlockPlacementListener {
|
|||||||
if (instance == null)
|
if (instance == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Interact at block
|
||||||
PlayerBlockInteractEvent playerBlockInteractEvent = new PlayerBlockInteractEvent(blockPosition, hand);
|
PlayerBlockInteractEvent playerBlockInteractEvent = new PlayerBlockInteractEvent(blockPosition, hand);
|
||||||
player.callCancellableEvent(PlayerBlockInteractEvent.class, playerBlockInteractEvent, () -> {
|
player.callCancellableEvent(PlayerBlockInteractEvent.class, playerBlockInteractEvent, () -> {
|
||||||
CustomBlock customBlock = instance.getCustomBlock(blockPosition);
|
CustomBlock customBlock = instance.getCustomBlock(blockPosition);
|
||||||
@ -44,21 +48,32 @@ public class BlockPlacementListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if item at hand is a block
|
||||||
ItemStack usedItem = hand == Player.Hand.MAIN ? playerInventory.getItemInMainHand() : playerInventory.getItemInOffHand();
|
ItemStack usedItem = hand == Player.Hand.MAIN ? playerInventory.getItemInMainHand() : playerInventory.getItemInOffHand();
|
||||||
Material material = Material.fromId(usedItem.getMaterialId());
|
Material material = Material.fromId(usedItem.getMaterialId());
|
||||||
if (material != null && !material.isBlock()) {
|
if (material != null && !material.isBlock()) {
|
||||||
//instance.setBlock(blockPosition.clone().add(0, 1, 0), (short) 10);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the newly placed block position
|
||||||
int offsetX = blockFace == ClientPlayerDiggingPacket.BlockFace.WEST ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.EAST ? 1 : 0;
|
int offsetX = blockFace == ClientPlayerDiggingPacket.BlockFace.WEST ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.EAST ? 1 : 0;
|
||||||
int offsetY = blockFace == ClientPlayerDiggingPacket.BlockFace.BOTTOM ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.TOP ? 1 : 0;
|
int offsetY = blockFace == ClientPlayerDiggingPacket.BlockFace.BOTTOM ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.TOP ? 1 : 0;
|
||||||
int offsetZ = blockFace == ClientPlayerDiggingPacket.BlockFace.NORTH ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.SOUTH ? 1 : 0;
|
int offsetZ = blockFace == ClientPlayerDiggingPacket.BlockFace.NORTH ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.SOUTH ? 1 : 0;
|
||||||
|
|
||||||
blockPosition.add(offsetX, offsetY, offsetZ);
|
blockPosition.add(offsetX, offsetY, offsetZ);
|
||||||
boolean intersectPlayer = player.getBoundingBox().intersect(blockPosition); // TODO check if collide with nearby other players
|
|
||||||
if (material.isBlock() && !intersectPlayer) {
|
Chunk chunk = instance.getChunkAt(blockPosition);
|
||||||
|
Set<Entity> entities = instance.getChunkEntities(chunk);
|
||||||
|
boolean intersect = false;
|
||||||
|
for (Entity entity : entities) {
|
||||||
|
intersect = entity.getBoundingBox().intersect(blockPosition);
|
||||||
|
if (intersect)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean refreshChunk = false;
|
||||||
|
|
||||||
|
if (material.isBlock() && !intersect) {
|
||||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
||||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||||
|
|
||||||
@ -73,7 +88,6 @@ public class BlockPlacementListener {
|
|||||||
|
|
||||||
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
|
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
|
||||||
if (!playerBlockPlaceEvent.isCancelled() && canPlace) {
|
if (!playerBlockPlaceEvent.isCancelled() && canPlace) {
|
||||||
player.sendMessage("PLACE BLOCK");
|
|
||||||
instance.setBlock(blockPosition, material.getBlock());
|
instance.setBlock(blockPosition, material.getBlock());
|
||||||
//instance.setCustomBlock(blockPosition, "updatable");
|
//instance.setCustomBlock(blockPosition, "updatable");
|
||||||
if (playerBlockPlaceEvent.doesConsumeBlock()) {
|
if (playerBlockPlaceEvent.doesConsumeBlock()) {
|
||||||
@ -88,15 +102,17 @@ public class BlockPlacementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Refresh chunk
|
refreshChunk = true;
|
||||||
Chunk chunk = instance.getChunkAt(blockPosition);
|
|
||||||
instance.sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Refresh chunk
|
refreshChunk = true;
|
||||||
Chunk chunk = instance.getChunkAt(blockPosition);
|
}
|
||||||
|
|
||||||
|
// Refresh chunk section if needed
|
||||||
|
if (refreshChunk) {
|
||||||
instance.sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
|
instance.sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().refreshSlot(player.getHeldSlot());
|
player.getInventory().refreshSlot(player.getHeldSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +63,6 @@ public class UseItemListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check if item in main or off hand is food or item with animation (bow/crossbow/riptide)
|
|
||||||
// TODO in material enum?
|
|
||||||
ArmAnimationEvent armAnimationEvent = null;
|
ArmAnimationEvent armAnimationEvent = null;
|
||||||
boolean offhand = hand == Player.Hand.OFF;
|
boolean offhand = hand == Player.Hand.OFF;
|
||||||
boolean riptideSpinAttack = false;
|
boolean riptideSpinAttack = false;
|
||||||
|
@ -24,7 +24,7 @@ public class WindowListener {
|
|||||||
short actionNumber = packet.actionNumber;
|
short actionNumber = packet.actionNumber;
|
||||||
int mode = packet.mode;
|
int mode = packet.mode;
|
||||||
|
|
||||||
System.out.println("Window id: " + windowId + " | slot: " + slot + " | button: " + button + " | mode: " + mode);
|
// System.out.println("Window id: " + windowId + " | slot: " + slot + " | button: " + button + " | mode: " + mode);
|
||||||
|
|
||||||
ConfirmTransactionPacket confirmTransactionPacket = new ConfirmTransactionPacket();
|
ConfirmTransactionPacket confirmTransactionPacket = new ConfirmTransactionPacket();
|
||||||
confirmTransactionPacket.windowId = windowId;
|
confirmTransactionPacket.windowId = windowId;
|
||||||
@ -35,12 +35,22 @@ public class WindowListener {
|
|||||||
case 0:
|
case 0:
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case 0:
|
case 0:
|
||||||
|
if (slot != -999) {
|
||||||
// Left click
|
// Left click
|
||||||
clickHandler.leftClick(player, slot);
|
clickHandler.leftClick(player, slot);
|
||||||
|
} else {
|
||||||
|
// DROP
|
||||||
|
clickHandler.drop(player, mode, slot, button);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
if (slot != -999) {
|
||||||
// Right click
|
// Right click
|
||||||
clickHandler.rightClick(player, slot);
|
clickHandler.rightClick(player, slot);
|
||||||
|
} else {
|
||||||
|
// DROP
|
||||||
|
clickHandler.drop(player, mode, slot, button);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -55,6 +65,7 @@ public class WindowListener {
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// Dropping functions
|
// Dropping functions
|
||||||
|
clickHandler.drop(player, mode, slot, button);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Dragging
|
// Dragging
|
||||||
|
Loading…
Reference in New Issue
Block a user