mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
convert some packets to kotlin, refactor game events (~~states~~), inventory types
This commit is contained in:
parent
c38b8955ef
commit
8e0400b08e
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.data.inventory
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
|
||||
object DefaultInventoryTypes {
|
||||
val CHEST = "minecraft:chest".asResourceLocation()
|
||||
val HORSE = "minecraft:EntityHorse".asResourceLocation()
|
||||
}
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.inventory;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
|
||||
@Deprecated
|
||||
public enum InventoryTypes {
|
||||
CHEST(new ResourceLocation("minecraft:chest")),
|
||||
WORKBENCH(new ResourceLocation("minecraft:crafting_table")),
|
||||
|
@ -18,6 +18,8 @@ import de.bixilon.minosoft.data.entities.EntityObjectType
|
||||
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaType
|
||||
import de.bixilon.minosoft.data.entities.meta.EntityMetaData
|
||||
import de.bixilon.minosoft.data.inventory.InventorySlots
|
||||
import de.bixilon.minosoft.data.mappings.other.ContainerType
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.GameEvent
|
||||
import de.bixilon.minosoft.data.mappings.registry.PerVersionEnumRegistry
|
||||
import de.bixilon.minosoft.data.mappings.registry.PerVersionRegistry
|
||||
import de.bixilon.minosoft.data.mappings.registry.Registry
|
||||
@ -49,6 +51,9 @@ object DefaultRegistries {
|
||||
|
||||
val DEFAULT_PLUGIN_CHANNELS_REGISTRY: PerVersionRegistry<PluginChannel> = PerVersionRegistry()
|
||||
|
||||
val CONTAINER_TYPE_REGISTRY: PerVersionRegistry<ContainerType> = PerVersionRegistry()
|
||||
val GAME_EVENT_REGISTRY: PerVersionRegistry<GameEvent> = PerVersionRegistry()
|
||||
|
||||
|
||||
fun load() {
|
||||
check(!initialized) { "Already initialized!" }
|
||||
@ -76,6 +81,9 @@ object DefaultRegistries {
|
||||
|
||||
BLOCK_ENTITY_META_TYPE_REGISTRY.initialize(registriesJson[ResourceLocation("block_entity_meta_data_types")]!!, BlockEntityMetaType)
|
||||
|
||||
CONTAINER_TYPE_REGISTRY.initialize(registriesJson[ResourceLocation("container_types")]!!, ContainerType)
|
||||
GAME_EVENT_REGISTRY.initialize(registriesJson[ResourceLocation("game_events")]!!, GameEvent)
|
||||
|
||||
initialized = true
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.data.mappings.other
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.registry.RegistryItem
|
||||
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
|
||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
|
||||
data class ContainerType(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
) : RegistryItem {
|
||||
|
||||
override fun toString(): String {
|
||||
return resourceLocation.toString()
|
||||
}
|
||||
|
||||
companion object : ResourceLocationDeserializer<ContainerType> {
|
||||
override fun deserialize(mappings: VersionMapping?, resourceLocation: ResourceLocation, data: JsonObject): ContainerType {
|
||||
return ContainerType(
|
||||
resourceLocation = resourceLocation,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.data.mappings.other.game.event
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.handlers.GameEventHandler
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.handlers.GameMoveChangeGameEventHandler
|
||||
|
||||
object DefaultGameEventHandlers {
|
||||
val GAME_EVENT_HANDLERS: Map<ResourceLocation, GameEventHandler>
|
||||
|
||||
init {
|
||||
val handlers = listOf(
|
||||
GameMoveChangeGameEventHandler,
|
||||
)
|
||||
val ret: MutableMap<ResourceLocation, GameEventHandler> = mutableMapOf()
|
||||
|
||||
for (handler in handlers) {
|
||||
ret[handler.RESOURCE_LOCATION] = handler
|
||||
}
|
||||
GAME_EVENT_HANDLERS = ret.toMap()
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.data.mappings.other.game.event
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.registry.RegistryItem
|
||||
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
|
||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
|
||||
data class GameEvent(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
) : RegistryItem {
|
||||
|
||||
override fun toString(): String {
|
||||
return resourceLocation.toString()
|
||||
}
|
||||
|
||||
companion object : ResourceLocationDeserializer<GameEvent> {
|
||||
override fun deserialize(mappings: VersionMapping?, resourceLocation: ResourceLocation, data: JsonObject): GameEvent {
|
||||
return GameEvent(
|
||||
resourceLocation = resourceLocation,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.data.mappings.other.game.event.handlers
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
|
||||
interface GameEventHandler {
|
||||
val RESOURCE_LOCATION: ResourceLocation
|
||||
|
||||
fun handle(data: Float, connection: PlayConnection)
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.data.mappings.other.game.event.handlers
|
||||
|
||||
import de.bixilon.minosoft.data.Gamemodes
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
|
||||
object GameMoveChangeGameEventHandler : GameEventHandler {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:gamemode_change".asResourceLocation()
|
||||
|
||||
override fun handle(data: Float, connection: PlayConnection) {
|
||||
connection.player.entity.tabListItem.gamemode = Gamemodes.byId(data.toInt())
|
||||
}
|
||||
}
|
@ -34,6 +34,8 @@ import de.bixilon.minosoft.data.mappings.inventory.CreativeModeTab
|
||||
import de.bixilon.minosoft.data.mappings.items.Item
|
||||
import de.bixilon.minosoft.data.mappings.items.ItemRegistry
|
||||
import de.bixilon.minosoft.data.mappings.materials.Material
|
||||
import de.bixilon.minosoft.data.mappings.other.ContainerType
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.GameEvent
|
||||
import de.bixilon.minosoft.data.mappings.particle.ParticleType
|
||||
import de.bixilon.minosoft.data.mappings.registry.*
|
||||
import de.bixilon.minosoft.data.mappings.sounds.SoundEvent
|
||||
@ -93,6 +95,9 @@ class VersionMapping {
|
||||
val blockEntityRegistry: Registry<BlockEntityType> = Registry()
|
||||
val blockEntityMetaDataTypeRegistry: Registry<BlockEntityMetaType> = Registry()
|
||||
|
||||
val containerTypeRegistry: Registry<ContainerType> = Registry()
|
||||
val gameEventRegistry: Registry<GameEvent> = Registry()
|
||||
|
||||
internal val models: MutableMap<ResourceLocation, BlockModel> = mutableMapOf()
|
||||
|
||||
|
||||
@ -165,6 +170,9 @@ class VersionMapping {
|
||||
creativeModeTabRegistry.initialize(pixlyzerData["creative_inventory_tab"]?.asJsonObject, this, CreativeModeTab)
|
||||
|
||||
// id resource location stuff
|
||||
containerTypeRegistry.initialize(pixlyzerData["container_types"]?.asJsonObject, this, ContainerType, alternative = DefaultRegistries.CONTAINER_TYPE_REGISTRY.forVersion(version))
|
||||
gameEventRegistry.initialize(pixlyzerData["game_events"]?.asJsonObject, this, GameEvent, alternative = DefaultRegistries.GAME_EVENT_REGISTRY.forVersion(version))
|
||||
|
||||
soundEventRegistry.initialize(pixlyzerData["sound_events"]?.asJsonObject, this, SoundEvent)
|
||||
particleTypeRegistry.initialize(pixlyzerData["particles"]?.asJsonObject, this, ParticleType)
|
||||
materialRegistry.initialize(pixlyzerData["materials"]?.asJsonObject, this, Material)
|
||||
|
@ -10,33 +10,17 @@
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.GameEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.play.GameEventS2CP
|
||||
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.play.PacketChangeGameState;
|
||||
class ChangeGameStateEvent(
|
||||
connection: PlayConnection,
|
||||
val event: GameEvent,
|
||||
val data: Float,
|
||||
) : PlayConnectionEvent(connection) {
|
||||
|
||||
public class ChangeGameStateEvent extends PlayConnectionEvent {
|
||||
private final PacketChangeGameState.Reason reason;
|
||||
private final float value;
|
||||
|
||||
public ChangeGameStateEvent(PlayConnection connection, PacketChangeGameState.Reason reason, float value) {
|
||||
super(connection);
|
||||
this.reason = reason;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ChangeGameStateEvent(PlayConnection connection, PacketChangeGameState pkg) {
|
||||
super(connection);
|
||||
this.reason = pkg.getReason();
|
||||
this.value = pkg.getFloatValue();
|
||||
}
|
||||
|
||||
public PacketChangeGameState.Reason getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return this.value;
|
||||
}
|
||||
constructor(connection: PlayConnection, pkg: GameEventS2CP) : this(connection, pkg.event, pkg.data)
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.data.inventory.DefaultInventoryTypes
|
||||
import de.bixilon.minosoft.data.mappings.other.ContainerType
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.*
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class ContainerOpenS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val containerId: Byte = buffer.readByte()
|
||||
val containerType: ContainerType = if (buffer.versionId < V_14W03B) {
|
||||
buffer.connection.mapping.containerTypeRegistry.get(buffer.readUnsignedByte())
|
||||
} else {
|
||||
buffer.connection.mapping.containerTypeRegistry.get(buffer.readResourceLocation())!!
|
||||
}
|
||||
val title: ChatComponent = buffer.readChatComponent()
|
||||
val slotCount: Int = if (buffer.versionId < V_19W02A || buffer.versionId >= V_19W11A) {
|
||||
buffer.readUnsignedByte()
|
||||
} else {
|
||||
// ToDo: load from pixlyzer
|
||||
0
|
||||
}
|
||||
val hasTitle: Boolean = if (buffer.versionId > V_14W03B) {
|
||||
buffer.readBoolean()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
var entityId: Int? = if (containerType.resourceLocation == DefaultInventoryTypes.HORSE || buffer.versionId < V_14W03B) {
|
||||
buffer.readInt()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
// ToDo: connection.getPlayer().createInventory(getInventoryProperties());
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Container open (containerId=$containerId, containerType=$containerType, title=\"$title\", slotCount=$slotCount, hasTitle=$hasTitle, entityId=$entityId)" }
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.DefaultGameEventHandlers
|
||||
import de.bixilon.minosoft.data.mappings.other.game.event.GameEvent
|
||||
import de.bixilon.minosoft.modding.event.events.ChangeGameStateEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class GameEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val event: GameEvent = buffer.connection.mapping.gameEventRegistry.get(buffer.readUnsignedByte())
|
||||
val data: Float = buffer.readFloat()
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val event = ChangeGameStateEvent(connection, this)
|
||||
if (connection.fireEvent(event)) {
|
||||
return
|
||||
}
|
||||
|
||||
DefaultGameEventHandlers.GAME_EVENT_HANDLERS[this.event.resourceLocation]?.handle(data, connection)
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Game event (event=$event, data=$data)" }
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.data.Gamemodes;
|
||||
import de.bixilon.minosoft.data.VersionValueMap;
|
||||
import de.bixilon.minosoft.modding.event.events.ChangeGameStateEvent;
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.*;
|
||||
|
||||
public class PacketChangeGameState extends PlayS2CPacket {
|
||||
private final Reason reason;
|
||||
private final float value;
|
||||
|
||||
public PacketChangeGameState(PlayInByteBuffer buffer) {
|
||||
this.reason = Reason.byId(buffer.readByte(), buffer.getVersionId());
|
||||
this.value = buffer.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayConnection connection) {
|
||||
ChangeGameStateEvent event = new ChangeGameStateEvent(connection, this);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.game(switch (getReason()) {
|
||||
case START_RAINING -> "Received weather packet: Starting rain...";
|
||||
case STOP_RAINING -> "Received weather packet: Stopping rain...";
|
||||
case CHANGE_GAMEMODE -> String.format("Received game mode change: Now in %s", Gamemodes.byId(getIntValue()));
|
||||
default -> "";
|
||||
});
|
||||
|
||||
switch (getReason()) {
|
||||
case STOP_RAINING -> connection.getWorld().setRaining(false);
|
||||
case START_RAINING -> connection.getWorld().setRaining(true);
|
||||
case CHANGE_GAMEMODE -> connection.getPlayer().getEntity().getTabListItem().setGamemode(Gamemodes.byId(getIntValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Received game status change (%s)", getReason()));
|
||||
}
|
||||
|
||||
public Reason getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return (int) this.value;
|
||||
}
|
||||
|
||||
public enum Reason {
|
||||
NO_RESPAWN_BLOCK_AVAILABLE(Map.of(LOWEST_VERSION_SUPPORTED, 0)),
|
||||
START_RAINING(Map.of(LOWEST_VERSION_SUPPORTED, 1, V_1_14_4, 2, V_1_15_2, 1)), // ToDo: when exactly did these 2 switch?
|
||||
STOP_RAINING(Map.of(LOWEST_VERSION_SUPPORTED, 2, V_1_14_4, 1, V_1_15_2, 2)),
|
||||
CHANGE_GAMEMODE(Map.of(LOWEST_VERSION_SUPPORTED, 3)),
|
||||
ENTER_CREDITS(Map.of(LOWEST_VERSION_SUPPORTED, 4)),
|
||||
DEMO_MESSAGES(Map.of(LOWEST_VERSION_SUPPORTED, 5)),
|
||||
ARROW_HITTING_PLAYER(Map.of(LOWEST_VERSION_SUPPORTED, 6)),
|
||||
RAIN_LEVEL_CHANGE(Map.of(LOWEST_VERSION_SUPPORTED, 7)),
|
||||
THUNDER_LEVEL_CHANGE(Map.of(LOWEST_VERSION_SUPPORTED, 8)),
|
||||
PUFFERFISH_STING(Map.of(LOWEST_VERSION_SUPPORTED, 9)),
|
||||
GUARDIAN_ELDER_EFFECT(Map.of(LOWEST_VERSION_SUPPORTED, 10)),
|
||||
IMMEDIATE_RESPAWN(Map.of(V_19W36A, 11));
|
||||
|
||||
private final VersionValueMap<Integer> valueMap;
|
||||
|
||||
Reason(Map<Integer, Integer> values) {
|
||||
this.valueMap = new VersionValueMap<>(values);
|
||||
}
|
||||
|
||||
public static Reason byId(int id, int versionId) {
|
||||
for (Reason reason : values()) {
|
||||
if (reason.getId(versionId) == id) {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId(Integer versionId) {
|
||||
Integer ret = this.valueMap.get(versionId);
|
||||
if (ret == null) {
|
||||
return -2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.data.inventory.InventoryProperties;
|
||||
import de.bixilon.minosoft.data.inventory.InventoryTypes;
|
||||
import de.bixilon.minosoft.data.text.ChatComponent;
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.*;
|
||||
|
||||
public class PacketOpenWindow extends PlayS2CPacket {
|
||||
private final byte windowId;
|
||||
private final InventoryTypes type;
|
||||
private ChatComponent title;
|
||||
private byte slotCount;
|
||||
private int entityId;
|
||||
|
||||
public PacketOpenWindow(PlayInByteBuffer buffer) {
|
||||
if (buffer.getVersionId() < V_14W03B) {
|
||||
this.windowId = buffer.readByte();
|
||||
this.type = InventoryTypes.byId(buffer.readUnsignedByte());
|
||||
this.title = buffer.readChatComponent();
|
||||
this.slotCount = buffer.readByte();
|
||||
if (!buffer.readBoolean()) {
|
||||
// no custom name
|
||||
this.title = null;
|
||||
}
|
||||
this.entityId = buffer.readInt();
|
||||
return;
|
||||
}
|
||||
this.windowId = buffer.readByte();
|
||||
this.type = InventoryTypes.byResourceLocation(buffer.readResourceLocation());
|
||||
this.title = buffer.readChatComponent();
|
||||
if (buffer.getVersionId() < V_19W02A || buffer.getVersionId() >= V_19W11A) {
|
||||
this.slotCount = buffer.readByte();
|
||||
}
|
||||
if (this.type == InventoryTypes.HORSE) {
|
||||
this.entityId = buffer.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayConnection connection) {
|
||||
// ToDo: connection.getPlayer().createInventory(getInventoryProperties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Received inventory open packet (windowId=%d, type=%s, title=%s, entityId=%d, slotCount=%d)", this.windowId, this.type, this.title, this.entityId, this.slotCount));
|
||||
}
|
||||
|
||||
public byte getSlotCount() {
|
||||
return this.slotCount;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
public ChatComponent getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public InventoryProperties getInventoryProperties() {
|
||||
return new InventoryProperties(getWindowId(), getType(), this.title, this.slotCount);
|
||||
}
|
||||
|
||||
public byte getWindowId() {
|
||||
return this.windowId;
|
||||
}
|
||||
|
||||
public InventoryTypes getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
@ -182,7 +182,7 @@ class PacketTypes {
|
||||
PLAY_ENTITY_STATUS({ EntityStatusS2CP(it) }),
|
||||
PLAY_EXPLOSION({ ExplosionS2CP(it) }),
|
||||
PLAY_CHUNK_UNLOAD({ ChunkUnloadS2CP(it) }),
|
||||
PLAY_CHANGE_GAME_STATE({ PacketChangeGameState(it) }),
|
||||
PLAY_GAME_EVENT({ GameEventS2CP(it) }),
|
||||
PLAY_OPEN_HORSE_WINDOW({ PacketOpenHorseWindow(it) }),
|
||||
PLAY_HEARTBEAT({ HeartbeatS2CP(it) }),
|
||||
PLAY_CHUNK_DATA({ ChunkDataS2CP(it) }),
|
||||
@ -197,7 +197,7 @@ class PacketTypes {
|
||||
PLAY_ENTITY_RELATIVE_MOVE({ EntityRelativeMoveS2CP(it) }),
|
||||
PLAY_VEHICLE_MOVE({ VehicleMoveS2CP(it) }),
|
||||
PLAY_BOOK_OPEN({ BookOpenS2CP(it) }),
|
||||
PLAY_OPEN_WINDOW({ PacketOpenWindow(it) }),
|
||||
PLAY_CONTAINER_OPEN({ ContainerOpenS2CP(it) }),
|
||||
PLAY_SIGN_EDITOR_OPEN({ SignEditorOpenS2CP(it) }),
|
||||
PLAY_CRAFT_RECIPE_RESPONSE({ PacketCraftRecipeResponse(it) }),
|
||||
PLAY_PLAYER_ABILITIES({ PlayerAbilitiesS2CP(it) }),
|
||||
|
@ -472,5 +472,120 @@
|
||||
"id": 14
|
||||
}
|
||||
}
|
||||
},
|
||||
"minecraft:container_types": {
|
||||
"0": {
|
||||
"minecraft:chest": {
|
||||
"id": 0
|
||||
},
|
||||
"minecraft:crafting_table": {
|
||||
"id": 1
|
||||
},
|
||||
"minecraft:furnace": {
|
||||
"id": 2
|
||||
},
|
||||
"minecraft:dispenser": {
|
||||
"id": 3
|
||||
},
|
||||
"minecraft:enchanting_table": {
|
||||
"id": 4
|
||||
},
|
||||
"minecraft:brewing_stand": {
|
||||
"id": 5
|
||||
},
|
||||
"minecraft:villager": {
|
||||
"id": 6
|
||||
},
|
||||
"minecraft:beacon": {
|
||||
"id": 7
|
||||
},
|
||||
"minecraft:anvil": {
|
||||
"id": 8
|
||||
},
|
||||
"minecraft:hopper": {
|
||||
"id": 9
|
||||
},
|
||||
"minecraft:dropper": {
|
||||
"id": 9
|
||||
},
|
||||
"minecraft:EntityHorse": {
|
||||
"id": 9
|
||||
}
|
||||
}
|
||||
},
|
||||
"minecraft:game_events": {
|
||||
"0": {
|
||||
"minecraft:bed_break": {
|
||||
"id": 0
|
||||
},
|
||||
"minecraft:rain_start": {
|
||||
"id": 1
|
||||
},
|
||||
"minecraft:rain_stop": {
|
||||
"id": 2
|
||||
},
|
||||
"minecraft:gamemode_change": {
|
||||
"id": 3
|
||||
},
|
||||
"minecraft:show_credits": {
|
||||
"id": 4
|
||||
},
|
||||
"minecraft:hide_demo_messages": {
|
||||
"id": 5
|
||||
},
|
||||
"minecraft:arrow_player_hit": {
|
||||
"id": 6
|
||||
},
|
||||
"minecraft:rain_level_set": {
|
||||
"id": 7
|
||||
},
|
||||
"minecraft:thunder_level_Set": {
|
||||
"id": 8
|
||||
},
|
||||
"minecraft:pufferfish_sting": {
|
||||
"id": 9
|
||||
},
|
||||
"minecraft:elder_guardian_effect": {
|
||||
"id": 10
|
||||
}
|
||||
},
|
||||
"552": {
|
||||
"minecraft:bed_break": {
|
||||
"id": 0
|
||||
},
|
||||
"minecraft:rain_start": {
|
||||
"id": 1
|
||||
},
|
||||
"minecraft:rain_stop": {
|
||||
"id": 2
|
||||
},
|
||||
"minecraft:gamemode_change": {
|
||||
"id": 3
|
||||
},
|
||||
"minecraft:show_credits": {
|
||||
"id": 4
|
||||
},
|
||||
"minecraft:hide_demo_messages": {
|
||||
"id": 5
|
||||
},
|
||||
"minecraft:arrow_player_hit": {
|
||||
"id": 6
|
||||
},
|
||||
"minecraft:rain_level_set": {
|
||||
"id": 7
|
||||
},
|
||||
"minecraft:thunder_level_Set": {
|
||||
"id": 8
|
||||
},
|
||||
"minecraft:pufferfish_sting": {
|
||||
"id": 9
|
||||
},
|
||||
"minecraft:elder_guardian_effect": {
|
||||
"id": 10
|
||||
},
|
||||
"minecraft:immediate_respawn": {
|
||||
"id": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user