Skip to content

Commit c93afb9

Browse files
authored
Merge branch 'Moulberry:master' into master
2 parents a81341d + 87ad894 commit c93afb9

16 files changed

+834
-30
lines changed

src/main/java/com/moulberry/axiom/AxiomPaper.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.moulberry.axiom;
22

33
import com.google.common.util.concurrent.RateLimiter;
4+
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
45
import com.moulberry.axiom.buffer.CompressedBlockEntity;
56
import com.moulberry.axiom.event.AxiomCreateWorldPropertiesEvent;
67
import com.moulberry.axiom.event.AxiomModifyWorldEvent;
@@ -35,6 +36,9 @@
3536
import org.checkerframework.checker.nullness.qual.NonNull;
3637
import org.jetbrains.annotations.Nullable;
3738

39+
import java.io.IOException;
40+
import java.nio.file.Files;
41+
import java.nio.file.Path;
3842
import java.util.*;
3943
import java.util.concurrent.ConcurrentHashMap;
4044

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

57+
public Path blueprintFolder = null;
58+
5359
@Override
5460
public void onEnable() {
5561
PLUGIN = this;
@@ -132,9 +138,13 @@ public void onEnable() {
132138
if (configuration.getBoolean("packet-handlers.marker-nbt-request")) {
133139
msg.registerIncomingPluginChannel(this, "axiom:marker_nbt_request", new MarkerNbtRequestPacketListener(this));
134140
}
141+
if (configuration.getBoolean("packet-handlers.blueprint-request")) {
142+
msg.registerIncomingPluginChannel(this, "axiom:request_blueprint", new BlueprintRequestPacketListener(this));
143+
}
135144

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

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

154164
Connection connection = (Connection) channel.pipeline().get("packet_handler");
155165
channel.pipeline().addBefore("decoder", "axiom-big-payload-handler",
156-
new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener));
166+
new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener,
167+
uploadBlueprintPacketListener));
157168
}
158169
});
159170
}
160171

172+
if (this.configuration.getBoolean("blueprint-sharing")) {
173+
this.blueprintFolder = this.getDataFolder().toPath().resolve("blueprints");
174+
try {
175+
Files.createDirectories(this.blueprintFolder);
176+
} catch (IOException ignored) {}
177+
ServerBlueprintManager.initialize(this.blueprintFolder);
178+
}
179+
161180
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
162181
HashSet<UUID> stillActiveAxiomPlayers = new HashSet<>();
163182

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.moulberry.axiom.blueprint;
2+
3+
import net.minecraft.core.registries.BuiltInRegistries;
4+
import net.minecraft.world.level.block.Block;
5+
import net.minecraft.world.level.block.entity.BlockEntityType;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class BlockEntityMap {
11+
12+
private static final Map<Block, BlockEntityType<?>> blockBlockEntityTypeMap = new HashMap<>();
13+
static {
14+
for (BlockEntityType<?> blockEntityType : BuiltInRegistries.BLOCK_ENTITY_TYPE) {
15+
for (Block validBlock : blockEntityType.validBlocks) {
16+
blockBlockEntityTypeMap.put(validBlock, blockEntityType);
17+
}
18+
}
19+
}
20+
21+
public static BlockEntityType<?> get(Block block) {
22+
return blockBlockEntityTypeMap.get(block);
23+
}
24+
25+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.moulberry.axiom.blueprint;
2+
3+
import net.minecraft.nbt.CompoundTag;
4+
import net.minecraft.nbt.ListTag;
5+
import net.minecraft.nbt.StringTag;
6+
import net.minecraft.nbt.Tag;
7+
import net.minecraft.network.FriendlyByteBuf;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
public record BlueprintHeader(String name, String author, List<String> tags, float thumbnailYaw, float thumbnailPitch, boolean lockedThumbnail, int blockCount) {
13+
14+
private static final int CURRENT_VERSION = 0;
15+
16+
public void write(FriendlyByteBuf friendlyByteBuf) {
17+
friendlyByteBuf.writeUtf(this.name);
18+
friendlyByteBuf.writeUtf(this.author);
19+
friendlyByteBuf.writeCollection(this.tags, FriendlyByteBuf::writeUtf);
20+
friendlyByteBuf.writeInt(this.blockCount);
21+
}
22+
23+
public static BlueprintHeader read(FriendlyByteBuf friendlyByteBuf) {
24+
String name = friendlyByteBuf.readUtf();
25+
String author = friendlyByteBuf.readUtf();
26+
List<String> tags = friendlyByteBuf.readList(FriendlyByteBuf::readUtf);
27+
int blockCount = friendlyByteBuf.readInt();
28+
return new BlueprintHeader(name, author, tags, 0, 0, true, blockCount);
29+
}
30+
31+
public static BlueprintHeader load(CompoundTag tag) {
32+
long version = tag.getLong("Version");
33+
String name = tag.getString("Name");
34+
String author = tag.getString("Author");
35+
float thumbnailYaw = tag.contains("ThumbnailYaw", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailYaw") : 135;
36+
float thumbnailPitch = tag.contains("ThumbnailPitch", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailPitch") : 30;
37+
boolean lockedThumbnail = tag.getBoolean("LockedThumbnail");
38+
int blockCount = tag.getInt("BlockCount");
39+
40+
List<String> tags = new ArrayList<>();
41+
for (Tag string : tag.getList("Tags", Tag.TAG_STRING)) {
42+
tags.add(string.getAsString());
43+
}
44+
45+
return new BlueprintHeader(name, author, tags, thumbnailYaw, thumbnailPitch, lockedThumbnail, blockCount);
46+
}
47+
48+
public CompoundTag save(CompoundTag tag) {
49+
ListTag listTag = new ListTag();
50+
for (String string : this.tags) {
51+
listTag.add(StringTag.valueOf(string));
52+
}
53+
54+
tag.putLong("Version", CURRENT_VERSION);
55+
tag.putString("Name", this.name);
56+
tag.putString("Author", this.author);
57+
tag.put("Tags", listTag);
58+
tag.putFloat("ThumbnailYaw", this.thumbnailYaw);
59+
tag.putFloat("ThumbnailPitch", this.thumbnailPitch);
60+
tag.putBoolean("LockedThumbnail", this.lockedThumbnail);
61+
tag.putInt("BlockCount", this.blockCount);
62+
return tag;
63+
}
64+
65+
}

0 commit comments

Comments
 (0)