Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Merge branch 'master' of https://github.com/GeyserMC/Geyser into server-inventory
Dieser Commit ist enthalten in:
Commit
e4ecd1a092
@ -262,6 +262,12 @@ public class GeyserSession implements CommandSender {
|
|||||||
@Setter
|
@Setter
|
||||||
private ScheduledFuture<?> movementSendIfIdle;
|
private ScheduledFuture<?> movementSendIfIdle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether the daylight cycle gamerule has been sent to the client, so the sun/moon remain motionless.
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
private boolean daylightCycle = true;
|
||||||
|
|
||||||
private boolean reducedDebugInfo = false;
|
private boolean reducedDebugInfo = false;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -34,8 +34,8 @@ import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
|
|||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.sound.SoundRegistry;
|
import org.geysermc.connector.network.translators.sound.SoundRegistry;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
@Translator(packet = ServerPlayBuiltinSoundPacket.class)
|
@Translator(packet = ServerPlayBuiltinSoundPacket.class)
|
||||||
public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayBuiltinSoundPacket> {
|
public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayBuiltinSoundPacket> {
|
||||||
@ -82,7 +82,11 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayB
|
|||||||
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
|
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
|
||||||
soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
|
soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
|
||||||
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
|
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
|
||||||
|
if (!soundMapping.getIdentifier().equals(":")) {
|
||||||
soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
|
soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
|
||||||
|
} else {
|
||||||
|
session.getConnector().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + packet.toString());
|
||||||
|
}
|
||||||
soundPacket.setIdentifier(":");
|
soundPacket.setIdentifier(":");
|
||||||
} else {
|
} else {
|
||||||
soundPacket.setExtraData(soundMapping.getExtraData());
|
soundPacket.setExtraData(soundMapping.getExtraData());
|
||||||
|
@ -25,49 +25,38 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.java.world;
|
package org.geysermc.connector.network.translators.java.world;
|
||||||
|
|
||||||
import com.nukkitx.protocol.bedrock.data.GameRuleData;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket;
|
import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2LongMap;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
|
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
|
|
||||||
|
|
||||||
@Translator(packet = ServerUpdateTimePacket.class)
|
@Translator(packet = ServerUpdateTimePacket.class)
|
||||||
public class JavaUpdateTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
|
public class JavaUpdateTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
|
||||||
|
|
||||||
// If negative, the last time is stored so we know it's not some plugin behavior doing weird things.
|
|
||||||
// Per-player for multi-world support
|
|
||||||
private static final Long2LongMap LAST_RECORDED_TIMES = new Long2LongOpenHashMap();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
|
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
|
||||||
|
|
||||||
// Bedrock sends a GameRulesChangedPacket if there is no daylight cycle
|
// Bedrock sends a GameRulesChangedPacket if there is no daylight cycle
|
||||||
// Java just sends a negative long if there is no daylight cycle
|
// Java just sends a negative long if there is no daylight cycle
|
||||||
long lastTime = LAST_RECORDED_TIMES.getOrDefault(session.getPlayerEntity().getEntityId(), 0);
|
|
||||||
long time = packet.getTime();
|
long time = packet.getTime();
|
||||||
|
|
||||||
if (lastTime != time) {
|
|
||||||
// https://minecraft.gamepedia.com/Day-night_cycle#24-hour_Minecraft_day
|
// https://minecraft.gamepedia.com/Day-night_cycle#24-hour_Minecraft_day
|
||||||
SetTimePacket setTimePacket = new SetTimePacket();
|
SetTimePacket setTimePacket = new SetTimePacket();
|
||||||
setTimePacket.setTime((int) Math.abs(time) % 24000);
|
setTimePacket.setTime((int) Math.abs(time) % 24000);
|
||||||
session.sendUpstreamPacket(setTimePacket);
|
session.sendUpstreamPacket(setTimePacket);
|
||||||
// TODO: Performance efficient to always do this?
|
if (!session.isDaylightCycle() && time >= 0) {
|
||||||
LAST_RECORDED_TIMES.put(session.getPlayerEntity().getEntityId(), time);
|
// Client thinks there is no daylight cycle but there is
|
||||||
}
|
|
||||||
if (lastTime < 0 && time >= 0) {
|
|
||||||
setDoDaylightCycleGamerule(session, true);
|
setDoDaylightCycleGamerule(session, true);
|
||||||
} else if (lastTime != time && time < 0) {
|
} else if (session.isDaylightCycle() && time < 0) {
|
||||||
|
// Client thinks there is daylight cycle but there isn't
|
||||||
setDoDaylightCycleGamerule(session, false);
|
setDoDaylightCycleGamerule(session, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDoDaylightCycleGamerule(GeyserSession session, boolean doCycle) {
|
private void setDoDaylightCycleGamerule(GeyserSession session, boolean doCycle) {
|
||||||
session.sendGameRule("dodaylightcycle", doCycle);
|
session.sendGameRule("dodaylightcycle", doCycle);
|
||||||
|
// Save the value so we don't have to constantly send a daylight cycle gamerule update
|
||||||
|
session.setDaylightCycle(doCycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,15 +30,18 @@ import com.google.common.collect.BiMap;
|
|||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.nukkitx.nbt.*;
|
import com.nukkitx.nbt.*;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import it.unimi.dsi.fastutil.objects.*;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.network.translators.world.block.entity.BlockEntity;
|
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlockTranslator {
|
public class BlockTranslator {
|
||||||
/**
|
/**
|
||||||
@ -65,8 +68,6 @@ public class BlockTranslator {
|
|||||||
// Bedrock carpet ID, used in LlamaEntity.java for decoration
|
// Bedrock carpet ID, used in LlamaEntity.java for decoration
|
||||||
public static final int CARPET = 171;
|
public static final int CARPET = 171;
|
||||||
|
|
||||||
private static final Int2ObjectMap<String> JAVA_ID_TO_BLOCK_ENTITY_MAP = new Int2ObjectOpenHashMap<>();
|
|
||||||
|
|
||||||
public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
|
public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
|
||||||
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
|
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
|
||||||
public static final Int2ObjectMap<String> JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<String> JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>();
|
||||||
@ -175,18 +176,6 @@ public class BlockTranslator {
|
|||||||
|
|
||||||
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
||||||
|
|
||||||
// Used for adding all "special" Java block states to block state map
|
|
||||||
String identifier;
|
|
||||||
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
|
|
||||||
for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
|
|
||||||
identifier = clazz.getAnnotation(BlockEntity.class).regex();
|
|
||||||
// Endswith, or else the block bedrock gets picked up for bed
|
|
||||||
if (bedrockIdentifier.endsWith(identifier) && !identifier.equals("")) {
|
|
||||||
JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaRuntimeId, clazz.getAnnotation(BlockEntity.class).name());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
||||||
|
|
||||||
String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
|
String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
|
||||||
@ -196,6 +185,8 @@ public class BlockTranslator {
|
|||||||
JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
|
JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
|
||||||
|
|
||||||
if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
|
if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
|
||||||
JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
|
JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
|
||||||
}
|
}
|
||||||
@ -352,12 +343,12 @@ public class BlockTranslator {
|
|||||||
return BLOCK_STATE_VERSION;
|
return BLOCK_STATE_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param javaId the Java string identifier to search for
|
||||||
|
* @return the Java block state integer, or {@link #JAVA_AIR_ID} if there is no valid entry.
|
||||||
|
*/
|
||||||
public static int getJavaBlockState(String javaId) {
|
public static int getJavaBlockState(String javaId) {
|
||||||
return JAVA_ID_BLOCK_MAP.get(javaId);
|
return JAVA_ID_BLOCK_MAP.getOrDefault(javaId, JAVA_AIR_ID);
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBlockEntityString(int javaId) {
|
|
||||||
return JAVA_ID_TO_BLOCK_ENTITY_MAP.get(javaId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWaterlogged(int state) {
|
public static boolean isWaterlogged(int state) {
|
||||||
|
@ -38,13 +38,14 @@ import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
|
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.inventory.GeyserItemStack;
|
|
||||||
import org.geysermc.connector.common.ChatColor;
|
import org.geysermc.connector.common.ChatColor;
|
||||||
|
import org.geysermc.connector.inventory.GeyserItemStack;
|
||||||
import org.geysermc.connector.inventory.Inventory;
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.inventory.translators.chest.DoubleChestInventoryTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.translators.chest.DoubleChestInventoryTranslator;
|
||||||
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -206,12 +207,17 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemEntry entry = ItemRegistry.getItemEntry(itemName);
|
||||||
|
if (entry != null) {
|
||||||
ClientCreativeInventoryActionPacket actionPacket = new ClientCreativeInventoryActionPacket(slot,
|
ClientCreativeInventoryActionPacket actionPacket = new ClientCreativeInventoryActionPacket(slot,
|
||||||
new ItemStack(ItemRegistry.getItemEntry(itemName).getJavaId()));
|
new ItemStack(entry.getJavaId()));
|
||||||
if ((slot - 36) != inventory.getHeldItemSlot()) {
|
if ((slot - 36) != inventory.getHeldItemSlot()) {
|
||||||
setHotbarItem(session, slot);
|
setHotbarItem(session, slot);
|
||||||
}
|
}
|
||||||
session.sendDownstreamPacket(actionPacket);
|
session.sendDownstreamPacket(actionPacket);
|
||||||
|
} else {
|
||||||
|
session.getConnector().getLogger().debug("Cannot find item for block " + itemName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 2d14c9dc3d75df7463fc7605a6cff63b5926a03e
|
Subproject commit 3f4707c0d26427dfe2ac79eca68e6048732f4412
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren