Skip to content

Commit

Permalink
Update the non-item parts
Browse files Browse the repository at this point in the history
  • Loading branch information
basaigh committed Apr 20, 2024
1 parent 78edbac commit 3b3f28b
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 186 deletions.
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 @@ -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
106 changes: 62 additions & 44 deletions core/src/main/java/org/geysermc/geyser/item/Items.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

package org.geysermc.geyser.level;

import com.github.steveice10.mc.protocol.data.game.RegistryEntry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import org.geysermc.geyser.util.JavaCodecUtil;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -38,8 +39,9 @@
*/
public record JavaDimension(int minY, int maxY, boolean piglinSafe, double worldCoordinateScale) {

public static void load(CompoundTag tag, Map<String, JavaDimension> map) {
for (CompoundTag dimension : JavaCodecUtil.iterateAsTag(tag.get("minecraft:dimension_type"))) {
public static void load(List<RegistryEntry> entries, Map<String, JavaDimension> map) {
for (RegistryEntry entry : entries) {
CompoundTag dimension = entry.getData();
CompoundTag elements = dimension.get("element");
int minY = ((IntTag) elements.get("min_y")).getValue();
int maxY = ((IntTag) elements.get("height")).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void connect(boolean wait) {
public void initChannel(@NonNull LocalChannelWithRemoteAddress channel) {
channel.spoofedRemoteAddress(new InetSocketAddress(clientIp, 0));
PacketProtocol protocol = getPacketProtocol();
protocol.newClientSession(LocalSession.this);
protocol.newClientSession(LocalSession.this, false);

refreshReadTimeoutHandler(channel);
refreshWriteTimeoutHandler(channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ public Map<JavaEnchantment, EnchantmentData> load(String input) {
Map.Entry<String, JsonNode> entry = it.next();
JavaEnchantment key = JavaEnchantment.getByJavaIdentifier(entry.getKey());
JsonNode node = entry.getValue();
int rarityMultiplier = switch (node.get("rarity").textValue()) {
case "common" -> 1;
case "uncommon" -> 2;
case "rare" -> 4;
case "very_rare" -> 8;
default -> throw new IllegalStateException("Unexpected value: " + node.get("rarity").textValue());
};
int rarityMultiplier = node.get("anvil_cost").asInt();
int maxLevel = node.get("max_level").asInt();

EnumSet<JavaEnchantment> incompatibleEnchantments = EnumSet.noneOf(JavaEnchantment.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, Geyser
String identifer = mapping.getBedrockIdentifier();

switch (identifer) {
case "minecraft:turtle_scute" -> { return mapping.withBedrockIdentifier("minecraft:scute"); }
case "minecraft:armadillo_scute", "minecraft:turtle_scute" -> { return mapping.withBedrockIdentifier("minecraft:scute"); }
case "minecraft:armadillo_spawn_egg" -> { return mapping.withBedrockIdentifier("minecraft:rabbit_spawn_egg"); }
case "minecraft:trial_spawner" -> { return mapping.withBedrockIdentifier("minecraft:mob_spawner"); }
case "minecraft:trial_key" -> { return mapping.withBedrockIdentifier("minecraft:echo_shard"); }
case "minecraft:wolf_armor" -> { return mapping.withBedrockIdentifier("minecraft:leather_horse_armor"); }
default -> { return mapping; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class Conversion662_649 {

private static final List<String> NEW_MISC = List.of("minecraft:grass_block", "minecraft:trial_spawner");
private static final List<String> NEW_MISC = List.of("minecraft:grass_block", "minecraft:vault");
private static final List<String> NEW_WOODS = List.of("minecraft:oak_wood", "minecraft:spruce_wood", "minecraft:birch_wood", "minecraft:jungle_wood", "minecraft:acacia_wood", "minecraft:dark_oak_wood", "minecraft:stripped_oak_wood", "minecraft:stripped_spruce_wood", "minecraft:stripped_birch_wood", "minecraft:stripped_jungle_wood", "minecraft:stripped_acacia_wood", "minecraft:stripped_dark_oak_wood");
private static final List<String> NEW_LEAVES = List.of("minecraft:oak_leaves", "minecraft:spruce_leaves", "minecraft:birch_leaves", "minecraft:jungle_leaves");
private static final List<String> NEW_LEAVES2 = List.of("minecraft:acacia_leaves", "minecraft:dark_oak_leaves");
Expand All @@ -48,9 +48,12 @@ static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, Geyser

String identifer = mapping.getBedrockIdentifier();

if (identifer.equals("minecraft:grass_block")) {
return mapping.withBedrockIdentifier("minecraft:grass");
}
switch (identifer) {
case "minecraft:bogged_spawn_egg" -> { return mapping.withBedrockIdentifier("minecraft:creeper_spawn_egg"); }
case "minecraft:grass_block" -> { return mapping.withBedrockIdentifier("minecraft:grass"); }
case "minecraft:vault" -> { return mapping.withBedrockIdentifier("minecraft:trial_spawner"); }
case "minecraft:wind_charge" -> { return mapping.withBedrockIdentifier("minecraft:snowball"); }
};

if (NEW_WOODS.contains(identifer)) {
switch (identifer) {
Expand Down Expand Up @@ -114,6 +117,19 @@ static NbtMap remapBlock(NbtMap tag) {
return builder.build();
}

if (name.equals("minecraft:vault")) {
replacement = "minecraft:trial_spawner";

NbtMapBuilder statesBuilder = NbtMap.builder()
.putInt("trial_spawner_state", 0);

NbtMapBuilder builder = tag.toBuilder();
builder.putString("name", replacement);
builder.putCompound("states", statesBuilder.build());

return builder.build();
}

if (NEW_WOODS.contains(name)) {
replacement = "minecraft:wood";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@
package org.geysermc.geyser.registry.populator;

import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.registry.type.GeyserMappingItem;

import java.util.List;
import java.util.stream.Stream;

public class Conversion671_662 {
private static final List<String> NEW_MISC = List.of("minecraft:heavy_core", "minecraft:mace", "minecraft:flow_banner_pattern", "minecraft:guster_banner_pattern", "minecraft:flow_armor_trim_smithing_template", "minecraft:bolt_armor_trim_smithing_template", "minecraft:flow_pottery_sherd", "minecraft:guster_pottery_sherd", "minecraft:scrape_pottery_sherd", "minecraft:breeze_rod");
private static final List<String> NEW_CORAL_FANS = List.of("minecraft:tube_coral_fan", "minecraft:brain_coral_fan", "minecraft:bubble_coral_fan", "minecraft:fire_coral_fan", "minecraft:horn_coral_fan");
private static final List<String> NEW_DEAD_CORAL_FANS = List.of("minecraft:dead_tube_coral_fan", "minecraft:dead_brain_coral_fan", "minecraft:dead_bubble_coral_fan", "minecraft:dead_fire_coral_fan", "minecraft:dead_horn_coral_fan");
private static final List<String> NEW_FLOWERS = List.of("minecraft:poppy", "minecraft:blue_orchid", "minecraft:allium", "minecraft:azure_bluet", "minecraft:red_tulip", "minecraft:orange_tulip", "minecraft:white_tulip", "minecraft:pink_tulip", "minecraft:oxeye_daisy", "minecraft:cornflower", "minecraft:lily_of_the_valley");
private static final List<String> NEW_SAPLINGS = List.of("minecraft:oak_sapling", "minecraft:spruce_sapling", "minecraft:birch_sapling", "minecraft:jungle_sapling", "minecraft:acacia_sapling", "minecraft:dark_oak_sapling", "minecraft:bamboo_sapling");
private static final List<String> NEW_BLOCKS = Stream.of(NEW_CORAL_FANS, NEW_DEAD_CORAL_FANS, NEW_FLOWERS, NEW_SAPLINGS).flatMap(List::stream).toList();
private static final List<String> NEW_BLOCKS = Stream.of(NEW_MISC, NEW_CORAL_FANS, NEW_DEAD_CORAL_FANS, NEW_FLOWERS, NEW_SAPLINGS).flatMap(List::stream).toList();

static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, GeyserMappingItem mapping) {
String identifer = mapping.getBedrockIdentifier();
Expand All @@ -46,6 +48,18 @@ static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, Geyser
return mapping;
}

switch (identifer) {
case "minecraft:bolt_armor_trim_smithing_template" -> { return mapping.withBedrockIdentifier("minecraft:wayfinder_armor_trim_smithing_template"); }
case "minecraft:breeze_rod" -> { return mapping.withBedrockIdentifier("minecraft:blaze_rod"); }
case "minecraft:flow_armor_trim_smithing_template" -> { return mapping.withBedrockIdentifier("minecraft:spire_armor_trim_smithing_template"); }
case "minecraft:flow_banner_pattern", "minecraft:guster_banner_pattern" -> { return mapping.withBedrockIdentifier("minecraft:globe_banner_pattern"); }
case "minecraft:flow_pottery_sherd" -> { return mapping.withBedrockIdentifier("minecraft:skull_pottery_sherd"); }
case "minecraft:guster_pottery_sherd" -> { return mapping.withBedrockIdentifier("minecraft:shelter_pottery_sherd"); }
case "minecraft:scrape_pottery_sherd" -> { return mapping.withBedrockIdentifier("minecraft:heartbreak_pottery_sherd"); }
case "minecraft:heavy_core" -> { return mapping.withBedrockIdentifier("minecraft:conduit"); }
case "minecraft:mace" -> { return mapping.withBedrockIdentifier("minecraft:netherite_axe"); }
}

if (NEW_FLOWERS.contains(identifer)) {
switch (identifer) {
case "minecraft:poppy" -> { return mapping.withBedrockIdentifier("minecraft:red_flower").withBedrockData(0); }
Expand Down Expand Up @@ -114,6 +128,15 @@ static NbtMap remapBlock(NbtMap tag) {

String replacement;

if (name.equals("minecraft:heavy_core")) {
replacement = "minecraft:conduit";

NbtMapBuilder builder = tag.toBuilder();
builder.putString("name", replacement);

return builder.build();
}

if (NEW_SAPLINGS.contains(name)) {
replacement = "minecraft:sapling";
String saplingType = name.replaceAll("minecraft:|_sapling", "");;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundClientInformationPacket;
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandSignedPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
Expand Down Expand Up @@ -360,7 +361,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
* As all entities are in the same world, this can be safely applied to all other entities.
*/
@Setter
private String dimension = DimensionUtils.OVERWORLD;
private int dimension = DimensionUtils.OVERWORLD;
@MonotonicNonNull
@Setter
private JavaDimension dimensionType = null;
Expand Down Expand Up @@ -1460,7 +1461,7 @@ public void sendChat(String message) {
* Sends a command to the Java server.
*/
public void sendCommand(String command) {
sendDownstreamGamePacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
}

public void setServerRenderDistance(int renderDistance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public ItemStackResponse translateRequest(GeyserSession session, Inventory inven
return rejectRequest(request);
}

ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, sourceItem.getItemStack(dropAction.getCount()));
ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket((short)-1, sourceItem.getItemStack(dropAction.getCount()));
session.sendDownstreamGamePacket(creativeDropPacket);

sourceItem.sub(dropAction.getCount());
Expand Down Expand Up @@ -493,9 +493,9 @@ protected ItemStackResponse translateCreativeRequest(GeyserSession session, Inve
dropStack = javaCreativeItem;
} else {
// Specify custom count
dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt());
dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getDataComponents());
}
ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack);
ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket((short)-1, dropStack);
session.sendDownstreamGamePacket(creativeDropPacket);
break;
}
Expand All @@ -516,7 +516,7 @@ private static void sendCreativeAction(GeyserSession session, Inventory inventor
GeyserItemStack item = inventory.getItem(slot);
ItemStack itemStack = item.isEmpty() ? new ItemStack(-1, 0, null) : item.getItemStack();

ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket(slot, itemStack);
ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket((short)slot, itemStack);
session.sendDownstreamGamePacket(creativePacket);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

package org.geysermc.geyser.translator.level;

import com.github.steveice10.mc.protocol.data.game.RegistryEntry;
import com.github.steveice10.mc.protocol.data.game.chunk.BitStorage;
import com.github.steveice10.mc.protocol.data.game.chunk.DataPalette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.GlobalPalette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.SingletonPalette;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import it.unimi.dsi.fastutil.ints.*;
import org.geysermc.geyser.level.chunk.BlockStorage;
Expand All @@ -41,21 +41,21 @@
import org.geysermc.geyser.level.chunk.bitarray.SingletonBitArray;
import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.JavaCodecUtil;
import org.geysermc.geyser.util.MathUtils;

import java.util.List;

// Array index formula by https://wiki.vg/Chunk_Format
public class BiomeTranslator {

public static void loadServerBiomes(GeyserSession session, CompoundTag codec) {
public static void loadServerBiomes(GeyserSession session, List<RegistryEntry> entries) {
Int2IntMap biomeTranslations = new Int2IntOpenHashMap();

CompoundTag worldGen = codec.get("minecraft:worldgen/biome");
ListTag serverBiomes = worldGen.get("value");
session.setBiomeGlobalPalette(MathUtils.getGlobalPaletteForSize(serverBiomes.size()));
session.setBiomeGlobalPalette(MathUtils.getGlobalPaletteForSize(entries.size()));

int greatestBiomeId = 0;
for (CompoundTag biomeTag : JavaCodecUtil.iterateAsTag(worldGen)) {
for (RegistryEntry entry : entries) {
CompoundTag biomeTag = entry.getData();
String javaIdentifier = ((StringTag) biomeTag.get("name")).getValue();
int bedrockId = Registries.BIOME_IDENTIFIERS.get().getOrDefault(javaIdentifier, 0);
int javaId = ((IntTag) biomeTag.get("id")).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommandsPacket> {

private static final String[] ALL_EFFECT_IDENTIFIERS = EntityUtils.getAllEffectIdentifiers();
private static final String[] ATTRIBUTES = AttributeType.Builtin.BUILTIN.keySet().toArray(new String[0]);
private static final String[] ATTRIBUTES = AttributeType.Builtin.BUILTIN.values().stream().map(AttributeType::getIdentifier).toList().toArray(new String[0]);
private static final String[] ENUM_BOOLEAN = {"true", "false"};
private static final String[] VALID_COLORS;
private static final String[] VALID_SCOREBOARD_SLOTS;
Expand Down
Loading

0 comments on commit 3b3f28b

Please sign in to comment.