Skip to content

Commit

Permalink
Merge branch 'master' into feature/mcee
Browse files Browse the repository at this point in the history
# Conflicts:
#	connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
#	connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java
  • Loading branch information
bundabrg committed Jul 25, 2020
2 parents fe8bd96 + 5b1116b commit 0a97183
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class GeyserSession implements CommandSender {
private long lastHitTime;

private MinecraftProtocol protocol;

public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
this.connector = connector;
this.upstream = new UpstreamSession(bedrockServerSession);
Expand Down Expand Up @@ -238,9 +238,7 @@ public void connect(RemoteServer remoteServer) {
SHIM.creativeContent(this);
} else {
CreativeContentPacket creativePacket = new CreativeContentPacket();
for (int i = 0; i < ItemRegistry.CREATIVE_ITEMS.length; i++) {
creativePacket.getEntries().put(i + 1, ItemRegistry.CREATIVE_ITEMS[i]);
}
creativePacket.setContents(ItemRegistry.CREATIVE_ITEMS);
upstream.sendPacket(creativePacket);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void translate(InventoryTransactionPacket packet, GeyserSession session)
}

// Handled in ITEM_USE
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BUCKET.getJavaId()) {
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BUCKET.getBedrockId()) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
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;
Expand Down Expand Up @@ -96,7 +94,7 @@ public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
if (displayTag != null && displayTag.contains("Name")) {
String itemName = displayTag.get("Name").getValue().toString();
Component component = GsonComponentSerializer.gson().deserialize(itemName);
rename = LegacyComponentSerializer.legacy().serialize(component);
rename = LegacyComponentSerializer.legacySection().serialize(component);
} else {
rename = "";
}
Expand Down Expand Up @@ -132,7 +130,7 @@ protected void processAction(Transaction transaction, ActionData cursor, ActionD
if (tag != null) {
String name = tag.getCompound("display").getString("Name");
Component component = GsonComponentSerializer.gson().deserialize(name);
rename = LegacyComponentSerializer.legacy().serialize(component);
rename = LegacyComponentSerializer.legacySection().serialize(component);
} else {
rename = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ public static void init() {
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.toolbox.fail.creative"), e);
}

int netId = 1;
List<ItemData> creativeItems = new ArrayList<>();
for (JsonNode itemNode : creativeItemEntries) {
short damage = 0;
if (itemNode.has("damage")) {
damage = itemNode.get("damage").numberValue().shortValue();
}
if (itemNode.has("nbt_b64")) {
byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText());
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
try {
NbtMap tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1, tag));
} catch (IOException e) {
e.printStackTrace();
try {
short damage = 0;
NbtMap tag = null;
if (itemNode.has("damage")) {
damage = itemNode.get("damage").numberValue().shortValue();
}
} else {
creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1));
if (itemNode.has("nbt_b64")) {
byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText());
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
}
creativeItems.add(ItemData.fromNet(netId++, itemNode.get("id").asInt(), damage, 1, tag));
} catch (IOException e) {
e.printStackTrace();
}
}
CREATIVE_ITEMS = creativeItems.toArray(new ItemData[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static ItemData translateToBedrock(GeyserSession session, ItemStack stack

// 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private String toBedrockMessage(StringTag tag) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -48,8 +49,9 @@ public void translate(ServerEntityStatusPacket packet, GeyserSession session) {
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);
Expand Down Expand Up @@ -88,7 +90,11 @@ public void translate(ServerEntityStatusPacket packet, GeyserSession session) {
entityEventPacket.setType(EntityEventType.CONSUME_TOTEM);
break;
case SHEEP_GRAZE_OR_TNT_CART_EXPLODE:
entityEventPacket.setType(EntityEventType.PRIME_TNT_MINECART);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ public static String getBedrockMessageLenient(String message) {

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) {
return GsonComponentSerializer.gson().deserialize(message);
}

public static String getJavaMessage(String message) {
Component component = LegacyComponentSerializer.legacy().deserialize(message);
Component component = LegacyComponentSerializer.legacySection().deserialize(message);
return GsonComponentSerializer.gson().serialize(component);
}

Expand Down

0 comments on commit 0a97183

Please sign in to comment.