Skip to content

Commit

Permalink
more and more, zzz
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Nov 22, 2024
1 parent 329244f commit 240a151
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 236 deletions.
10 changes: 7 additions & 3 deletions patches/server/0006-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ index 44bbfc4eba78dfa268696c79b1d15c8f1271bbb1..a88ff89928c322fa1c42987a06991a56
.withRequiredArg()
diff --git a/src/main/java/org/leavesmc/leaves/LeavesConfig.java b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..313beaa7eef481bfc42d89959e227dac6558fab9
index 0000000000000000000000000000000000000000..86738f2520d055ea556d03eacfdfb1b852993710
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,901 @@
@@ -0,0 +1,905 @@
+package org.leavesmc.leaves;
+
+import com.destroystokyo.paper.util.SneakyThrow;
Expand Down Expand Up @@ -810,9 +810,13 @@ index 0000000000000000000000000000000000000000..313beaa7eef481bfc42d89959e227dac
+ }
+ }
+
+ @GlobalConfig(name = "appleskin-protocol", category = "protocol")
+ @RemovedConfig(name = "appleskin-protocol", category = "protocol")
+ @GlobalConfig(name = "protocol", category = {"protocol", "appleskin"})
+ public static boolean appleskinProtocol = false;
+
+ @GlobalConfig(name = "sync-tick-interval", category = {"protocol", "appleskin"})
+ public static int appleskinSyncTickInterval = 20;
+
+ @GlobalConfig(name = "xaero-map-protocol", category = "protocol")
+ public static boolean xaeroMapProtocol = false;
+
Expand Down
23 changes: 7 additions & 16 deletions patches/server/0007-Leaves-Protocol-Core.patch
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ index 0000000000000000000000000000000000000000..986d2a6641ff8017dddf3e5f2655adfc
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..e5eb67c0bbdf4953ed0ccc3281f06eda26a7956e
index 0000000000000000000000000000000000000000..ea94da3a2332cf23fc8753129e546a6f5a5af395
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
@@ -0,0 +1,435 @@
@@ -0,0 +1,434 @@
+package org.leavesmc.leaves.protocol.core;
+
+import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -470,10 +470,9 @@ index 0000000000000000000000000000000000000000..e5eb67c0bbdf4953ed0ccc3281f06eda
+
+ Map<ProtocolHandler.MinecraftRegister, Method> map = MINECRAFT_REGISTER.get(protocol);
+ for (ProtocolHandler.MinecraftRegister register : map.keySet()) {
+ if (register.ignoreId() || register.channelId().equals(channel[1]) ||
+ ArrayUtils.contains(register.channelIds(), channel[1])) {
+ if (register.ignoreId() || ArrayUtils.contains(register.channelId(), channel[1])) {
+ try {
+ map.get(register).invoke(null, player);
+ map.get(register).invoke(null, player, channel[1]);
+ } catch (InvocationTargetException | IllegalAccessException exception) {
+ LOGGER.warning("Failed to handle minecraft register, " + exception.getCause() + ": " + exception.getMessage());
+ }
Expand Down Expand Up @@ -620,10 +619,10 @@ index 0000000000000000000000000000000000000000..e5eb67c0bbdf4953ed0ccc3281f06eda
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolHandler.java b/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..9d71f8e6af24301bedf60f5c87e0bb3c1697d5e3
index 0000000000000000000000000000000000000000..202fb0717734aa8948ff8307420bf9aaf77d63ca
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolHandler.java
@@ -0,0 +1,63 @@
@@ -0,0 +1,55 @@
+package org.leavesmc.leaves.protocol.core;
+
+import java.lang.annotation.ElementType;
Expand All @@ -636,13 +635,11 @@ index 0000000000000000000000000000000000000000..9d71f8e6af24301bedf60f5c87e0bb3c
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Init {
+
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface PayloadReceiver {
+
+ Class<? extends LeavesCustomPayload<?>> payload();
+
+ String[] payloadId() default "";
Expand All @@ -661,28 +658,22 @@ index 0000000000000000000000000000000000000000..9d71f8e6af24301bedf60f5c87e0bb3c
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface PlayerJoin {
+
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface PlayerLeave {
+
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface ReloadServer {
+
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface MinecraftRegister {
+
+ String channelId() default "";
+
+ String[] channelIds() default {};
+ String[] channelId() default "";
+
+ boolean ignoreId() default false;
+ }
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0031-BBOR-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ index 4640baec5bed6c2d53cc0f8ca1d273cc115abe9b..2fea5a46bba27578366c36f594472c3e
public Level getLevel() {
diff --git a/src/main/java/org/leavesmc/leaves/protocol/BBORProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/BBORProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..16ef00dde5a1c502449378829b1b6b85d6d145fd
index 0000000000000000000000000000000000000000..7c48c0a5ac7e53e52ca06f72e6f58472aad5d4a3
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/BBORProtocol.java
@@ -0,0 +1,227 @@
Expand Down Expand Up @@ -144,7 +144,7 @@ index 0000000000000000000000000000000000000000..16ef00dde5a1c502449378829b1b6b85
+ public static void onChunkLoaded(@NotNull LevelChunk chunk) {
+ if (LeavesConfig.bborProtocol) {
+ Map<String, StructureStart> structures = new HashMap<>();
+ final Registry<Structure> structureFeatureRegistry = chunk.getLevel().registryAccess().registryOrThrow(Registries.STRUCTURE);
+ final Registry<Structure> structureFeatureRegistry = chunk.getLevel().registryAccess().lookupOrThrow(Registries.STRUCTURE);
+ for (var es : chunk.getAllStarts().entrySet()) {
+ final var optional = structureFeatureRegistry.getResourceKey(es.getKey());
+ optional.ifPresent(key -> structures.put(key.location().toString(), es.getValue()));
Expand Down Expand Up @@ -184,8 +184,8 @@ index 0000000000000000000000000000000000000000..16ef00dde5a1c502449378829b1b6b85
+ return new BBoundingBox(type, min, max);
+ }
+
+ private static void sendStructureList(ServerPlayer player) {
+ final Registry<Structure> structureRegistry = player.server.registryAccess().registryOrThrow(Registries.STRUCTURE);
+ private static void sendStructureList(@NotNull ServerPlayer player) {
+ final Registry<Structure> structureRegistry = player.server.registryAccess().lookupOrThrow(Registries.STRUCTURE);
+ final Set<String> structureIds = structureRegistry.entrySet().stream()
+ .map(e -> e.getKey().location().toString()).collect(Collectors.toSet());
+ ProtocolUtils.sendPayloadPacket(player, STRUCTURE_LIST_SYNC, buf -> {
Expand Down
41 changes: 23 additions & 18 deletions patches/server/0033-Jade-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ index 30d0133a42ce990352f5c492fcf9beb105364848..1ab2eab686b3a89d406f127a6036c0e2
protected CompositeLootItemCondition(List<LootItemCondition> terms, Predicate<LootContext> predicate) {
diff --git a/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..438dfee78f7114e7c8d3d57c5dcc90e1fcc75a4c
index 0000000000000000000000000000000000000000..c72d6eeb61cda12e49939deebb9791d5c7f36f0a
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java
@@ -0,0 +1,311 @@
@@ -0,0 +1,312 @@
+package org.leavesmc.leaves.protocol.jade;
+
+import com.google.common.base.Suppliers;
Expand Down Expand Up @@ -290,8 +290,9 @@ index 0000000000000000000000000000000000000000..438dfee78f7114e7c8d3d57c5dcc90e1
+
+ try {
+ shearableBlocks = Collections.unmodifiableList(LootTableMineableCollector.execute(
+ MinecraftServer.getServer().reloadableRegistries().get().registryOrThrow(Registries.LOOT_TABLE),
+ Items.SHEARS.getDefaultInstance()));
+ MinecraftServer.getServer().reloadableRegistries().lookup().lookupOrThrow(Registries.LOOT_TABLE),
+ Items.SHEARS.getDefaultInstance()
+ ));
+ } catch (Throwable ignore) {
+ shearableBlocks = List.of();
+ LeavesLogger.LOGGER.severe("Failed to collect shearable blocks");
Expand Down Expand Up @@ -1231,7 +1232,7 @@ index 0000000000000000000000000000000000000000..6e32eed15f028020223e2500849b4db3
\ No newline at end of file
diff --git a/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java b/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..797558f3804a1a8143eafafd5dc46cc72ea19a42
index 0000000000000000000000000000000000000000..3efa3ceb9654bc53adb61ded96c0ad08eb9b083d
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java
@@ -0,0 +1,138 @@
Expand Down Expand Up @@ -1285,7 +1286,7 @@ index 0000000000000000000000000000000000000000..797558f3804a1a8143eafafd5dc46cc7
+ case RandomizableContainer te when te.getLootTable() != null -> {
+ return List.of();
+ }
+ case ContainerEntity containerEntity when containerEntity.getLootTable() != null -> {
+ case ContainerEntity containerEntity when containerEntity.getContainerLootTable() != null -> {
+ return List.of();
+ }
+ default -> {
Expand Down Expand Up @@ -3097,15 +3098,16 @@ index 0000000000000000000000000000000000000000..a046ae4e542efcadd0001b7225440c30
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/jade/util/LootTableMineableCollector.java b/src/main/java/org/leavesmc/leaves/protocol/jade/util/LootTableMineableCollector.java
new file mode 100644
index 0000000000000000000000000000000000000000..63f4d0a31232525db3620095fc662f0225c5f306
index 0000000000000000000000000000000000000000..81575cfa4c5a6f1a1aadbf9ea7743cd1d053f925
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/jade/util/LootTableMineableCollector.java
@@ -0,0 +1,105 @@
@@ -0,0 +1,109 @@
+package org.leavesmc.leaves.protocol.jade.util;
+
+import com.google.common.collect.Lists;
+import net.minecraft.advancements.critereon.ItemPredicate;
+import net.minecraft.core.Registry;
+import net.minecraft.core.Holder;
+import net.minecraft.core.HolderGetter;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.Block;
Expand All @@ -3121,29 +3123,32 @@ index 0000000000000000000000000000000000000000..63f4d0a31232525db3620095fc662f02
+import org.leavesmc.leaves.protocol.jade.tool.ShearsToolHandler;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Function;
+
+public class LootTableMineableCollector {
+
+ private final Registry<LootTable> lootRegistry;
+ private final HolderGetter<LootTable> lootRegistry;
+ private final ItemStack toolItem;
+
+ public LootTableMineableCollector(Registry<LootTable> lootRegistry, ItemStack toolItem) {
+ public LootTableMineableCollector(HolderGetter<LootTable> lootRegistry, ItemStack toolItem) {
+ this.lootRegistry = lootRegistry;
+ this.toolItem = toolItem;
+ }
+
+ public static @NotNull List<Block> execute(Registry<LootTable> lootRegistry, ItemStack toolItem) {
+ public static @NotNull List<Block> execute(HolderGetter<LootTable> lootRegistry, ItemStack toolItem) {
+ LootTableMineableCollector collector = new LootTableMineableCollector(lootRegistry, toolItem);
+ List<Block> list = Lists.newArrayList();
+ for (Block block : BuiltInRegistries.BLOCK) {
+ if (!ShearsToolHandler.getInstance().test(block.defaultBlockState()).isEmpty()) {
+ continue;
+ }
+
+ LootTable lootTable = lootRegistry.get(block.getLootTable());
+ if (collector.doLootTable(lootTable)) {
+ list.add(block);
+ if (block.getLootTable().isPresent()) {
+ LootTable lootTable = lootRegistry.get(block.getLootTable().get()).map(Holder::value).orElse(null);
+ if (collector.doLootTable(lootTable)) {
+ list.add(block);
+ }
+ }
+ }
+ return list;
Expand Down Expand Up @@ -3179,7 +3184,7 @@ index 0000000000000000000000000000000000000000..63f4d0a31232525db3620095fc662f02
+ }
+ }
+ } else if (entry instanceof NestedLootTable nestedLootTable) {
+ LootTable lootTable = nestedLootTable.contents.map(lootRegistry::get, Function.identity());
+ LootTable lootTable = nestedLootTable.contents.map($ -> lootRegistry.get($).map(Holder::value).orElse(null), Function.identity());
+ return doLootTable(lootTable);
+ } else {
+ return isCorrectConditions(entry.conditions, toolItem);
Expand All @@ -3193,8 +3198,8 @@ index 0000000000000000000000000000000000000000..63f4d0a31232525db3620095fc662f02
+ }
+
+ LootItemCondition condition = conditions.getFirst();
+ if (condition instanceof MatchTool matchTool) {
+ ItemPredicate itemPredicate = matchTool.predicate().orElse(null);
+ if (condition instanceof MatchTool(Optional<ItemPredicate> predicate)) {
+ ItemPredicate itemPredicate = predicate.orElse(null);
+ return itemPredicate != null && itemPredicate.test(toolItem);
+ } else if (condition instanceof AnyOfCondition anyOfCondition) {
+ for (LootItemCondition child : anyOfCondition.terms) {
Expand Down
Loading

0 comments on commit 240a151

Please sign in to comment.