wip spawning, PacketRespawn

This commit is contained in:
bixilon 2020-06-09 00:44:02 +02:00
parent b398fecf45
commit 7469e56648
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 87 additions and 1 deletions

View File

@ -16,9 +16,9 @@ package de.bixilon.minosoft.objects;
import de.bixilon.minosoft.game.datatypes.GameMode;
import de.bixilon.minosoft.game.datatypes.Slot;
import de.bixilon.minosoft.game.datatypes.Slots;
import de.bixilon.minosoft.game.datatypes.world.World;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.game.datatypes.entities.meta.HumanMetaData;
import de.bixilon.minosoft.game.datatypes.world.World;
import java.util.HashMap;
import java.util.UUID;
@ -37,6 +37,7 @@ public class Player {
short totalExperience;
HumanMetaData metaData;
HashMap<Slots.Inventory, Slot> inventory = new HashMap<>();
boolean spawnConfirmed = false;
public Player(Account acc) {
this.acc = acc;
@ -160,4 +161,12 @@ public class Player {
public void setSlot(Slots.Inventory slot, Slot data) {
inventory.put(slot, data);
}
public boolean isSpawnConfirmed() {
return spawnConfirmed;
}
public void setSpawnConfirmed(boolean spawnConfirmed) {
this.spawnConfirmed = spawnConfirmed;
}
}

View File

@ -0,0 +1,70 @@
/*
* 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.Difficulty;
import de.bixilon.minosoft.game.datatypes.Dimension;
import de.bixilon.minosoft.game.datatypes.GameMode;
import de.bixilon.minosoft.game.datatypes.LevelType;
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;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketRespawn implements ClientboundPacket {
Dimension dimension;
Difficulty difficulty;
GameMode gameMode;
LevelType levelType;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
dimension = Dimension.byId(buffer.readInteger());
difficulty = Difficulty.byId(buffer.readByte());
gameMode = GameMode.byId(buffer.readByte());
levelType = LevelType.byType(buffer.readString());
break;
}
}
@Override
public void log() {
Log.protocol(String.format("Respawn packet received (dimension=%s, difficulty=%s, gamemode=%s, levelType=%s)", dimension.name(), difficulty.name(), gameMode.name(), levelType.name()));
}
public Dimension getDimension() {
return dimension;
}
public Difficulty getDifficulty() {
return difficulty;
}
public GameMode getGameMode() {
return gameMode;
}
public LevelType getLevelType() {
return levelType;
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
}

View File

@ -218,4 +218,10 @@ public class PacketHandler {
public void handle(PacketMultiBlockChange pkg) {
connection.getPlayer().getWorld().getChunk(pkg.getLocation()).setBlocks(pkg.getBlocks());
}
public void handle(PacketRespawn pkg) {
connection.getPlayer().getWorld().setDimension(pkg.getDimension());
connection.getPlayer().setSpawnConfirmed(false);
connection.getPlayer().setGameMode(pkg.getGameMode());
}
}

View File

@ -76,5 +76,6 @@ public interface Protocol {
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_EQUIPMENT, PacketEntityEquipment.class);
packetClassMapping.put(Packets.Clientbound.PLAY_BLOCK_CHANGE, PacketBlockChange.class);
packetClassMapping.put(Packets.Clientbound.PLAY_MULTIBLOCK_CHANGE, PacketMultiBlockChange.class);
packetClassMapping.put(Packets.Clientbound.PLAY_RESPAWN, PacketRespawn.class);
}
}