Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-16 04:50:07 +01:00
Merge branch 'master' of https://github.com/GeyserMC/Geyser
Dieser Commit ist enthalten in:
Commit
ddce10138e
@ -55,7 +55,11 @@ import org.geysermc.geyser.api.GeyserApi;
|
|||||||
import org.geysermc.geyser.api.command.CommandSource;
|
import org.geysermc.geyser.api.command.CommandSource;
|
||||||
import org.geysermc.geyser.api.event.EventBus;
|
import org.geysermc.geyser.api.event.EventBus;
|
||||||
import org.geysermc.geyser.api.event.EventRegistrar;
|
import org.geysermc.geyser.api.event.EventRegistrar;
|
||||||
import org.geysermc.geyser.api.event.lifecycle.*;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
||||||
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPostReloadEvent;
|
||||||
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
||||||
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPreReloadEvent;
|
||||||
|
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
|
||||||
import org.geysermc.geyser.api.network.AuthType;
|
import org.geysermc.geyser.api.network.AuthType;
|
||||||
import org.geysermc.geyser.api.network.BedrockListener;
|
import org.geysermc.geyser.api.network.BedrockListener;
|
||||||
import org.geysermc.geyser.api.network.RemoteServer;
|
import org.geysermc.geyser.api.network.RemoteServer;
|
||||||
@ -85,7 +89,13 @@ import org.geysermc.geyser.skin.SkinProvider;
|
|||||||
import org.geysermc.geyser.text.GeyserLocale;
|
import org.geysermc.geyser.text.GeyserLocale;
|
||||||
import org.geysermc.geyser.text.MinecraftLocale;
|
import org.geysermc.geyser.text.MinecraftLocale;
|
||||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||||
import org.geysermc.geyser.util.*;
|
import org.geysermc.geyser.util.AssetUtils;
|
||||||
|
import org.geysermc.geyser.util.CooldownUtils;
|
||||||
|
import org.geysermc.geyser.util.DimensionUtils;
|
||||||
|
import org.geysermc.geyser.util.Metrics;
|
||||||
|
import org.geysermc.geyser.util.NewsHandler;
|
||||||
|
import org.geysermc.geyser.util.VersionCheckUtils;
|
||||||
|
import org.geysermc.geyser.util.WebUtils;
|
||||||
import org.geysermc.mcprotocollib.network.tcp.TcpSession;
|
import org.geysermc.mcprotocollib.network.tcp.TcpSession;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -97,11 +107,19 @@ import java.net.UnknownHostException;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -645,16 +663,11 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.kick.done"));
|
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.kick.done"));
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduledThread.shutdown();
|
runIfNonNull(scheduledThread, ScheduledExecutorService::shutdown);
|
||||||
geyserServer.shutdown();
|
runIfNonNull(geyserServer, GeyserServer::shutdown);
|
||||||
if (skinUploader != null) {
|
runIfNonNull(skinUploader, FloodgateSkinUploader::close);
|
||||||
skinUploader.close();
|
runIfNonNull(newsHandler, NewsHandler::shutdown);
|
||||||
}
|
runIfNonNull(erosionUnixListener, UnixSocketClientListener::close);
|
||||||
newsHandler.shutdown();
|
|
||||||
|
|
||||||
if (this.erosionUnixListener != null) {
|
|
||||||
this.erosionUnixListener.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Registries.RESOURCE_PACKS.get().clear();
|
Registries.RESOURCE_PACKS.get().clear();
|
||||||
|
|
||||||
@ -833,6 +846,12 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T> void runIfNonNull(T nullable, Consumer<T> consumer) {
|
||||||
|
if (nullable != null) {
|
||||||
|
consumer.accept(nullable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void scheduleRefreshTokensWrite() {
|
private void scheduleRefreshTokensWrite() {
|
||||||
scheduledThread.execute(() -> {
|
scheduledThread.execute(() -> {
|
||||||
// Ensure all writes are handled on the same thread
|
// Ensure all writes are handled on the same thread
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 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.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||||
|
|
||||||
|
public interface BedrockRequiresTagItem {
|
||||||
|
|
||||||
|
void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder);
|
||||||
|
}
|
@ -27,6 +27,8 @@ package org.geysermc.geyser.item.type;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrays;
|
import it.unimi.dsi.fastutil.ints.IntArrays;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.cloudburstmc.nbt.NbtList;
|
||||||
import org.cloudburstmc.nbt.NbtMap;
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
import org.cloudburstmc.nbt.NbtType;
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
@ -41,7 +43,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.Fireworks;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FireworkRocketItem extends Item {
|
public class FireworkRocketItem extends Item implements BedrockRequiresTagItem {
|
||||||
public FireworkRocketItem(String javaIdentifier, Builder builder) {
|
public FireworkRocketItem(String javaIdentifier, Builder builder) {
|
||||||
super(javaIdentifier, builder);
|
super(javaIdentifier, builder);
|
||||||
}
|
}
|
||||||
@ -58,14 +60,16 @@ public class FireworkRocketItem extends Item {
|
|||||||
fireworksNbt.putByte("Flight", (byte) fireworks.getFlightDuration());
|
fireworksNbt.putByte("Flight", (byte) fireworks.getFlightDuration());
|
||||||
|
|
||||||
List<Fireworks.FireworkExplosion> explosions = fireworks.getExplosions();
|
List<Fireworks.FireworkExplosion> explosions = fireworks.getExplosions();
|
||||||
if (explosions.isEmpty()) {
|
if (!explosions.isEmpty()) {
|
||||||
return;
|
List<NbtMap> explosionNbt = new ArrayList<>();
|
||||||
|
for (Fireworks.FireworkExplosion explosion : explosions) {
|
||||||
|
explosionNbt.add(translateExplosionToBedrock(explosion));
|
||||||
|
}
|
||||||
|
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
|
||||||
|
} else {
|
||||||
|
// This is the default firework
|
||||||
|
fireworksNbt.put("Explosions", NbtList.EMPTY);
|
||||||
}
|
}
|
||||||
List<NbtMap> explosionNbt = new ArrayList<>();
|
|
||||||
for (Fireworks.FireworkExplosion explosion : explosions) {
|
|
||||||
explosionNbt.add(translateExplosionToBedrock(explosion));
|
|
||||||
}
|
|
||||||
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
|
|
||||||
builder.putCompound("Fireworks", fireworksNbt.build());
|
builder.putCompound("Fireworks", fireworksNbt.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,4 +142,20 @@ public class FireworkRocketItem extends Item {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder) {
|
||||||
|
if (components != null) {
|
||||||
|
Fireworks fireworks = components.get(DataComponentType.FIREWORKS);
|
||||||
|
if (fireworks != null) {
|
||||||
|
// Already translated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NbtMapBuilder fireworksNbt = NbtMap.builder();
|
||||||
|
fireworksNbt.putByte("Flight", (byte) 1);
|
||||||
|
fireworksNbt.put("Explosions", NbtList.EMPTY);
|
||||||
|
builder.putCompound("Fireworks", fireworksNbt.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ import org.geysermc.geyser.inventory.GeyserItemStack;
|
|||||||
import org.geysermc.geyser.item.Items;
|
import org.geysermc.geyser.item.Items;
|
||||||
import org.geysermc.geyser.item.components.Rarity;
|
import org.geysermc.geyser.item.components.Rarity;
|
||||||
import org.geysermc.geyser.item.type.Item;
|
import org.geysermc.geyser.item.type.Item;
|
||||||
|
import org.geysermc.geyser.item.type.BedrockRequiresTagItem;
|
||||||
import org.geysermc.geyser.level.block.type.Block;
|
import org.geysermc.geyser.level.block.type.Block;
|
||||||
import org.geysermc.geyser.registry.BlockRegistries;
|
import org.geysermc.geyser.registry.BlockRegistries;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
@ -148,6 +149,12 @@ public final class ItemTranslator {
|
|||||||
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
|
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fixes fireworks crafting recipe: they always contain a tag
|
||||||
|
// TODO remove once all items have their default components
|
||||||
|
if (javaItem instanceof BedrockRequiresTagItem requiresTagItem) {
|
||||||
|
requiresTagItem.addRequiredNbt(session, components, nbtBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
Rarity rarity = javaItem.rarity();
|
Rarity rarity = javaItem.rarity();
|
||||||
boolean enchantmentGlint = javaItem.glint();
|
boolean enchantmentGlint = javaItem.glint();
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
|
@ -32,7 +32,12 @@ import org.cloudburstmc.protocol.bedrock.data.PlayerActionType;
|
|||||||
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.*;
|
import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.PlayerActionPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
|
||||||
import org.geysermc.geyser.api.block.custom.CustomBlockState;
|
import org.geysermc.geyser.api.block.custom.CustomBlockState;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
||||||
@ -52,8 +57,17 @@ import org.geysermc.geyser.translator.protocol.Translator;
|
|||||||
import org.geysermc.geyser.util.BlockUtils;
|
import org.geysermc.geyser.util.BlockUtils;
|
||||||
import org.geysermc.geyser.util.CooldownUtils;
|
import org.geysermc.geyser.util.CooldownUtils;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.*;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.*;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerState;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||||
|
|
||||||
@Translator(packet = PlayerActionPacket.class)
|
@Translator(packet = PlayerActionPacket.class)
|
||||||
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
||||||
@ -70,7 +84,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
Vector3i vector = packet.getBlockPosition();
|
Vector3i vector = packet.getBlockPosition();
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case RESPAWN:
|
case RESPAWN -> {
|
||||||
// Respawn process is finished and the server and client are both OK with respawning.
|
// Respawn process is finished and the server and client are both OK with respawning.
|
||||||
EntityEventPacket eventPacket = new EntityEventPacket();
|
EntityEventPacket eventPacket = new EntityEventPacket();
|
||||||
eventPacket.setRuntimeEntityId(entity.getGeyserId());
|
eventPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
@ -88,16 +102,16 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
|
|
||||||
// Needed here since 1.19.81 for dimension switching
|
// Needed here since 1.19.81 for dimension switching
|
||||||
session.getEntityCache().updateBossBars();
|
session.getEntityCache().updateBossBars();
|
||||||
break;
|
}
|
||||||
case START_SWIMMING:
|
case START_SWIMMING -> {
|
||||||
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
||||||
ServerboundPlayerCommandPacket startSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
|
ServerboundPlayerCommandPacket startSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||||
session.sendDownstreamGamePacket(startSwimPacket);
|
session.sendDownstreamGamePacket(startSwimPacket);
|
||||||
|
|
||||||
session.setSwimming(true);
|
session.setSwimming(true);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case STOP_SWIMMING:
|
case STOP_SWIMMING -> {
|
||||||
// Prevent packet spam when Bedrock players are crawling near the edge of a block
|
// Prevent packet spam when Bedrock players are crawling near the edge of a block
|
||||||
if (!session.getCollisionManager().mustPlayerCrawlHere()) {
|
if (!session.getCollisionManager().mustPlayerCrawlHere()) {
|
||||||
ServerboundPlayerCommandPacket stopSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
ServerboundPlayerCommandPacket stopSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||||
@ -105,56 +119,55 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
|
|
||||||
session.setSwimming(false);
|
session.setSwimming(false);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case START_GLIDE:
|
case START_GLIDE -> {
|
||||||
// Otherwise gliding will not work in creative
|
// Otherwise gliding will not work in creative
|
||||||
ServerboundPlayerAbilitiesPacket playerAbilitiesPacket = new ServerboundPlayerAbilitiesPacket(false);
|
ServerboundPlayerAbilitiesPacket playerAbilitiesPacket = new ServerboundPlayerAbilitiesPacket(false);
|
||||||
session.sendDownstreamGamePacket(playerAbilitiesPacket);
|
session.sendDownstreamGamePacket(playerAbilitiesPacket);
|
||||||
case STOP_GLIDE:
|
sendPlayerGlideToggle(session, entity);
|
||||||
ServerboundPlayerCommandPacket glidePacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
}
|
||||||
session.sendDownstreamGamePacket(glidePacket);
|
case STOP_GLIDE -> sendPlayerGlideToggle(session, entity);
|
||||||
break;
|
case START_SNEAK -> {
|
||||||
case START_SNEAK:
|
|
||||||
ServerboundPlayerCommandPacket startSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
|
ServerboundPlayerCommandPacket startSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
|
||||||
session.sendDownstreamGamePacket(startSneakPacket);
|
session.sendDownstreamGamePacket(startSneakPacket);
|
||||||
|
|
||||||
session.startSneaking();
|
session.startSneaking();
|
||||||
break;
|
}
|
||||||
case STOP_SNEAK:
|
case STOP_SNEAK -> {
|
||||||
ServerboundPlayerCommandPacket stopSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
ServerboundPlayerCommandPacket stopSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
||||||
session.sendDownstreamGamePacket(stopSneakPacket);
|
session.sendDownstreamGamePacket(stopSneakPacket);
|
||||||
|
|
||||||
session.stopSneaking();
|
session.stopSneaking();
|
||||||
break;
|
}
|
||||||
case START_SPRINT:
|
case START_SPRINT -> {
|
||||||
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
||||||
ServerboundPlayerCommandPacket startSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
|
ServerboundPlayerCommandPacket startSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||||
session.sendDownstreamGamePacket(startSprintPacket);
|
session.sendDownstreamGamePacket(startSprintPacket);
|
||||||
session.setSprinting(true);
|
session.setSprinting(true);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case STOP_SPRINT:
|
case STOP_SPRINT -> {
|
||||||
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
if (!entity.getFlag(EntityFlag.SWIMMING)) {
|
||||||
ServerboundPlayerCommandPacket stopSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
ServerboundPlayerCommandPacket stopSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||||
session.sendDownstreamGamePacket(stopSprintPacket);
|
session.sendDownstreamGamePacket(stopSprintPacket);
|
||||||
}
|
}
|
||||||
session.setSprinting(false);
|
session.setSprinting(false);
|
||||||
break;
|
}
|
||||||
case DROP_ITEM:
|
case DROP_ITEM -> {
|
||||||
ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM,
|
ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM,
|
||||||
vector, Direction.VALUES[packet.getFace()], 0);
|
vector, Direction.VALUES[packet.getFace()], 0);
|
||||||
session.sendDownstreamGamePacket(dropItemPacket);
|
session.sendDownstreamGamePacket(dropItemPacket);
|
||||||
break;
|
}
|
||||||
case STOP_SLEEP:
|
case STOP_SLEEP -> {
|
||||||
ServerboundPlayerCommandPacket stopSleepingPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.LEAVE_BED);
|
ServerboundPlayerCommandPacket stopSleepingPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.LEAVE_BED);
|
||||||
session.sendDownstreamGamePacket(stopSleepingPacket);
|
session.sendDownstreamGamePacket(stopSleepingPacket);
|
||||||
break;
|
}
|
||||||
case START_BREAK: {
|
case START_BREAK -> {
|
||||||
// Ignore START_BREAK when the player is CREATIVE to avoid Spigot receiving 2 packets it interpets as block breaking. https://github.com/GeyserMC/Geyser/issues/4021
|
// Ignore START_BREAK when the player is CREATIVE to avoid Spigot receiving 2 packets it interpets as block breaking. https://github.com/GeyserMC/Geyser/issues/4021
|
||||||
if (session.getGameMode() == GameMode.CREATIVE) {
|
if (session.getGameMode() == GameMode.CREATIVE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the block breaking animation
|
// Start the block breaking animation
|
||||||
int blockState = session.getGeyser().getWorldManager().getBlockAt(session, vector);
|
int blockState = session.getGeyser().getWorldManager().getBlockAt(session, vector);
|
||||||
LevelEventPacket startBreak = new LevelEventPacket();
|
LevelEventPacket startBreak = new LevelEventPacket();
|
||||||
@ -180,18 +193,20 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
// Account for fire - the client likes to hit the block behind.
|
// Account for fire - the client likes to hit the block behind.
|
||||||
Vector3i fireBlockPos = BlockUtils.getBlockPosition(vector, packet.getFace());
|
Vector3i fireBlockPos = BlockUtils.getBlockPosition(vector, packet.getFace());
|
||||||
Block block = session.getGeyser().getWorldManager().blockAt(session, fireBlockPos).block();
|
Block block = session.getGeyser().getWorldManager().blockAt(session, fireBlockPos).block();
|
||||||
|
Direction direction = Direction.VALUES[packet.getFace()];
|
||||||
if (block == Blocks.FIRE || block == Blocks.SOUL_FIRE) {
|
if (block == Blocks.FIRE || block == Blocks.SOUL_FIRE) {
|
||||||
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos,
|
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos,
|
||||||
Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
|
direction, session.getWorldCache().nextPredictionSequence());
|
||||||
session.sendDownstreamGamePacket(startBreakingPacket);
|
session.sendDownstreamGamePacket(startBreakingPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING,
|
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING,
|
||||||
vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
|
vector, direction, session.getWorldCache().nextPredictionSequence());
|
||||||
session.sendDownstreamGamePacket(startBreakingPacket);
|
session.sendDownstreamGamePacket(startBreakingPacket);
|
||||||
break;
|
|
||||||
|
spawnBlockBreakParticles(session, direction, vector, BlockState.of(blockState));
|
||||||
}
|
}
|
||||||
case CONTINUE_BREAK:
|
case CONTINUE_BREAK -> {
|
||||||
if (session.getGameMode() == GameMode.CREATIVE) {
|
if (session.getGameMode() == GameMode.CREATIVE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -201,52 +216,48 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3f vectorFloat = vector.toFloat();
|
Vector3f vectorFloat = vector.toFloat();
|
||||||
LevelEventPacket continueBreakPacket = new LevelEventPacket();
|
|
||||||
continueBreakPacket.setType(LevelEvent.PARTICLE_CRACK_BLOCK);
|
|
||||||
continueBreakPacket.setData((session.getBlockMappings().getBedrockBlockId(breakingBlock)) | (packet.getFace() << 24));
|
|
||||||
continueBreakPacket.setPosition(vectorFloat);
|
|
||||||
session.sendUpstreamPacket(continueBreakPacket);
|
|
||||||
|
|
||||||
// Update the break time in the event that player conditions changed (jumping, effects applied)
|
|
||||||
LevelEventPacket updateBreak = new LevelEventPacket();
|
|
||||||
updateBreak.setType(LevelEvent.BLOCK_UPDATE_BREAK);
|
|
||||||
updateBreak.setPosition(vectorFloat);
|
|
||||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockState.of(breakingBlock).block()) * 20;
|
|
||||||
|
|
||||||
|
BlockState breakingBlockState = BlockState.of(breakingBlock);
|
||||||
|
Direction direction = Direction.VALUES[packet.getFace()];
|
||||||
|
spawnBlockBreakParticles(session, direction, vector, breakingBlockState);
|
||||||
|
|
||||||
|
double breakTime = BlockUtils.getSessionBreakTime(session, breakingBlockState.block()) * 20;
|
||||||
// If the block is custom, we must keep track of when it should break ourselves
|
// If the block is custom, we must keep track of when it should break ourselves
|
||||||
long blockBreakStartTime = session.getBlockBreakStartTime();
|
long blockBreakStartTime = session.getBlockBreakStartTime();
|
||||||
if (blockBreakStartTime != 0) {
|
if (blockBreakStartTime != 0) {
|
||||||
long timeSinceStart = System.currentTimeMillis() - blockBreakStartTime;
|
long timeSinceStart = System.currentTimeMillis() - blockBreakStartTime;
|
||||||
// We need to add a slight delay to the break time, otherwise the client breaks blocks too fast
|
// We need to add a slight delay to the break time, otherwise the client breaks blocks too fast
|
||||||
if (timeSinceStart >= (breakTime+=2) * 50) {
|
if (timeSinceStart >= (breakTime += 2) * 50) {
|
||||||
// Play break sound and particle
|
// Play break sound and particle
|
||||||
LevelEventPacket effectPacket = new LevelEventPacket();
|
LevelEventPacket effectPacket = new LevelEventPacket();
|
||||||
effectPacket.setPosition(vectorFloat);
|
effectPacket.setPosition(vectorFloat);
|
||||||
effectPacket.setType(LevelEvent.PARTICLE_DESTROY_BLOCK);
|
effectPacket.setType(LevelEvent.PARTICLE_DESTROY_BLOCK);
|
||||||
effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakingBlock));
|
effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakingBlock));
|
||||||
session.sendUpstreamPacket(effectPacket);
|
session.sendUpstreamPacket(effectPacket);
|
||||||
|
|
||||||
// Break the block
|
// Break the block
|
||||||
ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING,
|
ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING,
|
||||||
vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
|
vector, direction, session.getWorldCache().nextPredictionSequence());
|
||||||
session.sendDownstreamGamePacket(finishBreakingPacket);
|
session.sendDownstreamGamePacket(finishBreakingPacket);
|
||||||
session.setBlockBreakStartTime(0);
|
session.setBlockBreakStartTime(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update the break time in the event that player conditions changed (jumping, effects applied)
|
||||||
|
LevelEventPacket updateBreak = new LevelEventPacket();
|
||||||
|
updateBreak.setType(LevelEvent.BLOCK_UPDATE_BREAK);
|
||||||
|
updateBreak.setPosition(vectorFloat);
|
||||||
updateBreak.setData((int) (65535 / breakTime));
|
updateBreak.setData((int) (65535 / breakTime));
|
||||||
session.sendUpstreamPacket(updateBreak);
|
session.sendUpstreamPacket(updateBreak);
|
||||||
break;
|
}
|
||||||
case ABORT_BREAK:
|
case ABORT_BREAK -> {
|
||||||
if (session.getGameMode() != GameMode.CREATIVE) {
|
if (session.getGameMode() != GameMode.CREATIVE) {
|
||||||
// As of 1.16.210: item frame items are taken out here.
|
// As of 1.16.210: item frame items are taken out here.
|
||||||
// Survival also sends START_BREAK, but by attaching our process here adventure mode also works
|
// Survival also sends START_BREAK, but by attaching our process here adventure mode also works
|
||||||
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, vector);
|
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, vector);
|
||||||
if (itemFrameEntity != null) {
|
if (itemFrameEntity != null) {
|
||||||
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(),
|
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(),
|
||||||
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
||||||
session.sendDownstreamGamePacket(interactPacket);
|
session.sendDownstreamGamePacket(interactPacket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -260,25 +271,23 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
stopBreak.setData(0);
|
stopBreak.setData(0);
|
||||||
session.setBreakingBlock(-1);
|
session.setBreakingBlock(-1);
|
||||||
session.sendUpstreamPacket(stopBreak);
|
session.sendUpstreamPacket(stopBreak);
|
||||||
break;
|
}
|
||||||
case STOP_BREAK:
|
// Handled in BedrockInventoryTransactionTranslator
|
||||||
// Handled in BedrockInventoryTransactionTranslator
|
case STOP_BREAK -> {
|
||||||
break;
|
}
|
||||||
case DIMENSION_CHANGE_SUCCESS:
|
case DIMENSION_CHANGE_SUCCESS -> {
|
||||||
//sometimes the client doesn't feel like loading
|
//sometimes the client doesn't feel like loading
|
||||||
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
||||||
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||||
session.sendUpstreamPacket(spawnPacket);
|
session.sendUpstreamPacket(spawnPacket);
|
||||||
|
|
||||||
attributesPacket = new UpdateAttributesPacket();
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
||||||
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
attributesPacket.getAttributes().addAll(entity.getAttributes().values());
|
attributesPacket.getAttributes().addAll(entity.getAttributes().values());
|
||||||
session.sendUpstreamPacket(attributesPacket);
|
session.sendUpstreamPacket(attributesPacket);
|
||||||
break;
|
}
|
||||||
case JUMP:
|
case JUMP -> entity.setOnGround(false); // Increase block break time while jumping
|
||||||
entity.setOnGround(false); // Increase block break time while jumping
|
case MISSED_SWING -> {
|
||||||
break;
|
|
||||||
case MISSED_SWING:
|
|
||||||
// Java edition sends a cooldown when hitting air.
|
// Java edition sends a cooldown when hitting air.
|
||||||
// Normally handled by BedrockLevelSoundEventTranslator, but there is no sound on Java for this.
|
// Normally handled by BedrockLevelSoundEventTranslator, but there is no sound on Java for this.
|
||||||
CooldownUtils.sendCooldown(session);
|
CooldownUtils.sendCooldown(session);
|
||||||
@ -294,18 +303,18 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
|
animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
|
||||||
session.sendUpstreamPacket(animatePacket);
|
session.sendUpstreamPacket(animatePacket);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case START_FLYING: // Since 1.20.30
|
case START_FLYING -> { // Since 1.20.30
|
||||||
if (session.isCanFly()) {
|
if (session.isCanFly()) {
|
||||||
if (session.getGameMode() == GameMode.SPECTATOR) {
|
if (session.getGameMode() == GameMode.SPECTATOR) {
|
||||||
// should already be flying
|
// should already be flying
|
||||||
session.sendAdventureSettings();
|
session.sendAdventureSettings();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.getPlayerEntity().getFlag(EntityFlag.SWIMMING) && session.getCollisionManager().isPlayerInWater()) {
|
if (session.getPlayerEntity().getFlag(EntityFlag.SWIMMING) && session.getCollisionManager().isPlayerInWater()) {
|
||||||
// As of 1.18.1, Java Edition cannot fly while in water, but it can fly while crawling
|
// As of 1.18.1, Java Edition cannot fly while in water, but it can fly while crawling
|
||||||
// If this isn't present, swimming on a 1.13.2 server and then attempting to fly will put you into a flying/swimming state that is invalid on JE
|
// If this isn't present, swimming on a 1.13.2 server and then attempting to fly will put you into a flying/swimming state that is invalid on JE
|
||||||
session.sendAdventureSettings();
|
session.sendAdventureSettings();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -313,9 +322,9 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
session.setFlying(true);
|
session.setFlying(true);
|
||||||
session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(true));
|
session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(true));
|
||||||
} else {
|
} else {
|
||||||
// update whether we can fly
|
// update whether we can fly
|
||||||
session.sendAdventureSettings();
|
session.sendAdventureSettings();
|
||||||
// stop flying
|
// stop flying
|
||||||
PlayerActionPacket stopFlyingPacket = new PlayerActionPacket();
|
PlayerActionPacket stopFlyingPacket = new PlayerActionPacket();
|
||||||
stopFlyingPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
|
stopFlyingPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
stopFlyingPacket.setAction(PlayerActionType.STOP_FLYING);
|
stopFlyingPacket.setAction(PlayerActionType.STOP_FLYING);
|
||||||
@ -324,24 +333,24 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
stopFlyingPacket.setFace(0);
|
stopFlyingPacket.setFace(0);
|
||||||
session.sendUpstreamPacket(stopFlyingPacket);
|
session.sendUpstreamPacket(stopFlyingPacket);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case STOP_FLYING:
|
case STOP_FLYING -> {
|
||||||
session.setFlying(false);
|
session.setFlying(false);
|
||||||
session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(false));
|
session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(false));
|
||||||
break;
|
}
|
||||||
case DIMENSION_CHANGE_REQUEST_OR_CREATIVE_DESTROY_BLOCK: // Used by client to get book from lecterns and items from item frame in creative mode since 1.20.70
|
case DIMENSION_CHANGE_REQUEST_OR_CREATIVE_DESTROY_BLOCK -> { // Used by client to get book from lecterns and items from item frame in creative mode since 1.20.70
|
||||||
BlockState state = session.getGeyser().getWorldManager().blockAt(session, vector);
|
BlockState state = session.getGeyser().getWorldManager().blockAt(session, vector);
|
||||||
|
|
||||||
if (state.getValue(Properties.HAS_BOOK, false)) {
|
if (state.getValue(Properties.HAS_BOOK, false)) {
|
||||||
session.setDroppingLecternBook(true);
|
session.setDroppingLecternBook(true);
|
||||||
|
|
||||||
ServerboundUseItemOnPacket blockPacket = new ServerboundUseItemOnPacket(
|
ServerboundUseItemOnPacket blockPacket = new ServerboundUseItemOnPacket(
|
||||||
vector,
|
vector,
|
||||||
Direction.DOWN,
|
Direction.DOWN,
|
||||||
Hand.MAIN_HAND,
|
Hand.MAIN_HAND,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
false,
|
false,
|
||||||
session.getWorldCache().nextPredictionSequence());
|
session.getWorldCache().nextPredictionSequence());
|
||||||
session.sendDownstreamGamePacket(blockPacket);
|
session.sendDownstreamGamePacket(blockPacket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -349,10 +358,30 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
Entity itemFrame = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
Entity itemFrame = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
||||||
if (itemFrame != null) {
|
if (itemFrame != null) {
|
||||||
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrame.getEntityId(),
|
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrame.getEntityId(),
|
||||||
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
||||||
session.sendDownstreamGamePacket(interactPacket);
|
session.sendDownstreamGamePacket(interactPacket);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void spawnBlockBreakParticles(GeyserSession session, Direction direction, Vector3i position, BlockState blockState) {
|
||||||
|
LevelEventPacket levelEventPacket = new LevelEventPacket();
|
||||||
|
switch (direction) {
|
||||||
|
case UP -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_UP);
|
||||||
|
case DOWN -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_DOWN);
|
||||||
|
case NORTH -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_NORTH);
|
||||||
|
case EAST -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_EAST);
|
||||||
|
case SOUTH -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_SOUTH);
|
||||||
|
case WEST -> levelEventPacket.setType(LevelEvent.PARTICLE_BREAK_BLOCK_WEST);
|
||||||
|
}
|
||||||
|
levelEventPacket.setPosition(position.toFloat());
|
||||||
|
levelEventPacket.setData(session.getBlockMappings().getBedrockBlock(blockState).getRuntimeId());
|
||||||
|
session.sendUpstreamPacket(levelEventPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPlayerGlideToggle(GeyserSession session, Entity entity) {
|
||||||
|
ServerboundPlayerCommandPacket glidePacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
||||||
|
session.sendDownstreamGamePacket(glidePacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,11 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.java;
|
package org.geysermc.geyser.translator.protocol.java;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntIterator;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
||||||
@ -40,7 +44,11 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemTagDescri
|
|||||||
import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.TrimDataPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.TrimDataPacket;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.inventory.recipe.*;
|
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserShapedRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserShapelessRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.TrimRecipe;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@ -58,7 +66,17 @@ import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.SmithingTransfo
|
|||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.geysermc.geyser.util.InventoryUtils.LAST_RECIPE_NET_ID;
|
import static org.geysermc.geyser.util.InventoryUtils.LAST_RECIPE_NET_ID;
|
||||||
@ -191,6 +209,9 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
case CRAFTING_SPECIAL_MAPCLONING -> {
|
case CRAFTING_SPECIAL_MAPCLONING -> {
|
||||||
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), context.getAndIncrementNetId()));
|
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), context.getAndIncrementNetId()));
|
||||||
}
|
}
|
||||||
|
case CRAFTING_SPECIAL_FIREWORK_ROCKET -> {
|
||||||
|
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("00000000-0000-0000-0000-000000000002"), context.getAndIncrementNetId()));
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
List<GeyserRecipe> recipes = Registries.RECIPES.get(recipe.getType());
|
List<GeyserRecipe> recipes = Registries.RECIPES.get(recipe.getType());
|
||||||
if (recipes != null) {
|
if (recipes != null) {
|
||||||
@ -427,7 +448,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Strip NBT - tools won't appear in the recipe book otherwise
|
// Strip NBT - tools won't appear in the recipe book otherwise
|
||||||
output = output.toBuilder().tag(null).build();
|
// output = output.toBuilder().tag(null).build(); // TODO confirm???
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -451,7 +472,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Strip NBT - tools won't appear in the recipe book otherwise
|
// Strip NBT - tools won't appear in the recipe book otherwise
|
||||||
output = output.toBuilder().tag(null).build();
|
//output = output.toBuilder().tag(null).build(); // TODO confirm this is still true???
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -475,7 +496,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// See above
|
// See above
|
||||||
output = output.toBuilder().tag(null).build();
|
//output = output.toBuilder().tag(null).build();
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren