Begin updating Geyser. Requires manual MCProtocolLib compile

This commit is contained in:
DoctorMacc 2020-06-20 22:24:45 -04:00
parent 77873b6fbb
commit 117cdf282d
17 changed files with 198 additions and 174 deletions

View file

@ -105,7 +105,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>013e8e6dc4</version>
<version>1.16-rc1-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>

View file

@ -67,7 +67,7 @@ public class Entity {
protected long entityId;
protected long geyserId;
protected int dimension;
protected String dimension;
protected Vector3f position;
protected Vector3f motion;
@ -100,7 +100,7 @@ public class Entity {
this.rotation = rotation;
this.valid = false;
this.dimension = 0;
this.dimension = "minecraft:overworld";
setPosition(position);

View file

@ -33,20 +33,20 @@ import lombok.Getter;
public enum AttributeType {
// Universal Attributes
FOLLOW_RANGE("generic.followRange", "minecraft:follow_range", 0f, 2048f, 32f),
KNOCKBACK_RESISTANCE("generic.knockbackResistance", "minecraft:knockback_resistance", 0f, 1f, 0f),
MOVEMENT_SPEED("generic.movementSpeed", "minecraft:movement", 0f, 1024f, 0.1f),
FLYING_SPEED("generic.flyingSpeed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f),
ATTACK_DAMAGE("generic.attackDamage", "minecraft:attack_damage", 0f, 2048f, 1f),
HORSE_JUMP_STRENGTH("horse.jumpStrength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f),
FOLLOW_RANGE("minecraft:generic.follow_range", "minecraft:follow_range", 0f, 2048f, 32f),
KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", "minecraft:knockback_resistance", 0f, 1f, 0f),
MOVEMENT_SPEED("minecraft:generic.movement_speed", "minecraft:movement", 0f, 1024f, 0.1f),
FLYING_SPEED("minecraft:generic.flying_speed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f),
ATTACK_DAMAGE("minecraft:generic.attack_damage", "minecraft:attack_damage", 0f, 2048f, 1f),
HORSE_JUMP_STRENGTH("minecraft:horse.jump_strength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f),
// Java Attributes
ARMOR("generic.armor", null, 0f, 30f, 0f),
ARMOR_TOUGHNESS("generic.armorToughness", null, 0F, 20f, 0f),
ATTACK_KNOCKBACK("generic.attackKnockback", null, 1.5f, Float.MAX_VALUE, 0f),
ATTACK_SPEED("generic.attackSpeed", null, 0f, 1024f, 4f),
LUCK("generic.luck", null, -1024f, 1024f, 0f),
MAX_HEALTH("generic.maxHealth", null, 0f, 1024f, 20f),
ARMOR("minecraft:generic.armor", null, 0f, 30f, 0f),
ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", null, 0F, 20f, 0f),
ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", null, 1.5f, Float.MAX_VALUE, 0f),
ATTACK_SPEED("minecraft:generic.attack_speed", null, 0f, 1024f, 4f),
LUCK("minecraft:generic.luck", null, -1024f, 1024f, 0f),
MAX_HEALTH("minecraft:generic.max_health", null, 0f, 1024f, 20f),
// Bedrock Attributes
ABSORPTION(null, "minecraft:absorption", 0f, Float.MAX_VALUE, 0f),

View file

@ -68,7 +68,7 @@ public enum EntityType {
CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f),
SKELETON(AbstractSkeletonEntity.class, 34, 1.8f, 0.6f, 0.6f, 1.62f),
SPIDER(SpiderEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f),
ZOMBIE_PIGMAN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f),
ZOMBIFIED_PIGLIN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f),
SLIME(SlimeEntity.class, 37, 0.51f),
ENDERMAN(EndermanEntity.class, 38, 2.9f, 0.6f),
SILVERFISH(MonsterEntity.class, 39, 0.3f, 0.4f),
@ -150,7 +150,6 @@ public enum EntityType {
COD(AbstractFishEntity.class, 112, 0.25f, 0.5f),
PANDA(PandaEntity.class, 113, 1.25f, 1.125f, 1.825f),
FOX(FoxEntity.class, 121, 0.5f, 1.25f),
BEE(BeeEntity.class, 122, 0.6f, 0.6f),
/**
* Item frames are handled differently since they are a block in Bedrock.

View file

@ -68,10 +68,7 @@ import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.utils.LocaleUtils;
import org.geysermc.connector.utils.MathUtils;
import org.geysermc.connector.utils.SkinUtils;
import org.geysermc.connector.utils.*;
import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.floodgate.util.EncryptionUtil;
@ -503,7 +500,7 @@ public class GeyserSession implements CommandSender {
startGamePacket.setRotation(Vector2f.from(1, 1));
startGamePacket.setSeed(-1);
startGamePacket.setDimensionId(playerEntity.getDimension());
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(playerEntity.getDimension()));
startGamePacket.setGeneratorId(1);
startGamePacket.setLevelGamemode(0);
startGamePacket.setDifficulty(1);

View file

@ -44,7 +44,7 @@ public class BedrockAdventureSettingsTranslator extends PacketTranslator<Adventu
boolean flying = packet.getFlags().contains(AdventureSettingsPacket.Flag.FLYING);
boolean creative = session.getGameMode() == GameMode.CREATIVE;
ClientPlayerAbilitiesPacket abilitiesPacket = new ClientPlayerAbilitiesPacket(
false, canFly, flying, creative, 0.05f, 0.1f
false, canFly, flying, creative
);
session.sendDownstreamPacket(abilitiesPacket);
}

View file

@ -56,12 +56,12 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
break;
}
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.INTERACT, Hand.MAIN_HAND);
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket);
break;
case DAMAGE:
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.ATTACK, Hand.MAIN_HAND);
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(attackPacket);
break;
case LEAVE_VEHICLE:

View file

@ -82,9 +82,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
session.getEntityCache().getEntityByJavaId(ItemFrameEntity.getItemFrameEntityId(session, packet.getBlockPosition())) != null) {
Vector3f vector = packet.getClickPosition();
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) ItemFrameEntity.getItemFrameEntityId(session, packet.getBlockPosition()),
InteractAction.INTERACT, Hand.MAIN_HAND);
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
ClientPlayerInteractEntityPacket interactAtPacket = new ClientPlayerInteractEntityPacket((int) ItemFrameEntity.getItemFrameEntityId(session, packet.getBlockPosition()),
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket);
session.sendDownstreamPacket(interactAtPacket);
break;
@ -161,7 +161,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
if (ItemFrameEntity.positionContainsItemFrame(session, packet.getBlockPosition()) &&
session.getEntityCache().getEntityByJavaId(ItemFrameEntity.getItemFrameEntityId(session, packet.getBlockPosition())) != null) {
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) ItemFrameEntity.getItemFrameEntityId(session, packet.getBlockPosition()),
InteractAction.ATTACK);
InteractAction.ATTACK, session.isSneaking());
session.sendDownstreamPacket(attackPacket);
break;
}
@ -191,9 +191,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
case 0: //Interact
Vector3f vector = packet.getClickPosition();
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.INTERACT, Hand.MAIN_HAND);
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
ClientPlayerInteractEntityPacket interactAtPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket);
session.sendDownstreamPacket(interactAtPacket);
@ -205,7 +205,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break;
case 1: //Attack
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.ATTACK);
InteractAction.ATTACK, session.isSneaking());
session.sendDownstreamPacket(attackPacket);
break;
}

View file

@ -50,7 +50,7 @@ public class BedrockItemFrameDropItemTranslator extends PacketTranslator<ItemFra
}
Vector3i position = Vector3i.from(packet.getBlockPosition().getX(), y, packet.getBlockPosition().getZ());
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) ItemFrameEntity.getItemFrameEntityId(session, position),
InteractAction.ATTACK, Hand.MAIN_HAND);
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket);
}

View file

@ -100,6 +100,7 @@ public class ItemRegistry {
int itemIndex = 0;
Iterator<Map.Entry<String, JsonNode>> iterator = items.fields();
while (iterator.hasNext()) {
try {
Map.Entry<String, JsonNode> entry = iterator.next();
if (entry.getValue().has("tool_type")) {
if (entry.getValue().has("tool_tier")) {
@ -109,7 +110,7 @@ public class ItemRegistry {
entry.getValue().get("bedrock_data").intValue(),
entry.getValue().get("tool_type").textValue(),
entry.getValue().get("tool_tier").textValue(),
entry.getValue().get("is_block").booleanValue()));
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
} else {
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
entry.getKey(), itemIndex,
@ -124,13 +125,17 @@ public class ItemRegistry {
entry.getKey(), itemIndex,
entry.getValue().get("bedrock_id").intValue(),
entry.getValue().get("bedrock_data").intValue(),
entry.getValue().get("is_block").booleanValue()));
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
}
if (entry.getKey().equals("minecraft:barrier")) {
BARRIER_INDEX = itemIndex;
}
itemIndex++;
} catch (Exception e) {
System.out.println("Exception in item registry! " + e.toString());
e.printStackTrace();
}
}
/* Load creative items */

View file

@ -80,7 +80,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, Hand.MAIN_HAND);
session.sendDownstreamPacket(clientSettingsPacket);
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
if (!packet.getDimension().equals(entity.getDimension())) {
DimensionUtils.switchDimension(session, packet.getDimension());
}
}

View file

@ -66,11 +66,11 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
stopRainPacket.setPosition(Vector3f.ZERO);
session.sendUpstreamPacket(stopRainPacket);
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
if (!entity.getDimension().equals(packet.getDimension())) {
DimensionUtils.switchDimension(session, packet.getDimension());
} else {
if (session.isManyDimPackets()) { //reloading world
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
String fakeDim = entity.getDimension().equals("minecraft:overworld") ? "minecraft:nether" : "minecraft:overworld";
DimensionUtils.switchDimension(session, fakeDim);
DimensionUtils.switchDimension(session, packet.getDimension());
} else {

View file

@ -35,6 +35,7 @@ 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.utils.BedrockMapIcon;
import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.MapColor;
@Translator(packet = ServerMapDataPacket.class)
@ -45,7 +46,7 @@ public class JavaMapDataTranslator extends PacketTranslator<ServerMapDataPacket>
boolean shouldStore = false;
mapItemDataPacket.setUniqueMapId(packet.getMapId());
mapItemDataPacket.setDimensionId(session.getPlayerEntity().getDimension());
mapItemDataPacket.setDimensionId(DimensionUtils.javaToBedrock(session.getPlayerEntity().getDimension()));
mapItemDataPacket.setLocked(packet.isLocked());
mapItemDataPacket.setScale(packet.getScale());

View file

@ -40,6 +40,7 @@ import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnParticlePacket;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.network.translators.effect.EffectRegistry;
import org.geysermc.connector.utils.DimensionUtils;
@Translator(packet = ServerSpawnParticlePacket.class)
public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnParticlePacket> {
@ -93,7 +94,7 @@ public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnPar
if (stringParticle != null) {
SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket();
stringPacket.setIdentifier(stringParticle);
stringPacket.setDimensionId(session.getPlayerEntity().getDimension());
stringPacket.setDimensionId(DimensionUtils.javaToBedrock(session.getPlayerEntity().getDimension()));
stringPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
session.sendUpstreamPacket(stringPacket);
}

View file

@ -117,6 +117,7 @@ public class BlockTranslator {
int spawnerRuntimeId = -1;
Iterator<Map.Entry<String, JsonNode>> blocksIterator = blocks.fields();
while (blocksIterator.hasNext()) {
try {
javaRuntimeId++;
Map.Entry<String, JsonNode> entry = blocksIterator.next();
String javaId = entry.getKey();
@ -128,7 +129,11 @@ public class BlockTranslator {
JAVA_RUNTIME_ID_TO_HARDNESS.put(javaRuntimeId, hardnessNode.doubleValue());
}
try {
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue());
} catch (Exception e) {
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, false);
}
JsonNode toolTypeNode = entry.getValue().get("tool_type");
if (toolTypeNode != null) {
@ -205,6 +210,11 @@ public class BlockTranslator {
}
bedrockRuntimeId++;
} catch (Exception e) {
// REMOVE AFTER 1.16 UPDATE PROBABLY
System.out.println("Block translator error! " + e.toString());
e.printStackTrace();
}
}
if (cobwebRuntimeId == -1) {

View file

@ -36,10 +36,10 @@ public class DimensionUtils {
// Changes if the above-bedrock Nether building workaround is applied
private static int BEDROCK_NETHER_ID = 1;
public static void switchDimension(GeyserSession session, int javaDimension) {
public static void switchDimension(GeyserSession session, String javaDimension) {
int bedrockDimension = javaToBedrock(javaDimension);
Entity player = session.getPlayerEntity();
if (bedrockDimension == player.getDimension())
if (bedrockToJava(bedrockDimension) == player.getDimension())
return;
session.getEntityCache().removeAllEntities();
@ -55,7 +55,7 @@ public class DimensionUtils {
changeDimensionPacket.setRespawn(true);
changeDimensionPacket.setPosition(pos.toFloat());
session.sendUpstreamPacket(changeDimensionPacket);
player.setDimension(bedrockDimension);
player.setDimension(bedrockToJava(bedrockDimension));
player.setPosition(pos.toFloat());
session.setSpawned(false);
session.setLastChunkPosition(null);
@ -83,14 +83,25 @@ public class DimensionUtils {
* @param javaDimension Dimension ID to convert
* @return Converted Bedrock edition dimension ID
*/
public static int javaToBedrock(int javaDimension) {
public static int javaToBedrock(String javaDimension) {
switch (javaDimension) {
case -1:
case "minecraft:nether":
return BEDROCK_NETHER_ID;
case 1:
case "minecraft:the_end":
return 2;
default:
return javaDimension;
return 0;
}
}
public static String bedrockToJava(int bedrockDimension) {
switch (bedrockDimension) {
case 1:
return "minecraft:nether";
case 2:
return "minecraft:the_end";
default:
return "minecraft:overworld";
}
}

View file

@ -210,13 +210,13 @@ public class MessageUtils {
* @return Colour string to be used
*/
private static String getColorOrParent(MessageStyle style) {
ChatColor chatColor = style.getColor();
String color = style.getColor();
/*if (chatColor == ChatColor.NONE && style.getParent() != null) {
/*if (color == ChatColor.NONE && style.getParent() != null) {
return getColorOrParent(style.getParent());
}*/
return getColor(chatColor);
return getColor(color);
}
/**
@ -225,58 +225,58 @@ public class MessageUtils {
* @param color ChatColor to convert
* @return The converted color string
*/
private static String getColor(ChatColor color) {
private static String getColor(String color) {
String base = "\u00a7";
switch (color) {
case BLACK:
case ChatColor.BLACK:
base += "0";
break;
case DARK_BLUE:
case ChatColor.DARK_BLUE:
base += "1";
break;
case DARK_GREEN:
case ChatColor.DARK_GREEN:
base += "2";
break;
case DARK_AQUA:
case ChatColor.DARK_AQUA:
base += "3";
break;
case DARK_RED:
case ChatColor.DARK_RED:
base += "4";
break;
case DARK_PURPLE:
case ChatColor.DARK_PURPLE:
base += "5";
break;
case GOLD:
case ChatColor.GOLD:
base += "6";
break;
case GRAY:
case ChatColor.GRAY:
base += "7";
break;
case DARK_GRAY:
case ChatColor.DARK_GRAY:
base += "8";
break;
case BLUE:
case ChatColor.BLUE:
base += "9";
break;
case GREEN:
case ChatColor.GREEN:
base += "a";
break;
case AQUA:
case ChatColor.AQUA:
base += "b";
break;
case RED:
case ChatColor.RED:
base += "c";
break;
case LIGHT_PURPLE:
case ChatColor.LIGHT_PURPLE:
base += "d";
break;
case YELLOW:
case ChatColor.YELLOW:
base += "e";
break;
case WHITE:
case ChatColor.WHITE:
base += "f";
break;
case RESET:
case ChatColor.RESET:
//case NONE:
base += "r";
break;
@ -369,16 +369,16 @@ public class MessageUtils {
}
public static String toChatColor(TeamColor teamColor) {
for (ChatColor color : ChatColor.values()) {
if (color.name().equals(teamColor.name())) {
return getColor(color);
}
}
for (ChatFormat format : ChatFormat.values()) {
if (format.name().equals(teamColor.name())) {
return getFormat(Collections.singletonList(format));
}
}
// for (ChatColor color : ChatColor.) {
// if (color.name().equals(teamColor.name())) {
// return getColor(color);
// }
// }
// for (ChatFormat format : ChatFormat.values()) {
// if (format.name().equals(teamColor.name())) {
// return getFormat(Collections.singletonList(format));
// }
// } Not dealing with this
return "";
}