Skip to content

Commit aabbf79

Browse files
1.21.4 Spigot adapters (#8)
* 1.21.4 adapter for spigot * forgot to add it to spigot-all * forgot that the R suffix is made up. cool.
1 parent 1099f9a commit aabbf79

File tree

6 files changed

+116
-2
lines changed

6 files changed

+116
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
allprojects {
33
group = "org.geysermc.geyser.adapters"
4-
version = "1.15-SNAPSHOT"
4+
version = "1.16-SNAPSHOT"
55
description = "Adapters for Geyser"
66
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
dependencies {
6-
implementation("io.papermc.paperweight:paperweight-userdev:1.7.1")
6+
implementation("io.papermc.paperweight:paperweight-userdev:1.7.7")
77
implementation("com.github.johnrengelman", "shadow", "8.1.1")
88
}
99

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include(":spigot:v1_20_R3")
1919
include(":spigot:v1_20_R4")
2020
include(":spigot:v1_21_R1")
2121
include(":spigot:v1_21_R2")
22+
include(":spigot:v1_21_R3")
2223

2324
include(":paper")
2425
include(":paper:all")

spigot/all/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
adapter("1_20_R4")
2525
adapter("1_21_R1")
2626
adapter("1_21_R2")
27+
adapter("1_21_R3")
2728
}
2829

2930
tasks {

spigot/v1_21_R3/build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
plugins {
3+
id("adapters.spigot.paperweight-conventions")
4+
}
5+
6+
java {
7+
sourceCompatibility = JavaVersion.VERSION_21
8+
targetCompatibility = JavaVersion.VERSION_21
9+
toolchain {
10+
languageVersion = JavaLanguageVersion.of(21)
11+
}
12+
}
13+
14+
dependencies {
15+
implementation(projects.spigot.base)
16+
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")
17+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.adapters.spigot.v1_21_R3;
27+
28+
import it.unimi.dsi.fastutil.ints.IntArrayList;
29+
import it.unimi.dsi.fastutil.ints.IntList;
30+
import net.minecraft.core.Registry;
31+
import net.minecraft.core.registries.Registries;
32+
import net.minecraft.resources.ResourceLocation;
33+
import net.minecraft.server.MinecraftServer;
34+
import net.minecraft.world.level.biome.Biome;
35+
import net.minecraft.world.level.block.Block;
36+
import net.minecraft.world.level.block.state.BlockState;
37+
import net.minecraft.world.level.chunk.LevelChunk;
38+
import net.minecraft.world.level.chunk.LevelChunkSection;
39+
import org.bukkit.World;
40+
import org.bukkit.craftbukkit.CraftWorld;
41+
import org.geysermc.geyser.adapters.spigot.SpigotWorldAdapter;
42+
43+
import java.util.ArrayList;
44+
import java.util.List;
45+
import java.util.stream.Stream;
46+
47+
public class WorldAdapter_v1_21_R3 extends SpigotWorldAdapter {
48+
@Override
49+
public int getBlockAt(World world, int x, int y, int z) {
50+
if (y < world.getMinHeight()) {
51+
return 0;
52+
}
53+
54+
LevelChunk chunk = ((CraftWorld) world).getHandle().getChunkIfLoaded(x >> 4, z >> 4);
55+
if (chunk == null) { // should never happen but just to be on the safe side
56+
return 0;
57+
}
58+
int worldOffset = world.getMinHeight() >> 4;
59+
int chunkOffset = (y >> 4) - worldOffset;
60+
if (chunkOffset < chunk.getSections().length) {
61+
LevelChunkSection section = chunk.getSections()[chunkOffset];
62+
if (section != null && !section.hasOnlyAir()) {
63+
return Block.getId(section.getBlockState(x & 15, y & 15, z & 15));
64+
}
65+
}
66+
return 0;
67+
}
68+
69+
@Override
70+
public IntList getAllBlockStates() {
71+
IntList blockStates = new IntArrayList();
72+
for (BlockState block : Block.BLOCK_STATE_REGISTRY) {
73+
blockStates.add(Block.getId(block));
74+
}
75+
return blockStates;
76+
}
77+
78+
@Override
79+
public String[] getBiomeSuggestions(boolean tags) {
80+
Registry<Biome> registry = MinecraftServer.getServer()
81+
.registryAccess()
82+
.lookupOrThrow(Registries.BIOME);
83+
if (!tags) {
84+
return getBiomes(registry).toArray(String[]::new);
85+
}
86+
87+
List<String> keys = new ArrayList<>(registry.getTags().map(tag -> "#" + tag.key().location()).toList());
88+
keys.addAll(getBiomes(registry).toList());
89+
return keys.toArray(new String[0]);
90+
}
91+
92+
private Stream<String> getBiomes(Registry<Biome> registry) {
93+
return registry.keySet().stream().map(ResourceLocation::toString);
94+
}
95+
}

0 commit comments

Comments
 (0)