Initial update for 21w17a

This commit is contained in:
Camotoy 2021-05-01 23:19:49 -04:00
parent 1301cd9c30
commit e692b53c3f
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
23 changed files with 1806 additions and 1415 deletions

View file

@ -122,7 +122,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>26201a4</version>
<version>21w17a-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>

View file

@ -161,6 +161,7 @@ public enum EntityType {
ZOGLIN(ZoglinEntity.class, 126, 1.4f, 1.3965f, 1.3965f, 0f, "minecraft:zoglin"),
PIGLIN(PiglinEntity.class, 123, 1.95f, 0.6f, 0.6f, 0f, "minecraft:piglin"),
PIGLIN_BRUTE(BasePiglinEntity.class, 127, 1.95f, 0.6f, 0.6f, 0f, "minecraft:piglin_brute"),
//TODO: GOAT AXOLOTL GLOW_SQUID GLOW_ITEM_FRAME MARKER
/**
* Item frames are handled differently since they are a block in Bedrock.

View file

@ -66,9 +66,6 @@ public class Inventory {
@Setter
protected long holderId = -1;
@Getter
protected short transactionId = 0;
@Getter
@Setter
private boolean pending = false;
@ -114,10 +111,6 @@ public class Inventory {
}
}
public short getNextTransactionId() {
return ++transactionId;
}
@Override
public String toString() {
return "Inventory{" +
@ -127,7 +120,6 @@ public class Inventory {
", items=" + Arrays.toString(items) +
", holderPosition=" + holderPosition +
", holderId=" + holderId +
", transactionId=" + transactionId +
'}';
}
}

View file

@ -26,9 +26,6 @@
package org.geysermc.connector.network;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.v419.Bedrock_v419;
import com.nukkitx.protocol.bedrock.v422.Bedrock_v422;
import com.nukkitx.protocol.bedrock.v428.Bedrock_v428;
import com.nukkitx.protocol.bedrock.v431.Bedrock_v431;
import java.util.ArrayList;
@ -49,13 +46,6 @@ public class BedrockProtocol {
public static final List<BedrockPacketCodec> SUPPORTED_BEDROCK_CODECS = new ArrayList<>();
static {
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v419.V419_CODEC.toBuilder()
.minecraftVersion("1.16.100/1.16.101") // We change this as 1.16.100.60 is a beta
.build());
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v422.V422_CODEC.toBuilder()
.minecraftVersion("1.16.200/1.16.201")
.build());
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v428.V428_CODEC);
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
}

View file

@ -30,7 +30,6 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.data.ExperimentData;
import com.nukkitx.protocol.bedrock.data.ResourcePackType;
import com.nukkitx.protocol.bedrock.packet.*;
import com.nukkitx.protocol.bedrock.v428.Bedrock_v428;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
@ -38,7 +37,6 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.AdvancementsCache;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.world.block.BlockTranslator1_16_100;
import org.geysermc.connector.network.translators.world.block.BlockTranslator1_16_210;
import org.geysermc.connector.utils.*;
@ -74,8 +72,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
session.getUpstream().getSession().setPacketCodec(packetCodec);
// Set the block translation based off of version
session.setBlockTranslator(packetCodec.getProtocolVersion() >= Bedrock_v428.V428_CODEC.getProtocolVersion()
? BlockTranslator1_16_210.INSTANCE : BlockTranslator1_16_100.INSTANCE);
session.setBlockTranslator(BlockTranslator1_16_210.INSTANCE);
LoginEncryptionUtils.encryptPlayerConnection(connector, session, loginPacket);
@ -140,6 +137,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
stackPacket.getExperiments().add(new ExperimentData("data_driven_items", true));
}
stackPacket.getExperiments().add(new ExperimentData("caves_and_cliffs", true));
session.sendUpstreamPacket(stackPacket);
break;

View file

@ -807,7 +807,7 @@ public class GeyserSession implements CommandSender {
@Override
public void packetError(PacketErrorEvent event) {
connector.getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.network.downstream_error", event.getCause().getMessage()));
if (connector.getConfig().isDebugMode())
//if (connector.getConfig().isDebugMode()) //TODO don't leave this uncommented
event.getCause().printStackTrace();
event.setSuppress(true);
}
@ -1053,7 +1053,6 @@ public class GeyserSession implements CommandSender {
startGamePacket.setItemEntries(ItemRegistry.ITEMS);
startGamePacket.setVanillaVersion("*");
startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT); // can be removed once 1.16.200 support is dropped
SyncedPlayerMovementSettings settings = new SyncedPlayerMovementSettings();
settings.setMovementMode(AuthoritativeMovementMode.CLIENT);
@ -1061,6 +1060,8 @@ public class GeyserSession implements CommandSender {
settings.setServerAuthoritativeBlockBreaking(false);
startGamePacket.setPlayerMovementSettings(settings);
startGamePacket.getExperiments().add(new ExperimentData("caves_and_cliffs", true));
upstream.sendPacket(startGamePacket);
}

View file

@ -27,7 +27,6 @@ package org.geysermc.connector.network.translators.inventory.click;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.window.WindowAction;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
@ -43,7 +42,9 @@ import org.geysermc.connector.network.translators.inventory.translators.Crafting
import org.geysermc.connector.network.translators.inventory.translators.PlayerInventoryTranslator;
import org.geysermc.connector.utils.InventoryUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class ClickPlan {
private final List<ClickAction> plan = new ArrayList<>();
@ -116,22 +117,23 @@ public class ClickPlan {
clickedItemStack = getItem(action.slot).getItemStack();
}
short actionId = inventory.getNextTransactionId();
Int2ObjectMap<ItemStack> affectedSlots = new Int2ObjectOpenHashMap<>();
for (Int2ObjectMap.Entry<GeyserItemStack> simulatedSlot : simulatedItems.int2ObjectEntrySet()) {
affectedSlots.put(simulatedSlot.getIntKey(), simulatedSlot.getValue().getItemStack());
}
ClientWindowActionPacket clickPacket = new ClientWindowActionPacket(
inventory.getId(),
actionId,
action.slot,
clickedItemStack,
action.click.windowAction,
action.click.actionParam
action.click.actionParam,
clickedItemStack,
affectedSlots
);
simulateAction(action);
session.sendDownstreamPacket(clickPacket);
if (clickedItemStack == InventoryUtils.REFRESH_ITEM || action.force) {
session.sendDownstreamPacket(new ClientConfirmTransactionPacket(inventory.getId(), actionId, true));
}
}
session.getPlayerInventory().setCursor(simulatedCursor, session);

View file

@ -26,21 +26,14 @@
package org.geysermc.connector.network.translators.inventory.translators;
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.*;
import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftResultsDeprecatedStackRequestActionData;
import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData;
import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionType;
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
import org.geysermc.connector.inventory.AnvilContainer;
import org.geysermc.connector.inventory.GeyserItemStack;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
import org.geysermc.connector.network.translators.item.ItemTranslator;
public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
public AnvilInventoryTranslator() {
@ -48,55 +41,6 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
"minecraft:chipped_anvil", "minecraft:damaged_anvil");
}
/* 1.16.100 support start */
@Override
@Deprecated
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
return action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED;
}
@Override
@Deprecated
public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) {
if (!(request.getActions()[1] instanceof CraftResultsDeprecatedStackRequestActionData)) {
// Just silently log an error
session.getConnector().getLogger().debug("Something isn't quite right with taking an item out of an anvil.");
return translateRequest(session, inventory, request);
}
CraftResultsDeprecatedStackRequestActionData actionData = (CraftResultsDeprecatedStackRequestActionData) request.getActions()[1];
ItemData resultItem = actionData.getResultItems()[0];
if (resultItem.getTag() != null) {
NbtMap displayTag = resultItem.getTag().getCompound("display");
if (displayTag != null && displayTag.containsKey("Name")) {
ItemData sourceSlot = inventory.getItem(0).getItemData(session);
if (sourceSlot.getTag() != null) {
NbtMap oldDisplayTag = sourceSlot.getTag().getCompound("display");
if (oldDisplayTag != null && oldDisplayTag.containsKey("Name")) {
if (!displayTag.getString("Name").equals(oldDisplayTag.getString("Name"))) {
// Name has changed
sendRenamePacket(session, inventory, resultItem, displayTag.getString("Name"));
}
} else {
// No display tag on the old item
sendRenamePacket(session, inventory, resultItem, displayTag.getString("Name"));
}
} else {
// New NBT tag
sendRenamePacket(session, inventory, resultItem, displayTag.getString("Name"));
}
}
}
return translateRequest(session, inventory, request);
}
private void sendRenamePacket(GeyserSession session, Inventory inventory, ItemData outputItem, String name) {
session.sendDownstreamPacket(new ClientRenameItemPacket(name));
inventory.setItem(2, GeyserItemStack.from(ItemTranslator.translateToJava(outputItem)), session);
}
/* 1.16.100 support end */
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
switch (slotInfoData.getContainer()) {

View file

@ -93,7 +93,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
// We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
String locale = session.getLocale();
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, SKIN_PART_VALUES, HandPreference.RIGHT_HAND);
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, SKIN_PART_VALUES, HandPreference.RIGHT_HAND, false);
session.sendDownstreamPacket(clientSettingsPacket);
session.sendDownstreamPacket(new ClientPluginMessagePacket("minecraft:brand", PluginMessageUtils.getGeyserBrandData()));

