Skip to content

Commit 215c309

Browse files
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
# Conflicts: # core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java # core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java # core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java # core/src/main/resources/mappings
2 parents de95eb5 + 4180c13 commit 215c309

File tree

50 files changed

+20897
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+20897
-357
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Bug report
22
description: Create a report to help us improve
3+
type: Bug
34
body:
45
- type: markdown
56
attributes:
67
value: |
78
Thanks for taking the time to fill out this bug report for Geyser! Fill out the following form to your best ability to help us fix the problem.
8-
Only use this if you're absolutely sure that you found a bug and can reproduce it. For anything else, use: [our Discord server](https://discord.gg/geysermc), [the FAQ](https://github.com/GeyserMC/Geyser/wiki/FAQ) or the [Common Issues](https://github.com/GeyserMC/Geyser/wiki/Common-Issues).
9+
Only use this if you're absolutely sure that you found a bug and can reproduce it. For anything else, use: [our Discord server](https://discord.gg/geysermc), [the FAQ](https://geysermc.org/wiki/geyser/faq) or the [Common Issues](https://geysermc.org/wiki/geyser/common-issues).
910
- type: textarea
1011
attributes:
1112
label: Describe the bug

.github/ISSUE_TEMPLATE/feature_request.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name: Feature request
22
description: Suggest an idea for this project
33
labels: "Feature Request"
4+
type: Feature
45
body:
56
- type: markdown
67
attributes:
78
value: |
89
Thanks for taking the time to fill out this feature request for Geyser! Please fill out the following form to your best ability to help us understand your feature request and significantly improve the chance of getting added.
9-
For anything else than a feature request, use: [our Discord server](https://discord.gg/geysermc), [the FAQ](https://github.com/GeyserMC/Geyser/wiki/FAQ) or [the Common Issues](https://github.com/GeyserMC/Geyser/wiki/Common-Issues).
10+
For anything else than a feature request, use: [our Discord server](https://discord.gg/geysermc), [the FAQ](https://geysermc.org/wiki/geyser/faq) or the [Common Issues](https://geysermc.org/wiki/geyser/common-issues).
1011
- type: textarea
1112
attributes:
1213
label: What feature do you want to see added?
@@ -18,4 +19,4 @@ body:
1819
label: Are there any alternatives?
1920
description: List any alternatives you might have tried
2021
validations:
21-
required: true
22+
required: true

api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockItem.java

-7
This file was deleted.

api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface JavaBlockState {
7070
@Nullable String pistonBehavior();
7171

7272
/**
73-
* Gets whether the block state has block entity
73+
* Gets whether the block state has a block entity
7474
*
7575
* @return whether the block state has block entity
7676
* @deprecated Does not have an effect. If you were using this to

core/src/main/java/org/geysermc/geyser/Constants.java

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public final class Constants {
3636

3737
public static final String FLOODGATE_DOWNLOAD_LOCATION = "https://geysermc.org/download#floodgate";
3838
public static final String GEYSER_DOWNLOAD_LOCATION = "https://geysermc.org/download";
39-
40-
@Deprecated
41-
static final String SAVED_REFRESH_TOKEN_FILE = "saved-refresh-tokens.json";
4239
static final String SAVED_AUTH_CHAINS_FILE = "saved-auth-chains.json";
4340

4441
public static final String GEYSER_CUSTOM_NAMESPACE = "geyser_custom";

core/src/main/java/org/geysermc/geyser/GeyserImpl.java

-51
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.fasterxml.jackson.core.type.TypeReference;
3030
import com.fasterxml.jackson.databind.DeserializationFeature;
3131
import com.fasterxml.jackson.databind.ObjectMapper;
32-
import com.google.gson.Gson;
3332
import io.netty.channel.epoll.Epoll;
3433
import io.netty.util.NettyRuntime;
3534
import io.netty.util.concurrent.DefaultThreadFactory;
@@ -39,8 +38,6 @@
3938
import lombok.Setter;
4039
import net.kyori.adventure.text.Component;
4140
import net.kyori.adventure.text.format.NamedTextColor;
42-
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
43-
import net.raphimc.minecraftauth.step.msa.StepMsaToken;
4441
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
4542
import org.checkerframework.checker.nullness.qual.NonNull;
4643
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -99,7 +96,6 @@
9996
import org.geysermc.geyser.util.AssetUtils;
10097
import org.geysermc.geyser.util.CooldownUtils;
10198
import org.geysermc.geyser.util.Metrics;
102-
import org.geysermc.geyser.util.MinecraftAuthLogger;
10399
import org.geysermc.geyser.util.NewsHandler;
104100
import org.geysermc.geyser.util.VersionCheckUtils;
105101
import org.geysermc.geyser.util.WebUtils;
@@ -566,53 +562,6 @@ private void startInstance() {
566562
// May be written/read to on multiple threads from each GeyserSession as well as writing the config
567563
savedAuthChains = new ConcurrentHashMap<>();
568564

569-
// TODO Remove after a while - just a migration help
570-
//noinspection deprecation
571-
File refreshTokensFile = bootstrap.getSavedUserLoginsFolder().resolve(Constants.SAVED_REFRESH_TOKEN_FILE).toFile();
572-
if (refreshTokensFile.exists()) {
573-
logger.info("Migrating refresh tokens to auth chains...");
574-
TypeReference<Map<String, String>> type = new TypeReference<>() { };
575-
Map<String, String> refreshTokens = null;
576-
try {
577-
refreshTokens = JSON_MAPPER.readValue(refreshTokensFile, type);
578-
} catch (IOException e) {
579-
// ignored - we'll just delete this file :))
580-
}
581-
582-
if (refreshTokens != null) {
583-
List<String> validUsers = config.getSavedUserLogins();
584-
final Gson gson = new Gson();
585-
for (Map.Entry<String, String> entry : refreshTokens.entrySet()) {
586-
String user = entry.getKey();
587-
if (!validUsers.contains(user)) {
588-
continue;
589-
}
590-
591-
// Migrate refresh tokens to auth chains
592-
try {
593-
StepFullJavaSession javaSession = PendingMicrosoftAuthentication.AUTH_FLOW.apply(false, 10);
594-
StepFullJavaSession.FullJavaSession fullJavaSession = javaSession.getFromInput(
595-
MinecraftAuthLogger.INSTANCE,
596-
PendingMicrosoftAuthentication.AUTH_CLIENT,
597-
new StepMsaToken.RefreshToken(entry.getValue())
598-
);
599-
600-
String authChain = gson.toJson(javaSession.toJson(fullJavaSession));
601-
savedAuthChains.put(user, authChain);
602-
} catch (Exception e) {
603-
GeyserImpl.getInstance().getLogger().warning("Could not migrate " + entry.getKey() + " to an auth chain! " +
604-
"They will need to sign in the next time they join Geyser.");
605-
}
606-
607-
// Ensure the new additions are written to the file
608-
scheduleAuthChainsWrite();
609-
}
610-
}
611-
612-
// Finally: Delete it. Goodbye!
613-
refreshTokensFile.delete();
614-
}
615-
616565
File authChainsFile = bootstrap.getSavedUserLoginsFolder().resolve(Constants.SAVED_AUTH_CHAINS_FILE).toFile();
617566
if (authChainsFile.exists()) {
618567
TypeReference<Map<String, String>> type = new TypeReference<>() { };

core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected void initializeMetadata() {
6767
}
6868

6969
public void setText(EntityMetadata<Component, ?> entityMetadata) {
70-
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
70+
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue(), session.locale()));
7171
calculateLineCount(entityMetadata.getValue());
7272
}
7373

core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay;
5151

5252
import java.util.HashMap;
53+
import java.util.function.Supplier;
5354

5455
@Data
5556
public class GeyserItemStack {
@@ -169,9 +170,9 @@ public <T> T getComponent(@NonNull DataComponentType<T> type) {
169170
return value;
170171
}
171172

172-
public <T> T getComponentOrFallback(@NonNull DataComponentType<T> type, T def) {
173+
public <T> T getComponentElseGet(@NonNull DataComponentType<T> type, Supplier<T> supplier) {
173174
T value = getComponent(type);
174-
return value == null ? def : value;
175+
return value == null ? supplier.get() : value;
175176
}
176177

177178
public int getNetId() {

core/src/main/java/org/geysermc/geyser/inventory/StonecutterContainer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
package org.geysermc.geyser.inventory;
2727

28-
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
2928
import lombok.Getter;
3029
import lombok.Setter;
3130
import org.checkerframework.checker.nullness.qual.NonNull;
3231
import org.geysermc.geyser.session.GeyserSession;
32+
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
3333

3434
public class StonecutterContainer extends Container {
3535
/**

core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
4848
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;
4949
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantments;
50-
import org.geysermc.mcprotocollib.protocol.data.game.item.component.Unbreakable;
5150
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
5251

5352
import java.util.List;
@@ -420,7 +419,7 @@ private boolean isRenaming(GeyserSession session, AnvilContainer anvilContainer,
420419
}
421420

422421
private int getRepairCost(GeyserItemStack itemStack) {
423-
return itemStack.getComponentOrFallback(DataComponentType.REPAIR_COST, 0);
422+
return itemStack.getComponentElseGet(DataComponentType.REPAIR_COST, () -> 0);
424423
}
425424

426425
private boolean hasDurability(GeyserItemStack itemStack) {
@@ -431,6 +430,6 @@ private boolean hasDurability(GeyserItemStack itemStack) {
431430
}
432431

433432
private int getDamage(GeyserItemStack itemStack) {
434-
return itemStack.getComponentOrFallback(DataComponentType.DAMAGE, 0);
433+
return itemStack.getComponentElseGet(DataComponentType.DAMAGE, () -> 0);
435434
}
436435
}

core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
package org.geysermc.geyser.item;
2727

2828
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
29-
import org.cloudburstmc.protocol.bedrock.data.inventory.ComponentItemData;
3029
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
3130

32-
public record GeyserCustomMappingData(CustomItemDefinition definition, ComponentItemData componentItemData, ItemDefinition itemDefinition, int integerId) {
31+
public record GeyserCustomMappingData(CustomItemDefinition definition, ItemDefinition itemDefinition, int integerId) {
3332
}

core/src/main/java/org/geysermc/geyser/level/WorldManager.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
4040
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
4141
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
42-
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper;
4342
import org.geysermc.mcprotocollib.protocol.data.game.setting.Difficulty;
4443

4544
import java.util.HashMap;
@@ -203,9 +202,9 @@ public void getDecoratedPotData(GeyserSession session, Vector3i pos, Consumer<Li
203202
try {
204203
Map<DataComponentType<?>, DataComponent<?, ?>> components = new HashMap<>();
205204
Int2ObjectMaps.fastForEach(map, entry -> {
206-
DataComponentType type = DataComponentType.from(entry.getIntKey());
205+
DataComponentType<?> type = DataComponentType.from(entry.getIntKey());
207206
ByteBuf buf = Unpooled.wrappedBuffer(entry.getValue());
208-
DataComponent value = type.readDataComponent(ItemCodecHelper.INSTANCE, buf);
207+
DataComponent<?, ?> value = type.readDataComponent(buf);
209208
components.put(type, value);
210209
});
211210
return new DataComponents(components);

core/src/main/java/org/geysermc/geyser/level/block/type/Block.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ public static final class Builder {
240240
private Supplier<Item> pickItem;
241241

242242
// We'll use this field after building
243-
private Property<?>[] propertyKeys;
243+
private Property<?>[] propertyKeys = null;
244+
private @Nullable Integer javaId = null;
244245

245246
/**
246247
* For states that we're just tracking for mirroring Java states.
@@ -298,11 +299,18 @@ public Builder pickItem(Supplier<Item> pickItem) {
298299
return this;
299300
}
300301

302+
public Builder javaId(int javaId) {
303+
this.javaId = javaId;
304+
return this;
305+
}
306+
301307
private List<BlockState> build(Block block) {
302308
if (states.isEmpty()) {
303-
BlockState state = new BlockState(block, BlockRegistries.BLOCK_STATES.get().size());
309+
if (javaId == null) {
310+
javaId = BlockRegistries.BLOCK_STATES.get().size();
311+
}
312+
BlockState state = new BlockState(block, javaId);
304313
BlockRegistries.BLOCK_STATES.get().add(state);
305-
propertyKeys = null;
306314
return List.of(state);
307315
} else if (states.size() == 1) {
308316
// We can optimize because we don't need to worry about combinations

core/src/main/java/org/geysermc/geyser/network/GameProtocol.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
3030
import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748;
3131
import org.cloudburstmc.protocol.bedrock.codec.v766.Bedrock_v766;
32+
import org.cloudburstmc.protocol.bedrock.codec.v776.Bedrock_v776;
3233
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
3334
import org.geysermc.geyser.session.GeyserSession;
3435
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
@@ -47,8 +48,8 @@ public final class GameProtocol {
4748
* Default Bedrock codec that should act as a fallback. Should represent the latest available
4849
* release of the game that Geyser supports.
4950
*/
50-
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(Bedrock_v766.CODEC.toBuilder()
51-
.minecraftVersion("1.21.51")
51+
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(Bedrock_v776.CODEC.toBuilder()
52+
.minecraftVersion("1.21.60")
5253
.build());
5354

5455
/**
@@ -66,9 +67,10 @@ public final class GameProtocol {
6667
SUPPORTED_BEDROCK_CODECS.add(CodecProcessor.processCodec(Bedrock_v748.CODEC.toBuilder()
6768
.minecraftVersion("1.21.40 - 1.21.44")
6869
.build()));
69-
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
70+
SUPPORTED_BEDROCK_CODECS.add(CodecProcessor.processCodec(Bedrock_v766.CODEC.toBuilder()
7071
.minecraftVersion("1.21.50 - 1.21.51")
71-
.build());
72+
.build()));
73+
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
7274
}
7375

7476
/**
@@ -91,6 +93,10 @@ public static boolean isPreWinterDrop(GeyserSession session) {
9193
return session.getUpstream().getProtocolVersion() == Bedrock_v748.CODEC.getProtocolVersion();
9294
}
9395

96+
public static boolean isPreCreativeInventoryRewrite(int protocolVersion) {
97+
return protocolVersion < 776;
98+
}
99+
94100
/**
95101
* Gets the {@link PacketCodec} for Minecraft: Java Edition.
96102
*

core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,14 @@ public PacketSignal handle(ToggleCrafterSlotRequestPacket packet) {
896896
public PacketSignal handle(TrimDataPacket packet) {
897897
return defaultHandler(packet);
898898
}
899-
}
899+
900+
@Override
901+
public PacketSignal handle(MovementPredictionSyncPacket packet) {
902+
return defaultHandler(packet);
903+
}
904+
905+
@Override
906+
public PacketSignal handle(ServerboundDiagnosticsPacket packet) {
907+
return defaultHandler(packet);
908+
}
909+
}

core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java

+16
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
import io.netty.channel.ChannelFactory;
3232
import io.netty.channel.ChannelHandler;
3333
import io.netty.channel.ChannelOption;
34+
import io.netty.channel.DefaultEventLoopGroup;
35+
import io.netty.channel.EventLoopGroup;
3436
import io.netty.channel.ReflectiveChannelFactory;
3537
import io.netty.channel.unix.PreferredDirectByteBufAllocator;
38+
import io.netty.util.concurrent.DefaultThreadFactory;
3639
import org.checkerframework.checker.nullness.qual.NonNull;
3740
import org.geysermc.mcprotocollib.network.helper.NettyHelper;
3841
import org.geysermc.mcprotocollib.network.netty.MinecraftChannelInitializer;
@@ -42,11 +45,13 @@
4245
import java.net.InetSocketAddress;
4346
import java.net.SocketAddress;
4447
import java.util.concurrent.Executor;
48+
import java.util.concurrent.TimeUnit;
4549

4650
/**
4751
* Manages a Minecraft Java session over our LocalChannel implementations.
4852
*/
4953
public final class LocalSession extends ClientNetworkSession {
54+
private static DefaultEventLoopGroup DEFAULT_EVENT_LOOP_GROUP;
5055
private static PreferredDirectByteBufAllocator PREFERRED_DIRECT_BYTE_BUF_ALLOCATOR = null;
5156

5257
private final SocketAddress spoofedRemoteAddress;
@@ -68,6 +73,17 @@ protected void setOptions(Bootstrap bootstrap) {
6873
}
6974
}
7075

76+
@Override
77+
protected EventLoopGroup getEventLoopGroup() {
78+
if (DEFAULT_EVENT_LOOP_GROUP == null) {
79+
DEFAULT_EVENT_LOOP_GROUP = new DefaultEventLoopGroup(new DefaultThreadFactory(this.getClass(), true));
80+
Runtime.getRuntime().addShutdownHook(new Thread(
81+
() -> DEFAULT_EVENT_LOOP_GROUP.shutdownGracefully(100, 500, TimeUnit.MILLISECONDS)));
82+
}
83+
84+
return DEFAULT_EVENT_LOOP_GROUP;
85+
}
86+
7187
@Override
7288
protected ChannelHandler getChannelHandler() {
7389
return new MinecraftChannelInitializer<>(channel -> {

core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public static void populate() {
135135
CustomSkullRegistryPopulator.populate();
136136
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.PRE_INIT);
137137
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.DEFINITION);
138-
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.NON_VANILLA_REGISTRATION);
139138
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_JAVA);
140139
COLLISIONS.load();
140+
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.NON_VANILLA_REGISTRATION);
141141
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.VANILLA_REGISTRATION);
142142
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.CUSTOM_REGISTRATION);
143143
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_BEDROCK);

0 commit comments

Comments
 (0)