2019-07-17 18:00:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 GeyserMC. http://geysermc.org
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
package org.geysermc.connector.network.translators;
|
|
|
|
|
|
|
|
import com.flowpowered.math.vector.Vector2f;
|
2019-07-17 01:05:10 +00:00
|
|
|
import com.flowpowered.math.vector.Vector2i;
|
2019-07-11 22:39:28 +00:00
|
|
|
import com.flowpowered.math.vector.Vector3f;
|
|
|
|
import com.flowpowered.math.vector.Vector3i;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
2019-07-17 01:05:10 +00:00
|
|
|
import com.nukkitx.nbt.NbtUtils;
|
|
|
|
import com.nukkitx.nbt.stream.NBTOutputStream;
|
|
|
|
import com.nukkitx.nbt.tag.CompoundTag;
|
|
|
|
import com.nukkitx.network.VarInts;
|
2019-07-11 22:39:28 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.GameRule;
|
2019-07-13 19:00:51 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.*;
|
2019-07-17 01:05:10 +00:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
2019-07-19 00:11:58 +00:00
|
|
|
import org.geysermc.connector.utils.GeyserUtils;
|
2019-07-11 22:39:28 +00:00
|
|
|
import org.geysermc.connector.utils.Toolbox;
|
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
public class TranslatorsInit {
|
|
|
|
public static void start() {
|
2019-07-13 19:00:51 +00:00
|
|
|
addLoginPackets();
|
2019-07-11 22:39:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void addLoginPackets() {
|
2019-07-17 01:05:10 +00:00
|
|
|
Registry.add(ServerJoinGamePacket.class, (packet, session) -> {
|
2019-07-13 19:00:51 +00:00
|
|
|
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
bedrockPacket.setUniqueEntityId(packet.getEntityId());
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
session.getUpstream().sendPacketImmediately(bedrockPacket);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
StartGamePacket startGamePacket = new StartGamePacket();
|
2019-07-17 01:05:10 +00:00
|
|
|
startGamePacket.setUniqueEntityId(packet.getEntityId());
|
|
|
|
startGamePacket.setRuntimeEntityId(packet.getEntityId());
|
|
|
|
startGamePacket.setPlayerGamemode(packet.getGameMode().ordinal());
|
2019-07-13 19:00:51 +00:00
|
|
|
startGamePacket.setPlayerPosition(new Vector3f(0, 0, 0));
|
2019-07-11 22:39:28 +00:00
|
|
|
startGamePacket.setRotation(new Vector2f(1, 1));
|
|
|
|
|
|
|
|
startGamePacket.setSeed(1111);
|
|
|
|
startGamePacket.setDimensionId(0);
|
|
|
|
startGamePacket.setGeneratorId(0);
|
2019-07-17 01:05:10 +00:00
|
|
|
startGamePacket.setLevelGamemode(packet.getGameMode().ordinal());
|
2019-07-11 22:39:28 +00:00
|
|
|
startGamePacket.setDifficulty(1);
|
2019-07-13 19:00:51 +00:00
|
|
|
startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0));
|
2019-07-11 22:39:28 +00:00
|
|
|
startGamePacket.setAcheivementsDisabled(true);
|
|
|
|
startGamePacket.setTime(1300);
|
|
|
|
startGamePacket.setEduLevel(false);
|
|
|
|
startGamePacket.setEduFeaturesEnabled(false);
|
|
|
|
startGamePacket.setRainLevel(0);
|
|
|
|
startGamePacket.setLightningLevel(0);
|
|
|
|
startGamePacket.setMultiplayerGame(false);
|
|
|
|
startGamePacket.setBroadcastingToLan(true);
|
|
|
|
startGamePacket.getGamerules().add((new GameRule("showcoordinates", true)));
|
|
|
|
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
|
|
|
startGamePacket.setXblBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
|
|
|
startGamePacket.setCommandsEnabled(true);
|
|
|
|
startGamePacket.setTexturePacksRequired(false);
|
|
|
|
startGamePacket.setBonusChestEnabled(false);
|
|
|
|
startGamePacket.setStartingWithMap(false);
|
|
|
|
startGamePacket.setTrustingPlayers(true);
|
|
|
|
startGamePacket.setDefaultPlayerPermission(1);
|
|
|
|
startGamePacket.setServerChunkTickRange(4);
|
|
|
|
startGamePacket.setBehaviorPackLocked(false);
|
|
|
|
startGamePacket.setResourcePackLocked(false);
|
|
|
|
startGamePacket.setFromLockedWorldTemplate(false);
|
|
|
|
startGamePacket.setUsingMsaGamertagsOnly(false);
|
|
|
|
startGamePacket.setFromWorldTemplate(false);
|
|
|
|
startGamePacket.setWorldTemplateOptionLocked(false);
|
|
|
|
|
|
|
|
startGamePacket.setLevelId("oerjhii");
|
|
|
|
startGamePacket.setWorldName("world");
|
|
|
|
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
|
|
|
startGamePacket.setCurrentTick(1);
|
|
|
|
startGamePacket.setEnchantmentSeed(1);
|
|
|
|
startGamePacket.setMultiplayerCorrelationId("");
|
|
|
|
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
|
2019-07-17 01:05:10 +00:00
|
|
|
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
session.getUpstream().sendPacketImmediately(startGamePacket);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-20 20:49:58 +00:00
|
|
|
BiomeDefinitionListPacket biomeDefListPacket = new BiomeDefinitionListPacket();
|
|
|
|
session.getUpstream().sendPacketImmediately(biomeDefListPacket);
|
|
|
|
|
|
|
|
AvailableEntityIdentifiersPacket availableEntityPacket = new AvailableEntityIdentifiersPacket();
|
|
|
|
session.getUpstream().sendPacketImmediately(availableEntityPacket);
|
|
|
|
|
2019-07-13 19:00:51 +00:00
|
|
|
Vector3f pos = new Vector3f(0, 0, 0);
|
|
|
|
|
|
|
|
int chunkX = pos.getFloorX() >> 4;
|
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
int chunkZ = pos.getFloorZ() >> 4;
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
for (int x = -3; x < 3; x++) {
|
2019-07-13 19:00:51 +00:00
|
|
|
|
|
|
|
for (int z = -3; z < 3; z++) {
|
|
|
|
|
|
|
|
LevelChunkPacket data = new LevelChunkPacket();
|
2019-07-17 01:05:10 +00:00
|
|
|
data.setChunkX(chunkX + x);
|
2019-07-13 19:00:51 +00:00
|
|
|
data.setChunkZ(chunkZ + z);
|
|
|
|
|
2019-07-19 00:11:58 +00:00
|
|
|
ByteBuf buf = Unpooled.buffer();
|
|
|
|
|
2019-07-20 20:49:58 +00:00
|
|
|
data.setSubChunksLength(16);
|
2019-07-19 00:11:58 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < 1; i++) {
|
|
|
|
GeyserUtils.writeEmptySubChunk(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < 256; i++) {
|
|
|
|
buf.writeByte(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.writeZero(1);
|
|
|
|
|
|
|
|
VarInts.writeInt(buf, 0);
|
|
|
|
|
|
|
|
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
NBTOutputStream stream = NbtUtils.createNetworkWriter(s);
|
|
|
|
|
|
|
|
try {
|
|
|
|
stream.write(new CompoundTag("", new HashMap<>()));
|
|
|
|
s.close();
|
|
|
|
stream.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.writeBytes(s.toByteArray());
|
|
|
|
|
|
|
|
data.setData(new byte[0]);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
session.getUpstream().sendPacketImmediately(data);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
PlayStatusPacket packet1 = new PlayStatusPacket();
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
packet1.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
2019-07-13 19:00:51 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
session.getUpstream().sendPacket(packet1);
|
2019-07-11 22:39:28 +00:00
|
|
|
});
|
|
|
|
}
|
2019-07-17 01:05:10 +00:00
|
|
|
|
|
|
|
private static byte[] empty(byte[] b, Vector2i pos) {
|
|
|
|
ByteBuf by = Unpooled.buffer();
|
|
|
|
|
2019-07-19 00:11:58 +00:00
|
|
|
GeyserUtils.writePEChunkCoord(by, pos);
|
2019-07-17 01:05:10 +00:00
|
|
|
|
|
|
|
return by.array();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class CanWriteToBB extends ByteArrayOutputStream {
|
|
|
|
|
|
|
|
CanWriteToBB() {
|
|
|
|
super(8192);
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeTo(ByteBuf buf) {
|
|
|
|
buf.writeBytes(super.buf, 0, super.count);
|
|
|
|
}
|
|
|
|
}
|
2019-07-11 22:39:28 +00:00
|
|
|
}
|