PacketNameItem, PacketSelectTrade, PacketSetBeaconEffect, PacketUpdateCommandBlock, PacketUpdateCommandBlockMinecart

This commit is contained in:
Bixilon 2020-07-18 22:35:05 +02:00
parent 6e8228b941
commit 853075c2d6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,47 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketNameItem implements ServerboundPacket {
final String name;
public PacketNameItem(String name) {
this.name = name;
}
@Override
public OutPacketBuffer write(ProtocolVersion version) {
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_NAME_ITEM));
switch (version) {
case VERSION_1_13_2:
buffer.writeString(name);
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending name item packet (name=\"%s\")", name));
}
}

View File

@ -0,0 +1,47 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketSelectTrade implements ServerboundPacket {
final int id;
public PacketSelectTrade(int id) {
this.id = id;
}
@Override
public OutPacketBuffer write(ProtocolVersion version) {
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_SELECT_TRADE));
switch (version) {
case VERSION_1_13_2:
buffer.writeVarInt(id);
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending select trade packet (id=%d)", id));
}
}

View File

@ -0,0 +1,50 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketSetBeaconEffect implements ServerboundPacket {
final int primaryEffectId;
final int secondaryEffectId;
public PacketSetBeaconEffect(int primaryEffectId, int secondaryEffectId) {
this.primaryEffectId = primaryEffectId;
this.secondaryEffectId = secondaryEffectId;
}
@Override
public OutPacketBuffer write(ProtocolVersion version) {
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_SET_BEACON_EFFECT));
switch (version) {
case VERSION_1_13_2:
buffer.writeVarInt(primaryEffectId);
buffer.writeVarInt(secondaryEffectId);
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending beacon effect select packet (primaryEffectId=%d, secondaryEffectId=%d)", primaryEffectId, secondaryEffectId));
}
}

View File

@ -0,0 +1,99 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketUpdateCommandBlock implements ServerboundPacket {
final BlockPosition position;
final String command;
final CommandBlockType type;
final boolean trackOutput;
final boolean isConditional;
final boolean isAutomatic;
public PacketUpdateCommandBlock(BlockPosition position, String command, CommandBlockType type, boolean trackOutput, boolean isConditional, boolean isAutomatic) {
this.position = position;
this.command = command;
this.type = type;
this.trackOutput = trackOutput;
this.isConditional = isConditional;
this.isAutomatic = isAutomatic;
}
@Override
public OutPacketBuffer write(ProtocolVersion version) {
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_UPDATE_COMMAND_BLOCK));
switch (version) {
case VERSION_1_13_2:
buffer.writePosition(position);
buffer.writeString(command);
buffer.writeVarInt(type.getId());
byte flags = 0x00;
if (trackOutput) {
flags |= 0x01;
}
if (isConditional) {
flags |= 0x02;
}
if (isAutomatic) {
flags |= 0x04;
}
buffer.writeByte(flags);
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending update command block packet at %s (command=\"%s\", type=%s, trackOutput=%s, isConditional=%s, isAutomatic=%s)", position.toString(), command, type.name(), trackOutput, isConditional, isAutomatic));
}
public enum CommandBlockType {
SEQUENCE(0),
AUTO(1),
REDSTONE(2);
final int id;
CommandBlockType(int id) {
this.id = id;
}
public static CommandBlockType byId(int id) {
for (CommandBlockType type : values()) {
if (type.getId() == id) {
return type;
}
}
return null;
}
public int getId() {
return id;
}
}
}

View File

@ -0,0 +1,52 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketUpdateCommandBlockMinecart implements ServerboundPacket {
final int entityId;
final String command;
final boolean trackOutput;
public PacketUpdateCommandBlockMinecart(int entityId, String command, boolean trackOutput) {
this.entityId = entityId;
this.command = command;
this.trackOutput = trackOutput;
}
@Override
public OutPacketBuffer write(ProtocolVersion version) {
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_UPDATE_COMMAND_BLOCK_MINECART));
switch (version) {
case VERSION_1_13_2:
buffer.writeVarInt(entityId);
buffer.writeString(command);
buffer.writeBoolean(trackOutput);
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending update minecart command block packet (entityId=%d, command=\"%s\", trackOutput=%s)", entityId, command, trackOutput));
}
}