use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.
the class V1_8BItemDataType method write.
@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) {
ItemStack itemStack = (ItemStack) typeHolder.getObject();
if (itemStack == null) {
packetOutput.writeShort(-1);
} else {
packetOutput.writeShort(itemStack.getItemId());
packetOutput.writeShort(itemStack.getAmount());
packetOutput.writeShort(itemStack.getData());
}
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.
the class V1_8RItemDataType method read.
@Override
public ItemStack read(PacketInput packetInput) {
int itemId = packetInput.readShort();
if (itemId >= 0) {
int amount = packetInput.readByte();
int data = packetInput.readShort();
CompoundBinaryTag compoundTag = NBTUtils.readNBTUncompressed(packetInput);
return new ItemStack(itemId, amount, data, compoundTag);
}
return null;
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.
the class MetadataDataType method read.
@Override
public WatchableObject[] read(PacketInput packetInput) throws IOException {
ArrayList<WatchableObject> dataMap = new ArrayList<>();
for (byte b = packetInput.readByte(); b != 127; b = packetInput.readByte()) {
MetadataType type = MetadataType.fromType((b & 224) >> 5);
int index = b & 31;
WatchableObject value = null;
switch(type) {
case BYTE:
value = new WatchableObject(type, index, BaseProtocol.BYTE.read(packetInput));
break;
case SHORT:
value = new WatchableObject(type, index, BaseProtocol.SHORT.read(packetInput));
break;
case INT:
value = new WatchableObject(type, index, BaseProtocol.INT.read(packetInput));
break;
case FLOAT:
value = new WatchableObject(type, index, BaseProtocol.FLOAT.read(packetInput));
break;
case STRING:
if (getType() == Type.V1_7R_METADATA || getType() == Type.V1_8R_METADATA) {
value = new WatchableObject(type, index, V1_7_2RProtocol.STRING.read(packetInput));
} else {
value = new WatchableObject(type, index, BaseProtocol.STRING.read(packetInput));
}
break;
case ITEM:
ItemStack itemStack;
if (getType() == Type.V1_4R_METADATA || getType() == Type.V1_7R_METADATA) {
itemStack = V1_3_1RProtocol.ITEM.read(packetInput);
} else if (getType() == Type.V1_8R_METADATA) {
itemStack = V1_8RProtocol.ITEM.read(packetInput);
} else {
itemStack = V1_3BProtocol.ITEM.read(packetInput);
}
value = new WatchableObject(type, index, itemStack);
break;
case POSITION:
int x = packetInput.readInt();
int y = packetInput.readInt();
int z = packetInput.readInt();
value = new WatchableObject(type, index, new BlockLocation(x, y, z));
break;
case ROTATION:
float rX = packetInput.readFloat();
float rY = packetInput.readFloat();
float rZ = packetInput.readFloat();
value = new WatchableObject(type, index, new Rotation(rX, rY, rZ));
break;
}
dataMap.add(value);
}
return dataMap.toArray(new WatchableObject[0]);
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.
the class ItemArrayDataType method write.
@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
ItemStack[] objArray = (ItemStack[]) typeHolder.getObject();
packetOutput.writeShort(objArray.length);
for (ItemStack item : objArray) {
childInstruction.write(new TypeHolder(childInstruction.getType(), item), packetOutput);
}
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.
the class ProtocolRelease23To22 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { // protocol version
set(Type.INT, 22), data.read(1), data.read(2), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8) });
}
});
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(2), // world type
set(Type.STRING, "default"), data.read(3), data.read(4), data.read(5), data.read(6), data.read(7) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), // world type
set(Type.STRING, "default") });
}
});
// custom payload
addTranslator(0xFA, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
// cancel packet
return cancel();
}
});
// chat
addTranslator(0x03, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
String filteredMessage = ChatFilter.filterChat(data.read(Type.STRING, 0));
return PacketUtil.createPacket(0x03, new TypeHolder[] { set(Type.STRING, filteredMessage) });
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_0R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_0R_ITEM, item) });
}
});
}
Aggregations