Skip to content

Commit

Permalink
Update the non-item parts (#4586)
Browse files Browse the repository at this point in the history
* Update the non-item parts

* Add MaceItem

* Fix registry data loading
  • Loading branch information
basaigh authored Apr 20, 2024
1 parent 78edbac commit 3bdc615
Show file tree
Hide file tree
Showing 24 changed files with 253 additions and 199 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.

39 changes: 39 additions & 0 deletions core/src/main/java/org/geysermc/geyser/item/type/MaceItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2024 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.geyser.item.type;

import org.geysermc.geyser.item.Items;

public class MaceItem extends Item {
public MaceItem(String javaIdentifier, Builder builder) {
super(javaIdentifier, builder);
}

@Override
public boolean isValidRepairItem(Item other) {
return other == Items.BREEZE_ROD;
}
}
22 changes: 12 additions & 10 deletions core/src/main/java/org/geysermc/geyser/level/JavaDimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

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 it.unimi.dsi.fastutil.ints.Int2ObjectMap;

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

/**
* Represents the information we store from the current Java dimension
Expand All @@ -38,19 +39,20 @@
*/
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"))) {
CompoundTag elements = dimension.get("element");
int minY = ((IntTag) elements.get("min_y")).getValue();
int maxY = ((IntTag) elements.get("height")).getValue();
public static void load(List<RegistryEntry> entries, Int2ObjectMap<JavaDimension> map) {
for (int i = 0; i < entries.size(); i++) {
RegistryEntry entry = entries.get(i);
CompoundTag dimension = entry.getData();
int minY = ((IntTag) dimension.get("min_y")).getValue();
int maxY = ((IntTag) dimension.get("height")).getValue();
// Logical height can be ignored probably - seems to be for artificial limits like the Nether.

// Set if piglins/hoglins should shake
boolean piglinSafe = ((Number) elements.get("piglin_safe").getValue()).byteValue() != (byte) 0;
boolean piglinSafe = ((Number) dimension.get("piglin_safe").getValue()).byteValue() != (byte) 0;
// Load world coordinate scale for the world border
double coordinateScale = ((Number) elements.get("coordinate_scale").getValue()).doubleValue();
double coordinateScale = ((Number) dimension.get("coordinate_scale").getValue()).doubleValue();

map.put((String) dimension.get("name").getValue(), new JavaDimension(minY, maxY, piglinSafe, coordinateScale));
map.put(i, new JavaDimension(minY, maxY, piglinSafe, coordinateScale));
}
}
}
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
Loading

0 comments on commit 3bdc615

Please sign in to comment.