2019-08-10 00:15:06 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-08-10 00:15:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.protocol.java;
|
2019-08-10 00:15:06 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
2020-04-16 22:03:01 +00:00
|
|
|
import com.nukkitx.math.vector.Vector3f;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
2020-06-30 16:08:22 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
2021-11-21 18:36:42 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSessionImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
|
|
import org.geysermc.geyser.translator.protocol.Translator;
|
|
|
|
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
|
|
|
import org.geysermc.geyser.util.ChunkUtils;
|
|
|
|
import org.geysermc.geyser.util.DimensionUtils;
|
2019-08-10 00:15:06 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
@Translator(packet = ClientboundRespawnPacket.class)
|
|
|
|
public class JavaRespawnTranslator extends PacketTranslator<ClientboundRespawnPacket> {
|
2019-08-10 00:15:06 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void translate(GeyserSessionImpl session, ClientboundRespawnPacket packet) {
|
2021-07-08 02:44:53 +00:00
|
|
|
SessionPlayerEntity entity = session.getPlayerEntity();
|
2019-08-10 00:15:06 +00:00
|
|
|
|
2021-07-08 02:44:53 +00:00
|
|
|
entity.setHealth(entity.getMaxHealth());
|
|
|
|
entity.getAttributes().put(GeyserAttributeType.HEALTH, entity.createHealthAttribute());
|
2019-10-16 02:47:28 +00:00
|
|
|
|
2021-08-17 00:39:29 +00:00
|
|
|
session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR);
|
|
|
|
session.setOpenInventory(null);
|
|
|
|
session.setClosingInventory(false);
|
2019-10-16 02:47:28 +00:00
|
|
|
|
|
|
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
|
|
|
playerGameTypePacket.setGamemode(packet.getGamemode().ordinal());
|
2020-05-05 15:51:43 +00:00
|
|
|
session.sendUpstreamPacket(playerGameTypePacket);
|
2019-10-27 09:56:47 +00:00
|
|
|
session.setGameMode(packet.getGamemode());
|
2019-10-16 02:47:28 +00:00
|
|
|
|
2020-08-16 17:43:16 +00:00
|
|
|
if (session.isRaining()) {
|
|
|
|
LevelEventPacket stopRainPacket = new LevelEventPacket();
|
|
|
|
stopRainPacket.setType(LevelEventType.STOP_RAINING);
|
|
|
|
stopRainPacket.setData(0);
|
|
|
|
stopRainPacket.setPosition(Vector3f.ZERO);
|
|
|
|
session.sendUpstreamPacket(stopRainPacket);
|
|
|
|
session.setRaining(false);
|
|
|
|
}
|
2020-04-16 22:03:01 +00:00
|
|
|
|
2021-01-04 00:06:20 +00:00
|
|
|
if (session.isThunder()) {
|
|
|
|
LevelEventPacket stopThunderPacket = new LevelEventPacket();
|
|
|
|
stopThunderPacket.setType(LevelEventType.STOP_THUNDERSTORM);
|
|
|
|
stopThunderPacket.setData(0);
|
|
|
|
stopThunderPacket.setPosition(Vector3f.ZERO);
|
|
|
|
session.sendUpstreamPacket(stopThunderPacket);
|
|
|
|
session.setThunder(false);
|
|
|
|
}
|
|
|
|
|
2020-08-10 02:43:57 +00:00
|
|
|
String newDimension = DimensionUtils.getNewDimension(packet.getDimension());
|
2021-01-04 00:06:20 +00:00
|
|
|
if (!session.getDimension().equals(newDimension) || !packet.getWorldName().equals(session.getWorldName())) {
|
2021-07-01 12:48:22 +00:00
|
|
|
// Switching to a new world (based off the world name change); send a fake dimension change
|
|
|
|
if (!packet.getWorldName().equals(session.getWorldName()) && (session.getDimension().equals(newDimension)
|
|
|
|
// Ensure that the player never ever dimension switches to the same dimension - BAD
|
|
|
|
// Can likely be removed if the Above Bedrock Nether Building option can be removed
|
|
|
|
|| DimensionUtils.javaToBedrock(session.getDimension()) == DimensionUtils.javaToBedrock(newDimension))) {
|
2021-01-04 00:06:20 +00:00
|
|
|
String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), newDimension);
|
2020-02-06 04:21:09 +00:00
|
|
|
DimensionUtils.switchDimension(session, fakeDim);
|
2019-12-28 13:35:21 +00:00
|
|
|
}
|
2021-01-04 00:06:20 +00:00
|
|
|
session.setWorldName(packet.getWorldName());
|
|
|
|
DimensionUtils.switchDimension(session, newDimension);
|
2019-08-10 00:15:06 +00:00
|
|
|
}
|
2021-07-15 01:46:56 +00:00
|
|
|
|
2021-10-10 15:21:48 +00:00
|
|
|
ChunkUtils.loadDimensionTag(session, packet.getDimension());
|
2019-08-10 00:15:06 +00:00
|
|
|
}
|
|
|
|
}
|