Inventories! (Part 1)

This commit is contained in:
LOOHP
2022-12-09 02:40:16 +00:00
parent ca186938f4
commit 949d2f34d7
48 changed files with 10960 additions and 6652 deletions
@@ -20,6 +20,9 @@
package com.loohp.limbo.network;
import com.loohp.limbo.Limbo;
import com.loohp.limbo.events.inventory.InventoryCloseEvent;
import com.loohp.limbo.events.inventory.InventoryCreativeEvent;
import com.loohp.limbo.events.player.PlayerInteractEvent;
import com.loohp.limbo.events.player.PlayerJoinEvent;
import com.loohp.limbo.events.player.PlayerLoginEvent;
import com.loohp.limbo.events.player.PlayerMoveEvent;
@@ -30,6 +33,7 @@ import com.loohp.limbo.events.player.PlayerSpawnEvent;
import com.loohp.limbo.events.player.PluginMessageEvent;
import com.loohp.limbo.events.status.StatusPingEvent;
import com.loohp.limbo.file.ServerProperties;
import com.loohp.limbo.inventory.Inventory;
import com.loohp.limbo.location.Location;
import com.loohp.limbo.network.protocol.packets.Packet;
import com.loohp.limbo.network.protocol.packets.PacketHandshakingIn;
@@ -40,7 +44,9 @@ import com.loohp.limbo.network.protocol.packets.PacketLoginOutDisconnect;
import com.loohp.limbo.network.protocol.packets.PacketLoginOutLoginSuccess;
import com.loohp.limbo.network.protocol.packets.PacketLoginOutPluginMessaging;
import com.loohp.limbo.network.protocol.packets.PacketOut;
import com.loohp.limbo.network.protocol.packets.PacketPlayInBlockPlace;
import com.loohp.limbo.network.protocol.packets.PacketPlayInChat;
import com.loohp.limbo.network.protocol.packets.PacketPlayInCloseWindow;
import com.loohp.limbo.network.protocol.packets.PacketPlayInHeldItemChange;
import com.loohp.limbo.network.protocol.packets.PacketPlayInKeepAlive;
import com.loohp.limbo.network.protocol.packets.PacketPlayInPluginMessaging;
@@ -49,7 +55,10 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayInPositionAndLook;
import com.loohp.limbo.network.protocol.packets.PacketPlayInResourcePackStatus;
import com.loohp.limbo.network.protocol.packets.PacketPlayInResourcePackStatus.EnumResourcePackStatus;
import com.loohp.limbo.network.protocol.packets.PacketPlayInRotation;
import com.loohp.limbo.network.protocol.packets.PacketPlayInSetCreativeSlot;
import com.loohp.limbo.network.protocol.packets.PacketPlayInTabComplete;
import com.loohp.limbo.network.protocol.packets.PacketPlayInUseItem;
import com.loohp.limbo.network.protocol.packets.PacketPlayInWindowClick;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutDeclareCommands;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutDisconnect;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata;
@@ -86,6 +95,7 @@ import com.loohp.limbo.utils.GameMode;
import com.loohp.limbo.utils.MojangAPIUtils;
import com.loohp.limbo.utils.MojangAPIUtils.SkinResponse;
import com.loohp.limbo.world.BlockPosition;
import com.loohp.limbo.world.BlockState;
import com.loohp.limbo.world.World;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
@@ -114,6 +124,7 @@ import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@@ -491,7 +502,7 @@ public class ClientConnection extends Thread {
player = new Player(this, username, uuid, Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
player.setSkinLayers((byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
Limbo.getInstance().getUnsafe().addPlayer(player);
Limbo.getInstance().getUnsafe().a(player);
break;
} else if (packetIn instanceof PacketLoginInPluginMessaging) {
PacketLoginInPluginMessaging response = (PacketLoginInPluginMessaging) packetIn;
@@ -519,7 +530,7 @@ public class ClientConnection extends Thread {
player = new Player(this, data.getUsername(), data.getUuid(), Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
player.setSkinLayers((byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
Limbo.getInstance().getUnsafe().addPlayer(player);
Limbo.getInstance().getUnsafe().a(player);
break;
}
@@ -551,7 +562,7 @@ public class ClientConnection extends Thread {
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, properties.getDefaultGamemode(), Limbo.getInstance().getWorlds(), Limbo.getInstance().getDimensionRegistry().getCodec(), world, 0, (byte) properties.getMaxPlayers(), 8, 8, properties.isReducedDebugInfo(), true, false, true);
sendPacket(join);
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, properties.getDefaultGamemode());
Limbo.getInstance().getUnsafe().a(player, properties.getDefaultGamemode());
ByteArrayOutputStream brandOut = new ByteArrayOutputStream();
DataTypeIO.writeString(new DataOutputStream(brandOut), properties.getServerModName(), StandardCharsets.UTF_8);
@@ -586,7 +597,7 @@ public class ClientConnection extends Thread {
sendPacket(spawnPos);
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), worldSpawn.getYaw(), worldSpawn.getPitch(), 1, false);
Limbo.getInstance().getUnsafe().setPlayerLocationSilently(player, new Location(world, worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), worldSpawn.getYaw(), worldSpawn.getPitch()));
Limbo.getInstance().getUnsafe().a(player, new Location(world, worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), worldSpawn.getYaw(), worldSpawn.getPitch()));
sendPacket(positionLook);
player.getDataWatcher().update();
@@ -647,7 +658,7 @@ public class ClientConnection extends Thread {
sendPacket(cancel);
} else {
Location to = event.getTo();
Limbo.getInstance().getUnsafe().setPlayerLocationSilently(player, to);
Limbo.getInstance().getUnsafe().a(player, to);
// If an event handler used setTo, let's make sure we tell the player about it.
if (!originalTo.equals(to)) {
PacketPlayOutPositionAndLook pos = new PacketPlayOutPositionAndLook(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch(), 1, false);
@@ -657,7 +668,9 @@ public class ClientConnection extends Thread {
sendPacket(response);
}
};
System.out.println("Waiting");
PacketIn packetIn = channel.readPacket();
System.out.println("Received " + packetIn.getClass());
if (packetIn instanceof PacketPlayInPositionAndLook) {
PacketPlayInPositionAndLook pos = (PacketPlayInPositionAndLook) packetIn;
Location from = player.getLocation();
@@ -720,9 +733,9 @@ public class ClientConnection extends Thread {
} else if (change.getSlot() != event.getSlot()) {
PacketPlayOutHeldItemChange changePacket = new PacketPlayOutHeldItemChange(event.getSlot());
sendPacket(changePacket);
Limbo.getInstance().getUnsafe().setSelectedSlotSilently(player, event.getSlot());
Limbo.getInstance().getUnsafe().a(player, event.getSlot());
} else {
Limbo.getInstance().getUnsafe().setSelectedSlotSilently(player, event.getSlot());
Limbo.getInstance().getUnsafe().a(player, event.getSlot());
}
} else if (packetIn instanceof PacketPlayInResourcePackStatus) {
@@ -735,6 +748,42 @@ public class ClientConnection extends Thread {
} else if (packetIn instanceof PacketPlayInPluginMessaging) {
PacketPlayInPluginMessaging inPluginMessaging = (PacketPlayInPluginMessaging) packetIn;
Limbo.getInstance().getEventsManager().callEvent(new PluginMessageEvent(player, inPluginMessaging.getChannel(), inPluginMessaging.getData()));
} else if (packetIn instanceof PacketPlayInBlockPlace) {
PacketPlayInBlockPlace packet = (PacketPlayInBlockPlace) packetIn;
Limbo.getInstance().getEventsManager().callEvent(new PlayerInteractEvent(player, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, player.getEquipment().getItem(packet.getHand()), null, null, packet.getHand()));
} else if (packetIn instanceof PacketPlayInUseItem) {
PacketPlayInUseItem packet = (PacketPlayInUseItem) packetIn;
BlockState block = player.getWorld().getBlock(packet.getBlockHit().getBlockPos());
Limbo.getInstance().getEventsManager().callEvent(new PlayerInteractEvent(player, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, player.getEquipment().getItem(packet.getHand()), block, packet.getBlockHit().getDirection(), packet.getHand()));
} else if (packetIn instanceof PacketPlayInSetCreativeSlot) {
PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) packetIn;
InventoryCreativeEvent event = Limbo.getInstance().getEventsManager().callEvent(new InventoryCreativeEvent(player, player.getInventoryView(), player.getInventory(), player.getInventory().getUnsafe().b().applyAsInt(packet.getSlotNumber()), packet.getItemStack()));
if (event.isCancelled()) {
player.updateInventory();
} else {
player.getInventory().getUnsafe().b(packet.getSlotNumber(), event.getNewItem());
}
} else if (packetIn instanceof PacketPlayInWindowClick) {
PacketPlayInWindowClick packet = (PacketPlayInWindowClick) packetIn;
/*
InventoryCreativeEvent event = Limbo.getInstance().getEventsManager().callEvent(new InventoryCreativeEvent(player, player.getInventoryView(), player.getInventory(), player.getInventory().getUnsafe().b().applyAsInt(packet.getSlotNumber()), packet.getItemStack()));
if (event.isCancelled()) {
player.updateInventory();
} else {
player.getInventory().getUnsafe().b(packet.getSlotNumber(), event.getNewItem());
}
*/
} else if (packetIn instanceof PacketPlayInCloseWindow) {
PacketPlayInCloseWindow packet = (PacketPlayInCloseWindow) packetIn;
Inventory inventory = player.getInventoryView().getTopInventory();
if (inventory != null) {
Integer id = inventory.getUnsafe().c().get(player);
if (id != null) {
Limbo.getInstance().getEventsManager().callEvent(new InventoryCloseEvent(player, player.getInventoryView()));
player.getInventoryView().getUnsafe().a(null);
inventory.getUnsafe().c().remove(player);
}
}
}
} catch (Exception e) {
break;
@@ -757,7 +806,7 @@ public class ClientConnection extends Thread {
state = ClientState.DISCONNECTED;
if (player != null) {
Limbo.getInstance().getUnsafe().removePlayer(player);
Limbo.getInstance().getUnsafe().b(player);
}
Limbo.getInstance().getServerConnection().getClients().remove(this);
running = false;
@@ -0,0 +1,49 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.EquipmentSlot;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.DataInputStream;
import java.io.IOException;
public class PacketPlayInBlockPlace extends PacketIn {
private EquipmentSlot hand;
private int sequence;
public PacketPlayInBlockPlace(EquipmentSlot hand, int sequence) {
this.hand = hand;
this.sequence = sequence;
}
public PacketPlayInBlockPlace(DataInputStream in) throws IOException {
this(EquipmentSlot.values()[DataTypeIO.readVarInt(in)], DataTypeIO.readVarInt(in));
}
public EquipmentSlot getHand() {
return hand;
}
public int getSequence() {
return sequence;
}
}
@@ -0,0 +1,40 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import java.io.DataInputStream;
import java.io.IOException;
public class PacketPlayInCloseWindow extends PacketIn {
private int containerId;
public PacketPlayInCloseWindow(int containerId) {
this.containerId = containerId;
}
public PacketPlayInCloseWindow(DataInputStream in) throws IOException {
this(in.readByte());
}
public int getContainerId() {
return containerId;
}
}
@@ -0,0 +1,49 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.ItemStack;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.DataInputStream;
import java.io.IOException;
public class PacketPlayInSetCreativeSlot extends PacketIn {
private int slotNumber;
private ItemStack itemStack;
public PacketPlayInSetCreativeSlot(int slotNumber, ItemStack itemStack) {
this.slotNumber = slotNumber;
this.itemStack = itemStack;
}
public PacketPlayInSetCreativeSlot(DataInputStream in) throws IOException {
this(in.readShort(), DataTypeIO.readItemStack(in));
}
public int getSlotNumber() {
return slotNumber;
}
public ItemStack getItemStack() {
return itemStack;
}
}
@@ -0,0 +1,56 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.EquipmentSlot;
import com.loohp.limbo.location.MovingObjectPositionBlock;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.DataInputStream;
import java.io.IOException;
public class PacketPlayInUseItem extends PacketIn {
private EquipmentSlot hand;
private MovingObjectPositionBlock blockHit;
private int sequence;
public PacketPlayInUseItem(EquipmentSlot hand, MovingObjectPositionBlock blockHit, int sequence) {
this.hand = hand;
this.blockHit = blockHit;
this.sequence = sequence;
}
public PacketPlayInUseItem(DataInputStream in) throws IOException {
this(EquipmentSlot.values()[DataTypeIO.readVarInt(in)], DataTypeIO.readBlockHitResult(in), DataTypeIO.readVarInt(in));
}
public EquipmentSlot getHand() {
return hand;
}
public MovingObjectPositionBlock getBlockHit() {
return blockHit;
}
public int getSequence() {
return sequence;
}
}
@@ -0,0 +1,96 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.InventoryClickType;
import com.loohp.limbo.inventory.ItemStack;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class PacketPlayInWindowClick extends PacketIn {
private int containerId;
private int stateId;
private int slotNum;
private int buttonNum;
private InventoryClickType clickType;
private Map<Integer, ItemStack> changedSlots;
private ItemStack carriedItem;
public PacketPlayInWindowClick(int containerId, int stateId, int slotNum, int buttonNum, InventoryClickType clickType, Map<Integer, ItemStack> changedSlots, ItemStack carriedItem) {
this.containerId = containerId;
this.stateId = stateId;
this.slotNum = slotNum;
this.buttonNum = buttonNum;
this.clickType = clickType;
this.changedSlots = changedSlots;
this.carriedItem = carriedItem;
}
public PacketPlayInWindowClick(DataInputStream in) throws IOException {
this.containerId = in.readByte();
this.stateId = DataTypeIO.readVarInt(in);
this.slotNum = in.readShort();
this.buttonNum = in.readByte();
this.clickType = InventoryClickType.values()[DataTypeIO.readVarInt(in)];
Map<Integer, ItemStack> changedSlots = new HashMap<>();
int size = DataTypeIO.readVarInt(in);
for (int i = 0; i < size; i++) {
int slot = in.readShort();
ItemStack itemStack = DataTypeIO.readItemStack(in);
changedSlots.put(slot, itemStack);
}
this.changedSlots = Collections.unmodifiableMap(changedSlots);
this.carriedItem = DataTypeIO.readItemStack(in);
}
public int getContainerId() {
return containerId;
}
public int getStateId() {
return stateId;
}
public int getSlotNum() {
return slotNum;
}
public int getButtonNum() {
return buttonNum;
}
public InventoryClickType getClickType() {
return clickType;
}
public Map<Integer, ItemStack> getChangedSlots() {
return changedSlots;
}
public ItemStack getCarriedItem() {
return carriedItem;
}
}
@@ -0,0 +1,49 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class PacketPlayOutCloseWindow extends PacketOut {
private int containerId;
public PacketPlayOutCloseWindow(int containerId) {
this.containerId = containerId;
}
public int getContainerId() {
return containerId;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(containerId);
return buffer.toByteArray();
}
}
@@ -0,0 +1,70 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.registry.Registry;
import com.loohp.limbo.utils.DataTypeIO;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PacketPlayOutOpenWindow extends PacketOut {
private int containerId;
private Key type;
private Component title;
public PacketPlayOutOpenWindow(int containerId, Key type, Component title) {
this.containerId = containerId;
this.type = type;
this.title = title;
}
public int getContainerId() {
return containerId;
}
public Key getType() {
return type;
}
public Component getTitle() {
return title;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
DataTypeIO.writeVarInt(output, containerId);
DataTypeIO.writeVarInt(output, Registry.MENU_REGISTRY.getId(type));
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(title), StandardCharsets.UTF_8);
return buffer.toByteArray();
}
}
@@ -0,0 +1,74 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.ItemStack;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
public class PacketPlayOutSetSlot extends PacketOut {
private int containerId;
private int stateId;
private int slot;
private ItemStack itemStack;
public PacketPlayOutSetSlot(int containerId, int stateId, int slot, ItemStack itemStack) {
this.containerId = containerId;
this.stateId = stateId;
this.slot = slot;
this.itemStack = itemStack;
}
public int getContainerId() {
return containerId;
}
public int getStateId() {
return stateId;
}
public int getSlot() {
return slot;
}
public ItemStack getItemStack() {
return itemStack;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(containerId);
DataTypeIO.writeVarInt(output, stateId);
output.writeShort(slot);
DataTypeIO.writeItemStack(output, itemStack);
return buffer.toByteArray();
}
}
@@ -0,0 +1,63 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class PacketPlayOutWindowData extends PacketOut {
private int containerId;
private int id;
private int value;
public PacketPlayOutWindowData(int containerId, int id, int value) {
this.containerId = containerId;
this.id = id;
this.value = value;
}
public int getContainerId() {
return containerId;
}
public int getId() {
return id;
}
public int getValue() {
return value;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(containerId);
output.writeShort(id);
output.writeShort(value);
return buffer.toByteArray();
}
}
@@ -0,0 +1,77 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import com.loohp.limbo.inventory.ItemStack;
import com.loohp.limbo.utils.DataTypeIO;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
public class PacketPlayOutWindowItems extends PacketOut {
private int containerId;
private int stateId;
private List<ItemStack> items;
private ItemStack carriedItem;
public PacketPlayOutWindowItems(int containerId, int stateId, List<ItemStack> items, ItemStack carriedItem) {
this.containerId = containerId;
this.stateId = stateId;
this.items = items;
this.carriedItem = carriedItem;
}
public int getContainerId() {
return containerId;
}
public int getStateId() {
return stateId;
}
public List<ItemStack> getItems() {
return items;
}
public ItemStack getCarriedItem() {
return carriedItem;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(containerId);
DataTypeIO.writeVarInt(output, stateId);
DataTypeIO.writeVarInt(output, items.size());
for (ItemStack itemStack : items) {
DataTypeIO.writeItemStack(output, itemStack);
}
DataTypeIO.writeItemStack(output, carriedItem);
return buffer.toByteArray();
}
}