Skip to content

Commit

Permalink
Merge branch 'feature/1.20.5' into feature/1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hasankayra04 authored Apr 21, 2024
2 parents 2ddb7f5 + 6ecff0d commit 3dcb365
Show file tree
Hide file tree
Showing 58 changed files with 669 additions and 702 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,16 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.level.FireworkColor;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.MathUtils;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.UUID;

Expand All @@ -59,80 +51,16 @@ public void setFireworkItem(EntityMetadata<ItemStack, ?> entityMetadata) {
if (item == null) {
return;
}
CompoundTag tag = item.getNbt();

if (tag == null) {
return;
}

// TODO: Remove once Mojang fixes bugs with fireworks crashing clients on these specific devices.
// https://bugs.mojang.com/browse/MCPE-89115
if (session.getClientData().getDeviceOs() == DeviceOs.XBOX
|| session.getClientData().getDeviceOs() == DeviceOs.PS4) {
DataComponents components = item.getDataComponents();
if (components == null) {
return;
}

CompoundTag fireworks = tag.get("Fireworks");
if (fireworks == null) {
// Thank you Mineplex very cool
return;
}

NbtMapBuilder fireworksBuilder = NbtMap.builder();
if (fireworks.get("Flight") != null) {
fireworksBuilder.putByte("Flight", MathUtils.getNbtByte(fireworks.get("Flight").getValue()));
}

List<NbtMap> explosions = new ArrayList<>();
if (fireworks.get("Explosions") != null) {
for (Tag effect : ((ListTag) fireworks.get("Explosions")).getValue()) {
CompoundTag effectData = (CompoundTag) effect;
NbtMapBuilder effectBuilder = NbtMap.builder();

if (effectData.get("Type") != null) {
effectBuilder.putByte("FireworkType", MathUtils.getNbtByte(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.fromJavaRGB(color);
}

effectBuilder.putByteArray("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.fromJavaRGB(color);
}

effectBuilder.putByteArray("FireworkFade", colors);
}

if (effectData.get("Trail") != null) {
effectBuilder.putByte("FireworkTrail", MathUtils.getNbtByte(effectData.get("Trail").getValue()));
}

if (effectData.get("Flicker") != null) {
effectBuilder.putByte("FireworkFlicker", MathUtils.getNbtByte(effectData.get("Flicker").getValue()));
}

explosions.add(effectBuilder.build());
}
}

fireworksBuilder.putList("Explosions", NbtType.COMPOUND, explosions);

NbtMapBuilder builder = NbtMap.builder();
builder.put("Fireworks", fireworksBuilder.build());
// TODO this looked the same, so I'm going to assume it is and (keep below comment if true)
// Translate using item methods to get firework NBT for Bedrock
BedrockItemBuilder builder = new BedrockItemBuilder();
Items.FIREWORK_ROCKET.translateComponentsToBedrock(session, components, builder);

dirtyMetadata.put(EntityDataTypes.DISPLAY_FIREWORK, builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ protected void updateAttribute(Attribute javaAttribute, List<AttributeData> newA
case GENERIC_MOVEMENT_SPEED -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.MOVEMENT_SPEED));
case GENERIC_FOLLOW_RANGE -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.FOLLOW_RANGE));
case GENERIC_KNOCKBACK_RESISTANCE -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.KNOCKBACK_RESISTANCE));
case HORSE_JUMP_STRENGTH -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.HORSE_JUMP_STRENGTH));
case GENERIC_JUMP_STRENGTH -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.HORSE_JUMP_STRENGTH));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
import com.github.steveice10.mc.protocol.data.game.item.component.PotionContents;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
Expand Down Expand Up @@ -58,16 +59,17 @@ public void setItem(EntityMetadata<ItemStack, ?> entityMetadata) {
setFlag(EntityFlag.LINGERING, false);
} else {
// As of Java 1.19.3, the server/client doesn't seem to care of the item is actually a potion?
if (itemStack.getNbt() != null) {
Tag potionTag = itemStack.getNbt().get("Potion");
if (potionTag instanceof StringTag) {
Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
DataComponents components = itemStack.getDataComponents();
if (components != null) {
PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS);
if (potionContents != null) {
Potion potion = Potion.VALUES[potionContents.getPotionId()];
if (potion != null) {
dirtyMetadata.put(EntityDataTypes.EFFECT_COLOR, (int) potion.getBedrockId());
setFlag(EntityFlag.ENCHANTED, !NON_ENCHANTED_POTIONS.contains(potion));
} else {
dirtyMetadata.put(EntityDataTypes.EFFECT_COLOR, 0);
GeyserImpl.getInstance().getLogger().debug("Unknown java potion: " + potionTag.getValue());
GeyserImpl.getInstance().getLogger().debug("Unknown java potion: " + potionContents.getPotionId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setPlayingDead(BooleanEntityMetadata entityMetadata) {

@Override
public boolean canEat(Item item) {
return session.getTagCache().isAxolotlTemptItem(item);
return session.getTagCache().isAxolotlFood(item);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public enum JavaEnchantment {
KNOCKBACK,
FIRE_ASPECT,
LOOTING,
SWEEPING,
SWEEPING_EDGE,
EFFICIENCY,
SILK_TOUCH,
UNBREAKING,
Expand All @@ -136,6 +136,9 @@ public enum JavaEnchantment {
MULTISHOT,
QUICK_CHARGE,
PIERCING,
DENSITY,
BREACH,
WIND_BURST,
MENDING,
VANISHING_CURSE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
@Getter
public enum TippedArrowPotion {
WATER(-1, ArrowParticleColors.NONE), // Guessing this based off of the Potion enum. TODO merge?
MUNDANE(2, ArrowParticleColors.NONE), // 3 is extended?
THICK(4, ArrowParticleColors.NONE),
AWKWARD(5, ArrowParticleColors.NONE),
Expand Down Expand Up @@ -94,6 +95,10 @@ public enum TippedArrowPotion {
this.javaColor = arrowParticleColor.getColor();
}

public static TippedArrowPotion of(int id) {
return VALUES[id];
}

public static @Nullable TippedArrowPotion getByJavaIdentifier(String javaIdentifier) {
for (TippedArrowPotion potion : VALUES) {
if (potion.javaIdentifier.equals(javaIdentifier)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private int calcMergeEnchantmentCost(GeyserSession session, GeyserItemStack inpu
if (enchantment == JavaEnchantment.IMPALING) {
// Multiplier is halved on Bedrock for some reason
rarityMultiplier /= 2;
} else if (enchantment == JavaEnchantment.SWEEPING) {
} else if (enchantment == JavaEnchantment.SWEEPING_EDGE) {
// Doesn't exist on Bedrock
rarityMultiplier = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@

public enum ArmorMaterial {
LEATHER(() -> Items.LEATHER),
CHAIN(() -> Items.IRON_INGOT),
CHAINMAIL(() -> Items.IRON_INGOT),
IRON(() -> Items.IRON_INGOT),
GOLD(() -> Items.GOLD_INGOT),
DIAMOND(() -> Items.DIAMOND),
TURTLE(() -> Items.SCUTE),
NETHERITE(() -> Items.NETHERITE_INGOT);
TURTLE(() -> Items.TURTLE_SCUTE),
NETHERITE(() -> Items.NETHERITE_INGOT),
ARMADILLO(() -> Items.ARMADILLO_SCUTE);

private final Supplier<Item> repairIngredient;

Expand Down
Loading

0 comments on commit 3dcb365

Please sign in to comment.