3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00
* Fixed firework entity

* Added firework item translator

* Fixed mappings submodule
Dieser Commit ist enthalten in:
rtm516 2020-05-23 22:33:39 +01:00 committet von GitHub
Ursprung 22a1073e54
Commit d8d9fb7190
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 360 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -1,64 +1,136 @@
/* /*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * 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 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
* *
* @author GeyserMC * @author GeyserMC
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
* */
*/
package org.geysermc.connector.entity;
package org.geysermc.connector.entity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.math.vector.Vector3f; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import org.geysermc.connector.entity.type.EntityType; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.geysermc.connector.network.session.GeyserSession; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import java.util.OptionalInt; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.nbt.CompoundTagBuilder;
public class FireworkEntity extends Entity { import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
public FireworkEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { import org.geysermc.connector.GeyserConnector;
super(entityId, geyserId, entityType, position, motion, rotation); import org.geysermc.connector.entity.type.EntityType;
} import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FireworkColor;
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { import java.util.ArrayList;
if (entityMetadata.getId() == 8 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) { import java.util.List;
//Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too. import java.util.OptionalInt;
PlayerEntity entity = session.getPlayerEntity();
float yaw = entity.getRotation().getX(); public class FireworkEntity extends Entity {
float pitch = entity.getRotation().getY();
//Uses math from NukkitX public FireworkEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
entity.setMotion(Vector3f.from( super(entityId, geyserId, entityType, position, motion, rotation);
-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2, }
-Math.sin(Math.toRadians(pitch)) * 2,
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
//Need to update the EntityMotionPacket or else the player won't boost @Override
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); if (entityMetadata.getId() == 7) {
entityMotionPacket.setMotion(entity.getMotion()); ItemStack item = (ItemStack) entityMetadata.getValue();
CompoundTag tag = item.getNbt();
session.sendUpstreamPacket(entityMotionPacket); CompoundTag fireworks = tag.get("Fireworks");
}
super.updateBedrockMetadata(entityMetadata, session); CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();
} fireworksBuilder.byteTag("Flight", (Byte) fireworks.get("Flight").getValue());
}
List<com.nukkitx.nbt.tag.CompoundTag> explosions = new ArrayList<>();
for (Tag effect : ((ListTag) fireworks.get("Explosions")).getValue()) {
CompoundTag effectData = (CompoundTag) effect;
try {
GeyserConnector.getInstance().getLogger().debug("Effect: " + new ObjectMapper().writeValueAsString(effect));
} catch (JsonProcessingException e) { }
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder();
if (effectData.get("Type") != null) {
effectBuilder.byteTag("FireworkType", (Byte) effectData.get("Type").getValue());
}
if (effectData.get("Colors") != null) {
int[] oldColors = (int[]) effectData.get("Colors").getValue();
byte[] colors = new byte[oldColors.length];
int i = 0;
for (int color : oldColors) {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
}
effectBuilder.byteArrayTag("FireworkColor", colors);
}
if (effectData.get("FadeColors") != null) {
int[] oldColors = (int[]) effectData.get("FadeColors").getValue();
byte[] colors = new byte[oldColors.length];
int i = 0;
for (int color : oldColors) {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
}
effectBuilder.byteArrayTag("FireworkFade", colors);
}
if (effectData.get("Trail") != null) {
effectBuilder.byteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue());
}
if (effectData.get("Flicker") != null) {
effectBuilder.byteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue());
}
explosions.add(effectBuilder.buildRootTag());
}
fireworksBuilder.tag(new com.nukkitx.nbt.tag.ListTag<>("Explosions", com.nukkitx.nbt.tag.CompoundTag.class, explosions));
metadata.put(EntityData.DISPLAY_ITEM, CompoundTagBuilder.builder().tag(fireworksBuilder.build("Fireworks")).buildRootTag());
} else if (entityMetadata.getId() == 8 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) {
//Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too.
PlayerEntity entity = session.getPlayerEntity();
float yaw = entity.getRotation().getX();
float pitch = entity.getRotation().getY();
//Uses math from NukkitX
entity.setMotion(Vector3f.from(
-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2,
-Math.sin(Math.toRadians(pitch)) * 2,
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
//Need to update the EntityMotionPacket or else the player won't boost
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
entityMotionPacket.setMotion(entity.getMotion());
session.sendUpstreamPacket(entityMotionPacket);
}
super.updateBedrockMetadata(entityMetadata, session);
}
}

Datei anzeigen

@ -106,7 +106,7 @@ public enum EntityType {
EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f, 0f, 0f, 0f, "minecraft:xp_orb"), EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f, 0f, 0f, 0f, "minecraft:xp_orb"),
EYE_OF_ENDER(Entity.class, 70, 0.25f, 0.25f, 0f, 0f, "minecraft:eye_of_ender_signal"), EYE_OF_ENDER(Entity.class, 70, 0.25f, 0.25f, 0f, 0f, "minecraft:eye_of_ender_signal"),
END_CRYSTAL(EnderCrystalEntity.class, 71, 0f, 0f, 0f, 0f, "minecraft:ender_crystal"), END_CRYSTAL(EnderCrystalEntity.class, 71, 0f, 0f, 0f, 0f, "minecraft:ender_crystal"),
FIREWORK_ROCKET(FireworkEntity.class, 72, 0.25f), FIREWORK_ROCKET(FireworkEntity.class, 72, 0.25f, 0.25f, 0.25f, 0f, "minecraft:fireworks_rocket"),
TRIDENT(TridentEntity.class, 73, 0f, 0f, 0f, 0f, "minecraft:thrown_trident"), TRIDENT(TridentEntity.class, 73, 0f, 0f, 0f, 0f, "minecraft:thrown_trident"),
TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f), TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f),
CAT(CatEntity.class, 75, 0.35f, 0.3f), CAT(CatEntity.class, 75, 0.35f, 0.3f),

Datei anzeigen

@ -0,0 +1,143 @@
/*
* Copyright (c) 2019-2020 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.item.translators.nbt;
import com.github.steveice10.opennbt.tag.builtin.*;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.NbtItemStackTranslator;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.utils.FireworkColor;
@ItemRemapper
public class FireworkTranslator extends NbtItemStackTranslator {
@Override
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
CompoundTag fireworks = itemTag.get("Fireworks");
ListTag explosions = fireworks.get("Explosions");
for (Tag effect : explosions.getValue()) {
CompoundTag effectData = (CompoundTag) effect;
CompoundTag newEffectData = new CompoundTag("");
if (effectData.get("Type") != null) {
newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue()));
}
if (effectData.get("Colors") != null) {
int[] oldColors = (int[]) effectData.get("Colors").getValue();
byte[] colors = new byte[oldColors.length];
int i = 0;
for (int color : oldColors) {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
}
newEffectData.put(new ByteArrayTag("FireworkColor", colors));
}
if (effectData.get("FadeColors") != null) {
int[] oldColors = (int[]) effectData.get("FadeColors").getValue();
byte[] colors = new byte[oldColors.length];
int i = 0;
for (int color : oldColors) {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
}
newEffectData.put(new ByteArrayTag("FireworkFade", colors));
}
if (effectData.get("Trail") != null) {
newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue()));
}
if (effectData.get("Flicker") != null) {
newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue()));
}
explosions.remove(effect);
explosions.add(newEffectData);
}
}
@Override
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
CompoundTag fireworks = itemTag.get("Fireworks");
ListTag explosions = fireworks.get("Explosions");
for (Tag effect : explosions.getValue()) {
CompoundTag effectData = (CompoundTag) effect;
CompoundTag newEffectData = new CompoundTag("");
if (effectData.get("FireworkType") != null) {
newEffectData.put(new ByteTag("Type", (Byte) effectData.get("FireworkType").getValue()));
}
if (effectData.get("FireworkColor") != null) {
byte[] oldColors = (byte[]) effectData.get("FireworkColor").getValue();
int[] colors = new int[oldColors.length];
int i = 0;
for (byte color : oldColors) {
colors[i++] = FireworkColor.fromBedrockID(color).getJavaID();
}
newEffectData.put(new IntArrayTag("Colors", colors));
}
if (effectData.get("FireworkFade") != null) {
byte[] oldColors = (byte[]) effectData.get("FireworkFade").getValue();
int[] colors = new int[oldColors.length];
int i = 0;
for (byte color : oldColors) {
colors[i++] = FireworkColor.fromBedrockID(color).getJavaID();
}
newEffectData.put(new IntArrayTag("FadeColors", colors));
}
if (effectData.get("FireworkTrail") != null) {
newEffectData.put(new ByteTag("Trail", (Byte) effectData.get("FireworkTrail").getValue()));
}
if (effectData.get("FireworkFlicker") != null) {
newEffectData.put(new ByteTag("Flicker", (Byte) effectData.get("FireworkFlicker").getValue()));
}
explosions.remove(effect);
explosions.add(newEffectData);
}
}
@Override
public boolean acceptItem(ItemEntry itemEntry) {
return "minecraft:firework_rocket".equals(itemEntry.getJavaIdentifier());
}
}

Datei anzeigen

@ -0,0 +1,80 @@
/*
* Copyright (c) 2019-2020 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.utils;
import lombok.Getter;
public enum FireworkColor {
BLACK((byte) 0, 1973019),
RED((byte) 1, 11743532),
GREEN((byte) 2, 3887386),
BROWN((byte) 3, 5320730),
BLUE((byte) 4, 2437522),
PURPLE((byte) 5, 8073150),
CYAN((byte) 6, 2651799),
LIGHT_GRAY((byte) 7, 11250603),
GRAY((byte) 8, 4408131),
PINK((byte) 9, 14188952),
LIME((byte) 10, 4312372),
YELLOW((byte) 11, 14602026),
LIGHT_BLUE((byte) 12, 6719955),
MAGENTA((byte) 13, 12801229),
ORANGE((byte) 14, 15435844),
WHITE((byte) 15, 15790320);
private static final FireworkColor[] VALUES = values();
@Getter
private byte bedrockID;
@Getter
private int javaID;
FireworkColor(byte bedrockID, int javaID) {
this.bedrockID = bedrockID;
this.javaID = javaID;
}
public static FireworkColor fromJavaID(int id) {
for (FireworkColor color : VALUES) {
if (color.javaID == id) {
return color;
}
}
return null;
}
public static FireworkColor fromBedrockID(int id) {
for (FireworkColor color : VALUES) {
if (color.bedrockID == id) {
return color;
}
}
return null;
}
}