Skip to content

Commit

Permalink
1.19 protocol and features (#1139)
Browse files Browse the repository at this point in the history
* ImmutableItemStack ItemMeta NPE
  • Loading branch information
kamcio96 authored Jun 22, 2022
1 parent ff85c0d commit fc908c6
Show file tree
Hide file tree
Showing 79 changed files with 2,686 additions and 727 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dependency-reduced-pom.xml
.db
.DS_Store
.vscode
server
25 changes: 24 additions & 1 deletion src/main/java/net/glowstone/GlowServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import com.jogamp.common.util.IOUtil;
import com.jogamp.opencl.CLDevice;
import com.jogamp.opencl.CLPlatform;
import com.tobedevoured.naether.NaetherException;
Expand Down Expand Up @@ -140,9 +141,13 @@
import net.glowstone.util.linkstone.LinkstonePluginLoader;
import net.glowstone.util.linkstone.LinkstonePluginScanner;
import net.glowstone.util.loot.LootingManager;
import net.glowstone.util.mojangson.Mojangson;
import net.glowstone.util.mojangson.ex.MojangsonParseException;
import net.glowstone.util.nbt.CompoundTag;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.chat.BaseComponent;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
Expand Down Expand Up @@ -181,6 +186,7 @@
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -221,8 +227,11 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
Expand Down Expand Up @@ -277,7 +286,7 @@ public class GlowServer implements Server {
/**
* The protocol version supported by the server.
*/
public static final int PROTOCOL_VERSION = NoInline.of(754);
public static final int PROTOCOL_VERSION = NoInline.of(759);
/**
* The data version supported by the server.
*/
Expand Down Expand Up @@ -498,6 +507,9 @@ public org.bukkit.configuration.file.YamlConfiguration getConfig() {
@Setter
private int maxPlayers;

@Getter
private CompoundTag registry;

/**
* Creates a new server.
*
Expand Down Expand Up @@ -831,6 +843,17 @@ public void start() {
e.printStackTrace();
}


try {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("builtin/dimensions.mojangson");
registry = Mojangson.parseCompound(new String(inputStream.readAllBytes(), StandardCharsets.UTF_8));
} catch (MojangsonParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


// Start loading plugins
String repository = config.getString(Key.LIBRARY_REPOSITORY_URL);
String libraryFolder = config.getString(Key.LIBRARIES_FOLDER);
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/net/glowstone/GlowWorldBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public GlowWorldBorder(World world) {
*/
public WorldBorderMessage createMessage() {
return new WorldBorderMessage(
WorldBorderMessage.Action.INITIALIZE, center.getX(), center.getZ(),
center.getX(), center.getZ(),
size, sizeLerpTarget, sizeLerpTime * 1000, 29999984,
warningTime, warningDistance);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public void reset() {
public void setSize(double size) {
this.size = size;
this.sizeLerpTarget = size;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_SIZE, size));
broadcast(createMessage()); // TODO 1.19 packet
}

@Override
Expand All @@ -128,15 +128,13 @@ public void setSize(double size, long seconds) {
step = (size - this.size) / (double) ticks;
sizeLerpTarget = size;
sizeLerpTime = seconds;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.LERP_SIZE,
this.size, sizeLerpTarget, sizeLerpTime * 1000));
broadcast(createMessage()); // TODO 1.19 packet
}

@Override
public void setCenter(Location location) {
center = location.clone();
broadcast(new WorldBorderMessage(
WorldBorderMessage.Action.SET_CENTER, center.getX(), center.getZ()));
broadcast(createMessage()); // TODO 1.19 packet
}

@Override
Expand All @@ -147,13 +145,13 @@ public void setCenter(double x, double z) {
@Override
public void setWarningTime(int seconds) {
this.warningTime = seconds;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_WARNING_TIME, seconds));
broadcast(createMessage()); // TODO 1.19 packet
}

@Override
public void setWarningDistance(int distance) {
this.warningDistance = distance;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_WARNING_BLOCKS, distance));
broadcast(createMessage()); // TODO 1.19 packet
}

@Override
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/net/glowstone/chunk/DimensionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.glowstone.chunk;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.bukkit.NamespacedKey;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.OptionalLong;