View file

@ -31,7 +31,6 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket;
import com.nukkitx.protocol.bedrock.v428.Bedrock_v428;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.living.ArmorStandEntity;
@ -88,13 +87,8 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
if (entity.getEntityType() == EntityType.BOAT) {
passenger.getMetadata().put(EntityData.RIDER_ROTATION_LOCKED, (byte) 1);
passenger.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 90f);
// Can be removed once 1.16.200 to 1.16.201 support is dropped
if (session.getUpstream().getSession().getPacketCodec().getProtocolVersion() >= Bedrock_v428.V428_CODEC.getProtocolVersion()) {
passenger.getMetadata().put(EntityData.RIDER_MIN_ROTATION, 1f);
passenger.getMetadata().put(EntityData.RIDER_ROTATION_OFFSET, -90f);
} else {
passenger.getMetadata().put(EntityData.RIDER_MIN_ROTATION, -90f);
}
} else {
passenger.getMetadata().put(EntityData.RIDER_ROTATION_LOCKED, (byte) 0);
passenger.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 0f);
@ -123,9 +117,7 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
passenger.getMetadata().put(EntityData.RIDER_ROTATION_LOCKED, (byte) 0);
passenger.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 0f);
passenger.getMetadata().put(EntityData.RIDER_MIN_ROTATION, 0f);
if (session.getUpstream().getSession().getPacketCodec().getProtocolVersion() >= Bedrock_v428.V428_CODEC.getProtocolVersion()) {
passenger.getMetadata().put(EntityData.RIDER_ROTATION_OFFSET, 0f);
}
this.updateOffset(passenger, entity, session, false, false, (packet.getPassengerIds().length > 1));
} else {

View file

@ -25,25 +25,22 @@
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerRemoveEntityPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
@Translator(packet = ServerEntityDestroyPacket.class)
public class JavaEntityDestroyTranslator extends PacketTranslator<ServerEntityDestroyPacket> {
@Translator(packet = ServerRemoveEntityPacket.class)
public class JavaRemoveEntityTranslator extends PacketTranslator<ServerRemoveEntityPacket> {
@Override
public void translate(ServerEntityDestroyPacket packet, GeyserSession session) {
for (int entityId : packet.getEntityIds()) {
Entity entity = session.getEntityCache().getEntityByJavaId(entityId);
public void translate(ServerRemoveEntityPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (entity != null) {
session.getEntityCache().removeEntity(entity, false);
}
}
}
}

View file

@ -23,37 +23,23 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.world.block;
package org.geysermc.connector.network.translators.java.title;
import com.google.common.collect.ImmutableSet;
import com.nukkitx.nbt.NbtMapBuilder;
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerClearTitlesPacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import java.util.Set;
public class BlockTranslator1_16_100 extends BlockTranslator {
private static final Set<String> CORRECTED_STATES = ImmutableSet.of("minecraft:stripped_warped_stem",
"minecraft:stripped_warped_hyphae", "minecraft:stripped_crimson_stem", "minecraft:stripped_crimson_hyphae");
public static final BlockTranslator1_16_100 INSTANCE = new BlockTranslator1_16_100();
public BlockTranslator1_16_100() {
super("bedrock/blockpalette.1_16_100.nbt");
}
@Translator(packet = ServerClearTitlesPacket.class)
public class JavaClearTitlesTranslator extends PacketTranslator<ServerClearTitlesPacket> {
@Override
public int getBlockStateVersion() {
return 17825808;
}
@Override
protected NbtMapBuilder adjustBlockStateForVersion(String bedrockIdentifier, NbtMapBuilder statesBuilder) {
if (CORRECTED_STATES.contains(bedrockIdentifier)) {
statesBuilder.putInt("deprecated", 0);
}
return super.adjustBlockStateForVersion(bedrockIdentifier, statesBuilder);
}
public static void init() {
// no-op
public void translate(ServerClearTitlesPacket packet, GeyserSession session) {
SetTitlePacket titlePacket = new SetTitlePacket();
// TODO handle packet.isResetTimes()
titlePacket.setType(SetTitlePacket.Type.CLEAR);
titlePacket.setText("");
session.sendUpstreamPacket(titlePacket);
}
}

View file

@ -23,58 +23,30 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java;
package org.geysermc.connector.network.translators.java.title;
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetActionBarTextPacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
@Translator(packet = ServerTitlePacket.class)
public class JavaTitleTranslator extends PacketTranslator<ServerTitlePacket> {
@Translator(packet = ServerSetActionBarTextPacket.class)
public class JavaSetActionBarTextTranslator extends PacketTranslator<ServerSetActionBarTextPacket> {
@Override
public void translate(ServerTitlePacket packet, GeyserSession session) {
SetTitlePacket titlePacket = new SetTitlePacket();
String locale = session.getLocale();
public void translate(ServerSetActionBarTextPacket packet, GeyserSession session) {
String text;
if (packet.getTitle() == null) {
if (packet.getText() == null) { //TODO 1.17 can this happen?
text = " ";
} else {
text = MessageTranslator.convertMessage(packet.getTitle(), locale);
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale());
}
switch (packet.getAction()) {
case TITLE:
titlePacket.setType(SetTitlePacket.Type.TITLE);
titlePacket.setText(text);
break;
case SUBTITLE:
titlePacket.setType(SetTitlePacket.Type.SUBTITLE);
titlePacket.setText(text);
break;
case CLEAR:
case RESET:
titlePacket.setType(SetTitlePacket.Type.CLEAR);
titlePacket.setText("");
break;
case ACTION_BAR:
SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
titlePacket.setText(text);
break;
case TIMES:
titlePacket.setType(SetTitlePacket.Type.TIMES);
titlePacket.setFadeInTime(packet.getFadeIn());
titlePacket.setFadeOutTime(packet.getFadeOut());
titlePacket.setStayTime(packet.getStay());
titlePacket.setText("");
break;
}
session.sendUpstreamPacket(titlePacket);
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2021 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
*/
package org.geysermc.connector.network.translators.java.title;
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetSubtitleTextPacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
@Translator(packet = ServerSetSubtitleTextPacket.class)
public class JavaSetSubtitleTextTranslator extends PacketTranslator<ServerSetSubtitleTextPacket> {
@Override
public void translate(ServerSetSubtitleTextPacket packet, GeyserSession session) {
String text;
if (packet.getText() == null) { //TODO 1.17 can this happen?
text = " ";
} else {
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale());
}
SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setType(SetTitlePacket.Type.SUBTITLE);
titlePacket.setText(text);
session.sendUpstreamPacket(titlePacket);
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2021 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
*/
package org.geysermc.connector.network.translators.java.title;
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetTitleTextPacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
@Translator(packet = ServerSetTitleTextPacket.class)
public class JavaSetTitleTextTranslator extends PacketTranslator<ServerSetTitleTextPacket> {
@Override
public void translate(ServerSetTitleTextPacket packet, GeyserSession session) {
String text;
if (packet.getText() == null) { //TODO 1.17 can this happen?
text = " ";
} else {
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale());
}
SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setType(SetTitlePacket.Type.TITLE);
titlePacket.setText(text);
session.sendUpstreamPacket(titlePacket);
}
}

View file

@ -23,25 +23,25 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.window;
package org.geysermc.connector.network.translators.java.title;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerConfirmTransactionPacket;
import org.geysermc.connector.inventory.Inventory;
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetTitlesAnimationPacket;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@Translator(packet = ServerConfirmTransactionPacket.class)
public class JavaConfirmTransactionTranslator extends PacketTranslator<ServerConfirmTransactionPacket> {
@Translator(packet = ServerSetTitlesAnimationPacket.class)
public class JavaSetTitlesAnimationTranslator extends PacketTranslator<ServerSetTitlesAnimationPacket> {
@Override
public void translate(ServerConfirmTransactionPacket packet, GeyserSession session) {
session.addInventoryTask(() -> {
if (!packet.isAccepted()) {
ClientConfirmTransactionPacket confirmPacket = new ClientConfirmTransactionPacket(packet.getWindowId(), packet.getActionId(), true);
session.sendDownstreamPacket(confirmPacket);
}
});
public void translate(ServerSetTitlesAnimationPacket packet, GeyserSession session) {
SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setType(SetTitlePacket.Type.TIMES);
titlePacket.setText("");
titlePacket.setFadeInTime(packet.getFadeIn());
titlePacket.setFadeOutTime(packet.getFadeOut());
titlePacket.setStayTime(packet.getStay());
session.sendUpstreamPacket(titlePacket);
}
}

View file

@ -45,14 +45,6 @@ import org.geysermc.connector.utils.ChunkUtils;
@Translator(packet = ServerChunkDataPacket.class)
public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPacket> {
/**
* Determines if we should process non-full chunks
*/
private final boolean cacheChunks;
public JavaChunkDataTranslator() {
cacheChunks = GeyserConnector.getInstance().getConfig().isCacheChunks();
}
@Override
public void translate(ServerChunkDataPacket packet, GeyserSession session) {
@ -60,23 +52,15 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt());
}
if (packet.getColumn().getBiomeData() == null && !cacheChunks) {
// Non-full chunk without chunk caching
session.getConnector().getLogger().debug("Not sending non-full chunk because chunk caching is off.");
return;
}
// Merge received column with cache on network thread
Column mergedColumn = session.getChunkCache().addToCache(packet.getColumn());
if (mergedColumn == null) { // There were no changes?!?
return;
}
boolean isNonFullChunk = packet.getColumn().getBiomeData() == null;
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
try {
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, mergedColumn, isNonFullChunk);
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, mergedColumn);
ChunkSection[] sections = chunkData.getSections();
// Find highest section

View file

@ -229,7 +229,6 @@ public abstract class BlockTranslator {
}
JAVA_WATER_ID = waterRuntimeId;
BlockTranslator1_16_100.init();
BlockTranslator1_16_210.init();
BLOCKS_JSON = null; // We no longer require this so let it garbage collect away
}
@ -274,7 +273,10 @@ public abstract class BlockTranslator {
NbtMap blockTag = buildBedrockState(entry.getValue());
int bedrockRuntimeId = blockStateOrderedMap.getOrDefault(blockTag, -1);
if (bedrockRuntimeId == -1) {
throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built compound tag: \n" + blockTag);
//TODO REMOVE THIS COMMENT BEFORE RELEASE!!!! :)
//throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built compound tag: \n" + blockTag);
bedrockRuntimeId = 0;
GeyserConnector.getInstance().getLogger().warning("Unable to find " + javaId + " Bedrock runtime ID!");
}
switch (javaId) {

View file

@ -81,7 +81,7 @@ public class ChunkUtils {
return (yzx >> 8) | (yzx & 0x0F0) | ((yzx & 0x00F) << 8);
}
public static ChunkData translateToBedrock(GeyserSession session, Column column, boolean isNonFullChunk) {
public static ChunkData translateToBedrock(GeyserSession session, Column column) {
Chunk[] javaSections = column.getChunks();
ChunkSection[] sections = new ChunkSection[javaSections.length];
@ -91,45 +91,11 @@ public class ChunkUtils {
BitSet waterloggedPaletteIds = new BitSet();
BitSet pistonOrFlowerPaletteIds = new BitSet();
boolean worldManagerHasMoreBlockDataThanCache = session.getConnector().getWorldManager().hasOwnChunkCache();
// If the received packet was a full chunk update, null sections in the chunk are guaranteed to also be null in the world manager
boolean shouldCheckWorldManagerOnMissingSections = isNonFullChunk && worldManagerHasMoreBlockDataThanCache;
Chunk temporarySection = null;
for (int sectionY = 0; sectionY < javaSections.length; sectionY++) {
Chunk javaSection = javaSections[sectionY];
// Section is null, the cache will not contain anything of use
if (javaSection == null) {
// The column parameter contains all data currently available from the cache. If the chunk is null and the world manager
// reports the ability to access more data than the cache, attempt to fetch from the world manager instead.
if (shouldCheckWorldManagerOnMissingSections) {
// Ensure that temporary chunk is set
if (temporarySection == null) {
temporarySection = new Chunk();
}
// Read block data in section
session.getConnector().getWorldManager().getBlocksInSection(session, column.getX(), sectionY, column.getZ(), temporarySection);
if (temporarySection.isEmpty()) {
// The world manager only contains air for the given section
// We can leave temporarySection as-is to allow it to potentially be re-used for later sections
continue;
} else {
javaSection = temporarySection;
// Section contents have been modified, we can't re-use it
temporarySection = null;
}
} else {
continue;
}
}
// No need to encode an empty section...
if (javaSection.isEmpty()) {
if (javaSection == null || javaSection.isEmpty()) {
continue;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff