PacketUnloadChunk, Sound Effect, Named Sound Effect

This commit is contained in:
Bixilon 2020-06-30 00:00:39 +02:00
parent 2fe88acd12
commit 98f24be025
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 150 additions and 11 deletions

View File

@ -0,0 +1,80 @@
/*
* 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.clientbound.play;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketNamedSoundEffect implements ClientboundPacket {
static final float pitchCalc = 100.0F / 63.0F;
Location location;
String sound;
float volume;
int pitch;
@Override
public boolean read(InPacketBuffer buffer) {
switch (buffer.getVersion()) {
case VERSION_1_7_10:
case VERSION_1_8:
sound = buffer.readString();
location = new Location(buffer.readInteger() * 8, buffer.readInteger() * 8, buffer.readInteger() * 8);
volume = buffer.readFloat();
pitch = (int) (buffer.readByte() * pitchCalc);
return true;
case VERSION_1_9_4:
sound = buffer.readString();
int category = buffer.readVarInt(); //ToDo: category
location = new Location(buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8);
volume = buffer.readFloat();
pitch = (int) (buffer.readByte() * pitchCalc);
return true;
}
return false;
}
@Override
public void log() {
Log.protocol(String.format("Play named sound effect %s with volume=%s and pitch=%s at %s", sound, volume, pitch, location.toString()));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public Location getLocation() {
return location;
}
/**
* @return Pitch in Percent * 100
*/
public int getPitch() {
return pitch;
}
public String getSound() {
return sound;
}
public float getVolume() {
return volume;
}
}

View File

@ -23,17 +23,17 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketSoundEffect implements ClientboundPacket {
static final float pitchCalc = 100.0F / 63.0F;
Location location;
String sound;
int sound;
float volume;
int pitch;
@Override
public boolean read(InPacketBuffer buffer) {
switch (buffer.getVersion()) {
case VERSION_1_7_10:
case VERSION_1_8:
sound = buffer.readString();
location = new Location(buffer.readInteger() * 8, buffer.readInteger() * 8, buffer.readInteger() * 8);
case VERSION_1_9_4:
sound = buffer.readVarInt();
int category = buffer.readVarInt(); //ToDo: category
location = new Location(buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8);
volume = buffer.readFloat();
pitch = (int) (buffer.readByte() * pitchCalc);
return true;
@ -44,7 +44,7 @@ public class PacketSoundEffect implements ClientboundPacket {
@Override
public void log() {
Log.protocol(String.format("Play sound effect %s with volume=%s and pitch=%s at %s", sound, volume, pitch, location.toString()));
Log.protocol(String.format("Play sound effect %d with volume=%s and pitch=%s at %s", sound, volume, pitch, location.toString()));
}
@Override
@ -63,7 +63,7 @@ public class PacketSoundEffect implements ClientboundPacket {
return pitch;
}
public String getSound() {
public int getSound() {
return sound;
}

View File

@ -0,0 +1,49 @@
/*
* 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.clientbound.play;
import de.bixilon.minosoft.game.datatypes.world.ChunkLocation;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketUnloadChunk implements ClientboundPacket {
ChunkLocation location;
@Override
public boolean read(InPacketBuffer buffer) {
switch (buffer.getVersion()) {
case VERSION_1_9_4:
location = new ChunkLocation(buffer.readInteger(), buffer.readInteger());
return true;
}
return false;
}
@Override
public void log() {
Log.protocol(String.format("Received unload chunk packet (location=%s)", location.toString()));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public ChunkLocation getLocation() {
return location;
}
}

View File

@ -324,7 +324,7 @@ public class PacketHandler {
//ToDo
}
public void handle(PacketSoundEffect pkg) {
public void handle(PacketNamedSoundEffect pkg) {
//ToDo
}
@ -521,4 +521,12 @@ public class PacketHandler {
public void handle(PacketCamera pkg) {
//ToDo
}
public void handle(PacketUnloadChunk pkg) {
connection.getPlayer().getWorld().unloadChunk(pkg.getLocation());
}
public void handle(PacketSoundEffect pkg) {
//ToDo
}
}

View File

@ -107,7 +107,7 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_SIGN, PacketUpdateSignReceiving.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
packetClassMapping.put(Packets.Clientbound.PLAY_NAMED_SOUND_EFFECT, PacketNamedSoundEffect.class);
packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_POSITION_AND_ROTATION, PacketPlayerPositionAndRotation.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ATTACH_ENTITY, PacketAttachEntity.class);
packetClassMapping.put(Packets.Clientbound.PLAY_USE_BED, PacketUseBed.class);
@ -138,6 +138,8 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_TITLE, PacketTitle.class);
packetClassMapping.put(Packets.Clientbound.PLAY_COMBAT_EVENT, PacketCombatEvent.class);
packetClassMapping.put(Packets.Clientbound.PLAY_CAMERA, PacketCamera.class);
packetClassMapping.put(Packets.Clientbound.PLAY_UNLOAD_CHUNK, PacketUnloadChunk.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
}
public static ProtocolVersion getLowestVersionSupported() {

View File

@ -86,7 +86,7 @@ public class Protocol_1_7_10 extends Protocol {
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, 0x26);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EFFECT, 0x28);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, 0x29);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_NAMED_SOUND_EFFECT, 0x29);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_PARTICLE, 0x2A);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);

View File

@ -91,7 +91,7 @@ public class Protocol_1_8 extends Protocol {
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, 0x26);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EFFECT, 0x28);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, 0x29);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_NAMED_SOUND_EFFECT, 0x29);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_PARTICLE, 0x2A);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);