@Data
@AllArgsConstructor
public final class DimensionType {

private final boolean piglinSafe;

private final boolean hasRaids;

private final int monsterSpawnLightLevel;

private final int monsterSpawnBlockLightLimit;

private final boolean natural;

private final float ambientLight;

private final OptionalLong fixedTime;

@Nullable
private final Optional<NamespacedKey> infiniburn;

private final boolean respawnAnchorWorks;

private final boolean skyLight;

private final boolean bedWorks;

private final NamespacedKey effects;

private final int minY;

private final int height;

private final int logicalHeight;

private final double coordinateScale;

private final boolean ultraWarm;

private final boolean hasCeiling;

}
31 changes: 31 additions & 0 deletions src/main/java/net/glowstone/chunk/DimensionTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.glowstone.chunk;

import org.bukkit.NamespacedKey;

import java.util.Optional;
import java.util.OptionalLong;

public class DimensionTypes {

public static final DimensionType OVERWORLD = new DimensionType(
false,
true,
7,
0,
true,
0.0F,
OptionalLong.empty(),
Optional.empty(),
false,
true,
true,
NamespacedKey.minecraft("overworld"),
-64,
384,
384,
1.0D,
false,
false
);

}
59 changes: 29 additions & 30 deletions src/main/java/net/glowstone/chunk/GlowChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.logging.Level;
Expand Down Expand Up @@ -76,6 +69,9 @@ public class GlowChunk implements Chunk {
* The number of chunk sections in a single chunk column.
*/
public static final int SEC_COUNT = DEPTH / SEC_DEPTH;

public static final byte[] EMPTY_LIGHT = new byte[2048];

/**
* The world of this chunk.
*/
Expand Down Expand Up @@ -955,33 +951,12 @@ public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk) {
public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk,
ByteBufAllocator alloc) {
load();
int sectionBitmask = 0;

// filter sectionBitmask based on actual chunk contents
if (sections != null) {
int maxBitmask = (1 << sections.length) - 1;
if (entireChunk) {
sectionBitmask = maxBitmask;
} else {
sectionBitmask &= maxBitmask;
}

for (int i = 0; i < sections.length; ++i) {
if (sections[i] == null || sections[i].isEmpty()) {
// remove empty sections from bitmask
sectionBitmask &= ~(1 << i);
}
}
}

ByteBuf buf = alloc == null ? Unpooled.buffer() : alloc.buffer();

if (sections != null) {
// get the list of sections
for (int i = 0; i < sections.length; ++i) {
if ((sectionBitmask & 1 << i) == 0) {
continue;
}
sections[i].writeToBuf(buf, skylight);
}
}
Expand All @@ -1002,7 +977,31 @@ public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk,
blockEntities.add(tag);
}

return new ChunkDataMessage(x, z, entireChunk, sectionBitmask, buf, blockEntities);
CompoundTag heightMap = new CompoundTag();
heightMap.putByteArray("MOTION_BLOCKING", this.heightMap);


BitSet skyLightMask = new BitSet();
BitSet blockLightMask = new BitSet();

for (int i = 0; i < SEC_COUNT + 2; i++) {
skyLightMask.set(i);
blockLightMask.set(i);
}

return new ChunkDataMessage(x, z, heightMap, buf, blockEntities, true, skyLightMask, blockLightMask, new BitSet(), new BitSet(),
Arrays.asList(
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT),
Arrays.asList(
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT, EMPTY_LIGHT,
EMPTY_LIGHT, EMPTY_LIGHT));
}

public void addTick() {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/glowstone/chunk/SectionPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.glowstone.chunk;

import lombok.Data;

@Data
public class SectionPosition {

private final int x;
private final int y;
private final int z;

public static SectionPosition fromLong(long encoded) {
int sectionX = (int) (encoded >> 42);
int sectionY = (int) (encoded << 44 >> 44);
int sectionZ = (int) (encoded << 22 >> 42);
return new SectionPosition(sectionX, sectionY, sectionZ);
}

public long asLong() {
return ((x & 0x3FFFFF) << 42) | (y & 0xFFFFF) | ((z & 0x3FFFFF) << 20);
}
}
53 changes: 53 additions & 0 deletions src/main/java/net/glowstone/chunk/WorldGenBiome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.glowstone.chunk;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Optional;
import java.util.OptionalInt;

@Data
@AllArgsConstructor
public class WorldGenBiome {

private String precipitation;

private float depth;

private float temperature;

private float scale;

private float downfall;

private String category;

private Optional<String> temperatureModifier;

private int skyColor;

private int waterFogColor;

private int fogColor;

private int waterColor;

private OptionalInt foliageColor;

private OptionalInt grassColor;

private Optional<String> grassColorModifier;

private Optional<String> music;

private Optional<String> ambientSound;

private Optional<String> additionsSound;

private Optional<String> moodSound;

private float particleProbability;

private String particleOptions;

}
Loading

0 comments on commit fc908c6

Please sign in to comment.