mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
PacketUnloadChunk, Sound Effect, Named Sound Effect
This commit is contained in:
parent
2fe88acd12
commit
98f24be025
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -23,17 +23,17 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
|||||||
public class PacketSoundEffect implements ClientboundPacket {
|
public class PacketSoundEffect implements ClientboundPacket {
|
||||||
static final float pitchCalc = 100.0F / 63.0F;
|
static final float pitchCalc = 100.0F / 63.0F;
|
||||||
Location location;
|
Location location;
|
||||||
String sound;
|
int sound;
|
||||||
float volume;
|
float volume;
|
||||||
int pitch;
|
int pitch;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(InPacketBuffer buffer) {
|
public boolean read(InPacketBuffer buffer) {
|
||||||
switch (buffer.getVersion()) {
|
switch (buffer.getVersion()) {
|
||||||
case VERSION_1_7_10:
|
case VERSION_1_9_4:
|
||||||
case VERSION_1_8:
|
sound = buffer.readVarInt();
|
||||||
sound = buffer.readString();
|
int category = buffer.readVarInt(); //ToDo: category
|
||||||
location = new Location(buffer.readInteger() * 8, buffer.readInteger() * 8, buffer.readInteger() * 8);
|
location = new Location(buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8, buffer.readFixedPointNumberInteger() * 8);
|
||||||
volume = buffer.readFloat();
|
volume = buffer.readFloat();
|
||||||
pitch = (int) (buffer.readByte() * pitchCalc);
|
pitch = (int) (buffer.readByte() * pitchCalc);
|
||||||
return true;
|
return true;
|
||||||
@ -44,7 +44,7 @@ public class PacketSoundEffect implements ClientboundPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log() {
|
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
|
@Override
|
||||||
@ -63,7 +63,7 @@ public class PacketSoundEffect implements ClientboundPacket {
|
|||||||
return pitch;
|
return pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSound() {
|
public int getSound() {
|
||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -324,7 +324,7 @@ public class PacketHandler {
|
|||||||
//ToDo
|
//ToDo
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(PacketSoundEffect pkg) {
|
public void handle(PacketNamedSoundEffect pkg) {
|
||||||
//ToDo
|
//ToDo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,4 +521,12 @@ public class PacketHandler {
|
|||||||
public void handle(PacketCamera pkg) {
|
public void handle(PacketCamera pkg) {
|
||||||
//ToDo
|
//ToDo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(PacketUnloadChunk pkg) {
|
||||||
|
connection.getPlayer().getWorld().unloadChunk(pkg.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(PacketSoundEffect pkg) {
|
||||||
|
//ToDo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public abstract class Protocol implements ProtocolInterface {
|
|||||||
packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_SIGN, PacketUpdateSignReceiving.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_SIGN, PacketUpdateSignReceiving.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.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_PLAYER_POSITION_AND_ROTATION, PacketPlayerPositionAndRotation.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_ATTACH_ENTITY, PacketAttachEntity.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_ATTACH_ENTITY, PacketAttachEntity.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_USE_BED, PacketUseBed.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_TITLE, PacketTitle.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_COMBAT_EVENT, PacketCombatEvent.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_COMBAT_EVENT, PacketCombatEvent.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_CAMERA, PacketCamera.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() {
|
public static ProtocolVersion getLowestVersionSupported() {
|
||||||
|
@ -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_CHUNK_BULK, 0x26);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EFFECT, 0x28);
|
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_PARTICLE, 0x2A);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);
|
||||||
|
@ -91,7 +91,7 @@ public class Protocol_1_8 extends Protocol {
|
|||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, 0x26);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, 0x26);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EXPLOSION, 0x27);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_EFFECT, 0x28);
|
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_PARTICLE, 0x2A);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, 0x2B);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_WEATHER_ENTITY, 0x2C);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user