Skip to content

Commit

Permalink
Merge branch 'Moulberry:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Timongcraft authored Feb 24, 2024
2 parents a81341d + 87ad894 commit c93afb9
Show file tree
Hide file tree
Showing 16 changed files with 834 additions and 30 deletions.
21 changes: 20 additions & 1 deletion src/main/java/com/moulberry/axiom/AxiomPaper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moulberry.axiom;

import com.google.common.util.concurrent.RateLimiter;
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.event.AxiomCreateWorldPropertiesEvent;
import com.moulberry.axiom.event.AxiomModifyWorldEvent;
Expand Down Expand Up @@ -35,6 +36,9 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -50,6 +54,8 @@ public class AxiomPaper extends JavaPlugin implements Listener {
public IdMapper<BlockState> allowedBlockRegistry = null;
private boolean logLargeBlockBufferChanges = false;

public Path blueprintFolder = null;

@Override
public void onEnable() {
PLUGIN = this;
Expand Down Expand Up @@ -132,9 +138,13 @@ public void onEnable() {
if (configuration.getBoolean("packet-handlers.marker-nbt-request")) {
msg.registerIncomingPluginChannel(this, "axiom:marker_nbt_request", new MarkerNbtRequestPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.blueprint-request")) {
msg.registerIncomingPluginChannel(this, "axiom:request_blueprint", new BlueprintRequestPacketListener(this));
}

if (configuration.getBoolean("packet-handlers.set-buffer")) {
SetBlockBufferPacketListener setBlockBufferPacketListener = new SetBlockBufferPacketListener(this);
UploadBlueprintPacketListener uploadBlueprintPacketListener = new UploadBlueprintPacketListener(this);

ChannelInitializeListenerHolder.addListener(Key.key("axiom:handle_big_payload"), new ChannelInitializeListener() {
@Override
Expand All @@ -153,11 +163,20 @@ public void afterInitChannel(@NonNull Channel channel) {

Connection connection = (Connection) channel.pipeline().get("packet_handler");
channel.pipeline().addBefore("decoder", "axiom-big-payload-handler",
new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener));
new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener,
uploadBlueprintPacketListener));
}
});
}

if (this.configuration.getBoolean("blueprint-sharing")) {
this.blueprintFolder = this.getDataFolder().toPath().resolve("blueprints");
try {
Files.createDirectories(this.blueprintFolder);
} catch (IOException ignored) {}
ServerBlueprintManager.initialize(this.blueprintFolder);
}

Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
HashSet<UUID> stillActiveAxiomPlayers = new HashSet<>();

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/moulberry/axiom/blueprint/BlockEntityMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.moulberry.axiom.blueprint;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;

import java.util.HashMap;
import java.util.Map;

public class BlockEntityMap {

private static final Map<Block, BlockEntityType<?>> blockBlockEntityTypeMap = new HashMap<>();
static {
for (BlockEntityType<?> blockEntityType : BuiltInRegistries.BLOCK_ENTITY_TYPE) {
for (Block validBlock : blockEntityType.validBlocks) {
blockBlockEntityTypeMap.put(validBlock, blockEntityType);
}
}
}

public static BlockEntityType<?> get(Block block) {
return blockBlockEntityTypeMap.get(block);
}

}
65 changes: 65 additions & 0 deletions src/main/java/com/moulberry/axiom/blueprint/BlueprintHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.moulberry.axiom.blueprint;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;

import java.util.ArrayList;
import java.util.List;

public record BlueprintHeader(String name, String author, List<String> tags, float thumbnailYaw, float thumbnailPitch, boolean lockedThumbnail, int blockCount) {

private static final int CURRENT_VERSION = 0;

public void write(FriendlyByteBuf friendlyByteBuf) {
friendlyByteBuf.writeUtf(this.name);
friendlyByteBuf.writeUtf(this.author);
friendlyByteBuf.writeCollection(this.tags, FriendlyByteBuf::writeUtf);
friendlyByteBuf.writeInt(this.blockCount);
}

public static BlueprintHeader read(FriendlyByteBuf friendlyByteBuf) {
String name = friendlyByteBuf.readUtf();
String author = friendlyByteBuf.readUtf();
List<String> tags = friendlyByteBuf.readList(FriendlyByteBuf::readUtf);
int blockCount = friendlyByteBuf.readInt();
return new BlueprintHeader(name, author, tags, 0, 0, true, blockCount);
}

public static BlueprintHeader load(CompoundTag tag) {
long version = tag.getLong("Version");
String name = tag.getString("Name");
String author = tag.getString("Author");
float thumbnailYaw = tag.contains("ThumbnailYaw", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailYaw") : 135;
float thumbnailPitch = tag.contains("ThumbnailPitch", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailPitch") : 30;
boolean lockedThumbnail = tag.getBoolean("LockedThumbnail");
int blockCount = tag.getInt("BlockCount");

List<String> tags = new ArrayList<>();
for (Tag string : tag.getList("Tags", Tag.TAG_STRING)) {
tags.add(string.getAsString());
}

return new BlueprintHeader(name, author, tags, thumbnailYaw, thumbnailPitch, lockedThumbnail, blockCount);
}

public CompoundTag save(CompoundTag tag) {
ListTag listTag = new ListTag();
for (String string : this.tags) {
listTag.add(StringTag.valueOf(string));
}

tag.putLong("Version", CURRENT_VERSION);
tag.putString("Name", this.name);
tag.putString("Author", this.author);
tag.put("Tags", listTag);
tag.putFloat("ThumbnailYaw", this.thumbnailYaw);
tag.putFloat("ThumbnailPitch", this.thumbnailPitch);
tag.putBoolean("LockedThumbnail", this.lockedThumbnail);
tag.putInt("BlockCount", this.blockCount);
return tag;
}

}
Loading

0 comments on commit c93afb9

Please sign in to comment.