Merge branch 'master' of https://github.com/GeyserMC/Geyser into feature/1.16.2

This commit is contained in:
DoctorMacc 2020-07-24 10:48:00 -04:00
commit 9a3a7ef50f
No known key found for this signature in database
GPG key ID: 6D6E7E059F186DB4
7 changed files with 41 additions and 21 deletions

View file

@ -36,12 +36,11 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ItemFrameEntity;
import org.geysermc.connector.entity.living.merchant.AbstractMerchantEntity;
@ -98,8 +97,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
false);
session.sendDownstreamPacket(blockPacket);
// Otherwise boats will not be able to be placed in survival
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BOAT.getBedrockId()) {
// Otherwise boats will not be able to be placed in survival and buckets wont work on mobile
if (packet.getItemInHand() != null && (packet.getItemInHand().getId() == ItemRegistry.BOAT.getBedrockId() || packet.getItemInHand().getId() == ItemRegistry.BUCKET.getBedrockId())) {
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
session.sendDownstreamPacket(itemPacket);
}
@ -136,9 +135,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break;
case 1:
ItemStack shieldSlot = session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36);
// Handled in Entity.java
if (shieldSlot != null && shieldSlot.getId() == ItemRegistry.SHIELD.getJavaId()) {
break;
} // Handled in Entity.java
}
// Handled in ITEM_USE
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BUCKET.getBedrockId()) {
break;
}
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
session.sendDownstreamPacket(useItemPacket);
// Used for sleeping in beds

View file

@ -26,12 +26,13 @@
package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.mc.protocol.data.message.TextMessage;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.updater.CursorInventoryUpdater;
@ -106,7 +107,9 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
String rename;
NbtMap tag = itemName.getTag();
if (tag != null) {
rename = tag.getCompound("display").getString("Name");
String name = tag.getCompound("display").getString("Name");
Component component = GsonComponentSerializer.gson().deserialize(name);
rename = LegacyComponentSerializer.legacySection().serialize(component);
} else {
rename = "";
}
@ -138,8 +141,8 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
CompoundTag displayTag = tag.get("display");
if (displayTag != null && displayTag.contains("Name")) {
String itemName = displayTag.get("Name").getValue().toString();
TextMessage message = (TextMessage) MessageSerializer.fromString(itemName);
rename = message.getText();
Component component = GsonComponentSerializer.gson().deserialize(itemName);
rename = LegacyComponentSerializer.legacySection().serialize(component);
} else {
rename = "";
}

View file

@ -56,12 +56,14 @@ public class ItemRegistry {
public static final List<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
// Shield ID, used in Entity.java
public static ItemEntry SHIELD;
// Boat ID, used in BedrockInventoryTransactionTranslator.java
public static ItemEntry BOAT;
// Gold ID, used in BedrockInventoryTransactionTranslator.java
public static ItemEntry BUCKET;
// Gold ID, used in PiglinEntity.java
public static ItemEntry GOLD;
// Shield ID, used in Entity.java
public static ItemEntry SHIELD;
public static int BARRIER_INDEX = 0;
@ -138,6 +140,9 @@ public class ItemRegistry {
case "minecraft:shield":
SHIELD = ITEM_ENTRIES.get(itemIndex);
break;
case "minecraft:bucket":
BUCKET = ITEM_ENTRIES.get(itemIndex);
break;
default:
break;
}

View file

@ -162,7 +162,7 @@ public abstract class ItemTranslator {
// If its not a message convert it
if (!MessageUtils.isMessage(name)) {
TextComponent component = LegacyComponentSerializer.legacy().deserialize(name);
TextComponent component = LegacyComponentSerializer.legacySection().deserialize(name);
name = GsonComponentSerializer.gson().serialize(component);
}

View file

@ -108,8 +108,8 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
String message = tag.getValue();
if (message == null) return null;
TextComponent component = (TextComponent) MessageUtils.phraseJavaMessage(message);
String legacy = LegacyComponentSerializer.legacy().serialize(component);
if (hasFormatting(LegacyComponentSerializer.legacy().deserialize(legacy))) {
String legacy = LegacyComponentSerializer.legacySection().serialize(component);
if (hasFormatting(LegacyComponentSerializer.legacySection().deserialize(legacy))) {
return "§r" + legacy;
}
return legacy;

View file

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntit
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@ -48,8 +49,9 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
EntityEventPacket entityEventPacket = new EntityEventPacket();
entityEventPacket.setRuntimeEntityId(entity.getGeyserId());
switch (packet.getStatus()) {
// EntityEventType.HURT sends extra data depending on the type of damage. However this appears to have no visual changes
case LIVING_BURN:
case LIVING_DROWN:
entityEventPacket.setData(9);
case LIVING_HURT:
case LIVING_HURT_SWEET_BERRY_BUSH:
entityEventPacket.setType(EntityEventType.HURT);
@ -88,7 +90,11 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
entityEventPacket.setType(EntityEventType.CONSUME_TOTEM);
break;
case SHEEP_GRAZE_OR_TNT_CART_EXPLODE:
if (entity.getEntityType() == EntityType.SHEEP) {
entityEventPacket.setType(EntityEventType.EAT_GRASS);
} else {
entityEventPacket.setType(EntityEventType.PRIME_TNT_MINECART);
}
break;
case IRON_GOLEM_HOLD_POPPY:
entityEventPacket.setType(EntityEventType.GOLEM_FLOWER_OFFER);

View file

@ -259,7 +259,7 @@ public class MessageUtils {
public static String getBedrockMessage(String message) {
Component component = phraseJavaMessage(message);
return LegacyComponentSerializer.legacy().serialize(component);
return LegacyComponentSerializer.legacySection().serialize(component);
}
public static Component phraseJavaMessage(String message) {
@ -267,7 +267,7 @@ public class MessageUtils {
}
public static String getJavaMessage(String message) {
Component component = LegacyComponentSerializer.legacy().deserialize(message);
Component component = LegacyComponentSerializer.legacySection().deserialize(message);
return GsonComponentSerializer.gson().serialize(component);
}