Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into custom-skulls
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyBMan committed May 28, 2020
2 parents 34f5142 + 3f76ae1 commit bd1d40d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FireworkColor;
import org.geysermc.connector.utils.MathUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -63,7 +64,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s

CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();
if (fireworks.get("Flight") != null) {
fireworksBuilder.byteTag("Flight", (Byte) fireworks.get("Flight").getValue());
fireworksBuilder.byteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue()));
}

List<com.nukkitx.nbt.tag.CompoundTag> explosions = new ArrayList<>();
Expand All @@ -73,7 +74,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder();

if (effectData.get("Type") != null) {
effectBuilder.byteTag("FireworkType", (Byte) effectData.get("Type").getValue());
effectBuilder.byteTag("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue()));
}

if (effectData.get("Colors") != null) {
Expand Down Expand Up @@ -101,11 +102,11 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

if (effectData.get("Trail") != null) {
effectBuilder.byteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue());
effectBuilder.byteTag("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue()));
}

if (effectData.get("Flicker") != null) {
effectBuilder.byteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue());
effectBuilder.byteTag("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue()));
}

explosions.add(effectBuilder.buildRootTag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@

package org.geysermc.connector.network.translators;

import java.util.HashMap;
import java.util.Map;

import com.github.steveice10.mc.protocol.packet.ingame.server.ServerKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateLightPacket;
import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;

import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.reflections.Reflections;

import java.util.HashMap;
import java.util.Map;

public class PacketTranslatorRegistry<T> {
private final Map<Class<? extends T>, PacketTranslator<? extends T>> translators = new HashMap<>();

Expand Down Expand Up @@ -72,7 +72,8 @@ public class PacketTranslatorRegistry<T> {
}
}

IGNORED_PACKETS.add(ServerUpdateLightPacket.class);
IGNORED_PACKETS.add(ServerKeepAlivePacket.class); // Handled by MCProtocolLib
IGNORED_PACKETS.add(ServerUpdateLightPacket.class); // Light is handled on Bedrock for us
}

private PacketTranslatorRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

import com.github.steveice10.opennbt.tag.builtin.*;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
import org.geysermc.connector.utils.FireworkColor;
import org.geysermc.connector.utils.MathUtils;

@ItemRemapper
public class FireworkTranslator extends NbtItemStackTranslator {
Expand All @@ -41,6 +42,10 @@ public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
}

CompoundTag fireworks = itemTag.get("Fireworks");
if (fireworks.get("Flight") != null) {
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
}

ListTag explosions = fireworks.get("Explosions");
if (explosions == null) {
return;
Expand All @@ -51,7 +56,7 @@ public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
CompoundTag newEffectData = new CompoundTag("");

if (effectData.get("Type") != null) {
newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue()));
newEffectData.put(new ByteTag("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue())));
}

if (effectData.get("Colors") != null) {
Expand Down Expand Up @@ -79,11 +84,11 @@ public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
}

if (effectData.get("Trail") != null) {
newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue()));
newEffectData.put(new ByteTag("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue())));
}

if (effectData.get("Flicker") != null) {
newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue()));
newEffectData.put(new ByteTag("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue())));
}

explosions.remove(effect);
Expand All @@ -94,6 +99,9 @@ public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
@Override
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
CompoundTag fireworks = itemTag.get("Fireworks");
if (fireworks.get("Flight") != null) {
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
}

ListTag explosions = fireworks.get("Explosions");
for (Tag effect : explosions.getValue()) {
Expand All @@ -102,7 +110,7 @@ public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
CompoundTag newEffectData = new CompoundTag("");

if (effectData.get("FireworkType") != null) {
newEffectData.put(new ByteTag("Type", (Byte) effectData.get("FireworkType").getValue()));
newEffectData.put(new ByteTag("Type", MathUtils.convertByte(effectData.get("FireworkType").getValue())));
}

if (effectData.get("FireworkColor") != null) {
Expand Down Expand Up @@ -130,11 +138,11 @@ public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
}

if (effectData.get("FireworkTrail") != null) {
newEffectData.put(new ByteTag("Trail", (Byte) effectData.get("FireworkTrail").getValue()));
newEffectData.put(new ByteTag("Trail", MathUtils.convertByte(effectData.get("FireworkTrail").getValue())));
}

if (effectData.get("FireworkFlicker") != null) {
newEffectData.put(new ByteTag("Flicker", (Byte) effectData.get("FireworkFlicker").getValue()));
newEffectData.put(new ByteTag("Flicker", MathUtils.convertByte(effectData.get("FireworkFlicker").getValue())));
}

explosions.remove(effect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ public static int ceil(float floatNumber) {
int truncated = (int) floatNumber;
return floatNumber > truncated ? truncated + 1 : truncated;
}

/**
* Converts the given object from an int or byte to byte.
* This is used for NBT data that might be either an int
* or byte and bedrock only takes it as an byte
*
* @param value The value to convert
* @return The converted byte
*/
public static Byte convertByte(Object value) {
if (value instanceof Integer) {
return ((Integer) value).byteValue();
}
return (Byte) value;
}
}

0 comments on commit bd1d40d

Please sign in to comment.