Skip to content

Commit

Permalink
add and apply editorconfig, fmj templating
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Jul 28, 2024
1 parent dc8950f commit 941225e
Show file tree
Hide file tree
Showing 108 changed files with 1,400 additions and 1,408 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[*]
indent_size = 4
indent_style = tab
tab_width = 4

[*.java]
ij_java_block_brace_style = end_of_line
ij_java_lambda_brace_style = end_of_line
ij_java_method_brace_style = end_of_line
ij_java_names_count_to_use_import_on_demand = 999

[{*.gant,*.groovy,*.gy,*.gradle}]
ij_groovy_block_brace_style = end_of_line
ij_groovy_class_brace_style = end_of_line
ij_groovy_lambda_brace_style = end_of_line
ij_groovy_method_brace_style = end_of_line

[{*.har,*.json,*.png.mcmeta,mcmod.info,pack.mcmeta}]
ij_json_array_wrapping = split_into_lines
35 changes: 21 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ plugins {
}

version = "$project.baseVersion+$project.branch"
archivesBaseName = "fireblanket"
group = "net.modfest"
archivesBaseName = project.archivesName

repositories {
maven { url "https://api.modrinth.com/maven" }
Expand All @@ -29,25 +28,33 @@ dependencies {
modImplementation libs.nettyIoUringClasses
modImplementation variantOf(libs.nettyIoUringNative) { classifier "linux-x86_64" }
modImplementation libs.zstd

modImplementation libs.worldeditCore
modImplementation libs.worldeditFabric

shade(libs.nettyIoUringClasses) { transitive = false }
shade(variantOf(libs.nettyIoUringNative) { classifier "linux-x86_64" }) { transitive = false }
shade(libs.zstd) { transitive = false }
}

processResources {
final Map<String, String> map = [
"version": version.toString(),
"mc" : libs.versions.mc.get(),
"fl" : libs.versions.fl.get(),
"fapi" : libs.versions.fapi.get()
final Map<String, String> meta = [
version : version,
modId : modId,
modName : modName,
modDescription: modDescription,
homepage : homepage,
issues : issues,
sources : sources,
license : license,
authors : authors.split(", ").join("\",\n \""),
contributors : contributors.split(", ").join("\",\n \""),
mc : libs.versions.mc.get(),
fl : libs.versions.fl.get(),
fapi : libs.versions.fapi.get()
]

inputs.properties(map)
filesMatching("*.mod.json") { expand(map) }
inputs.properties meta
filesMatching("fabric.mod.json") { expand meta }
}

tasks.withType(JavaCompile).configureEach {
Expand Down Expand Up @@ -75,9 +82,9 @@ java {

jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
rename { "${it}_${project.base.archivesName.get()}" }
}

configurations.shade.resolve().each {
from(zipTree(it)) {
exclude 'META-INF/MANIFEST.MF'
Expand Down
21 changes: 18 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# Gradle Properties
# Gradle
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.caching.debug=false
org.gradle.configureondemand=true
# Enable advanced multi-module optimizations (share tiny-remaper instance between projects)

# Loom
fabric.loom.multiProjectOptimisation=true
# Mod Properties

# Mod Metadata
archivesName=fireblanket
group=net.modfest
modId=fireblanket
modName=Fireblanket
modDescription=Performance, bugfixes, and utilities for ModFest events.
authors=jaskarth, unascribed
contributors=Patbox, IThundxr
homepage=https://modrinth.com/mod/fireblanket
issues=https://github.com/modfest/fireblanket/issues
sources=https://github.com/modfest/fireblanket
license=AGPL-3.0-or-later

# Mod Version
baseVersion = 0.5.4
branch = 1.21
53 changes: 27 additions & 26 deletions src/main/java/net/modfest/fireblanket/Fireblanket.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ public class Fireblanket implements ModInitializer {
public static final Identifier REGIONS_UPDATE = Identifier.of("fireblanket", "regions_update");

public static final Logger LOGGER = LoggerFactory.getLogger("Fireblanket");

public record QueuedPacket(ClientConnection conn, Packet<?> packet, PacketCallbacks listener) {}


public record QueuedPacket(ClientConnection conn, Packet<?> packet, PacketCallbacks listener) {
}

private static final AtomicInteger nextQueue = new AtomicInteger();

@SuppressWarnings("unchecked")
public static final LinkedBlockingQueue<QueuedPacket>[] PACKET_QUEUES = new LinkedBlockingQueue[4];

public static boolean CAN_USE_ZSTD = false;

public static final ChunkTicketType<ChunkPos> KEEP_LOADED = ChunkTicketType.create("fireblanket:keep_loaded", ChunkTicketType.FORCED.getArgumentComparator());

@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, access, environment) -> {
Expand All @@ -83,7 +84,7 @@ public void onInitialize() {
RegionCommand.init(base, access);
CmdFindReplaceCommand.init(base, access);
dispatcher.register(CommandManager.literal("fb")
.redirect(dispatcher.register(base)));
.redirect(dispatcher.register(base)));
});

for (Block block : Registries.BLOCK) {
Expand All @@ -102,24 +103,24 @@ public void onInitialize() {
EntityFilters.parse(types);
}
}

for (int i = 0; i < PACKET_QUEUES.length; i++) {
LinkedBlockingQueue<QueuedPacket> q = new LinkedBlockingQueue<>();
PACKET_QUEUES[i] = q;
Thread thread = new Thread(() -> {
while (true) {
try {
QueuedPacket p = q.take();
((ClientConnectionAccessor)p.conn()).fireblanket$sendImmediately(p.packet(), p.listener(), true);
((ClientConnectionAccessor) p.conn()).fireblanket$sendImmediately(p.packet(), p.listener(), true);
} catch (Throwable t) {
LOGGER.error("Exception in packet thread", t);
}
}
}, "Fireblanket async packet send thread #"+(i+1));
}, "Fireblanket async packet send thread #" + (i + 1));
thread.setDaemon(true);
thread.start();
}

try {
// TODO: ZSTD compression does not work with 1.20.2+ packet handling
// Native.load();
Expand All @@ -143,26 +144,26 @@ public void onInitialize() {
}
});
}

ServerLoginNetworking.registerGlobalReceiver(FULL_STREAM_COMPRESSION, (server, handler, understood, buf, synchronizer, responseSender) -> {
if (understood) {
((FSCConnection)((ServerLoginNetworkHandlerAccessor)handler).fireblanket$getConnection()).fireblanket$enableFullStreamCompression();
((FSCConnection) ((ServerLoginNetworkHandlerAccessor) handler).fireblanket$getConnection()).fireblanket$enableFullStreamCompression();
}
});

if (FabricLoader.getInstance().isModLoaded("polymc")) {
PolyMcCompat.init();
}

ServerWorldEvents.LOAD.register((server, world) -> {
if (System.getProperty("fireblanket.loadRadius") != null) {
if (!world.getRegistryKey().getValue().toString().equals("minecraft:overworld")) return;
int radius = Integer.getInteger("fireblanket.loadRadius");
int min = (int)Math.floor(-radius/16);
int max = (int)Math.ceil(radius/16);
int count = (max-min)*(max-min);
ChunkTicketManager mgr = ((ServerChunkManagerAccessor)world.getChunkManager()).fireblanket$getTicketManager();
LOGGER.info("Forcing "+count+" chunks to stay loaded (but not ticking)...");
int min = (int) Math.floor(-radius / 16);
int max = (int) Math.ceil(radius / 16);
int count = (max - min) * (max - min);
ChunkTicketManager mgr = ((ServerChunkManagerAccessor) world.getChunkManager()).fireblanket$getTicketManager();
LOGGER.info("Forcing " + count + " chunks to stay loaded (but not ticking)...");
int done = 0;
long lastReport = System.nanoTime();
Stopwatch sw = Stopwatch.createStarted();
Expand All @@ -174,20 +175,20 @@ public void onInitialize() {
// one above FULL; out of range, but not so far to unload
mgr.addTicketWithLevel(KEEP_LOADED, pos, 34, pos);
done++;
if (System.nanoTime()-lastReport > 1_000_000_000) {
if (System.nanoTime() - lastReport > 1_000_000_000) {
lastReport = System.nanoTime();
LOGGER.info(done+"/"+count+" loaded ("+((done*100)/count)+"%)...");
LOGGER.info(done + "/" + count + " loaded (" + ((done * 100) / count) + "%)...");
}
}
}
LOGGER.info("Done after "+sw);
LOGGER.info("Done after " + sw);
}
});

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
fullRegionSync(handler.player.getServerWorld(), sender::sendPacket);
});

ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> {
fullRegionSync(player.getServerWorld(), player.networkHandler::sendPacket);
});
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/net/modfest/fireblanket/FireblanketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import net.modfest.fireblanket.world.render_regions.RenderRegions;

public class FireblanketClient implements ClientModInitializer {

public static final RenderRegions renderRegions = new RenderRegions();

@Override
public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, access) -> {
Expand All @@ -49,12 +49,12 @@ public void onInitializeClient() {
base.then(mask);
}
dispatcher.register(ClientCommandManager.literal("fbc")
.redirect(dispatcher.register(base)));
.redirect(dispatcher.register(base)));
});

ClientLoginNetworking.registerGlobalReceiver(Fireblanket.FULL_STREAM_COMPRESSION, (client, handler, buf, listenerAdder) -> {
if (Fireblanket.CAN_USE_ZSTD) {
((FSCConnection)((ClientLoginNetworkHandlerAccessor)handler).fireblanket$getConnection()).fireblanket$enableFullStreamCompression();
((FSCConnection) ((ClientLoginNetworkHandlerAccessor) handler).fireblanket$getConnection()).fireblanket$enableFullStreamCompression();
return CompletableFuture.completedFuture(PacketByteBufs.empty());
} else {
return CompletableFuture.completedFuture(null);
Expand All @@ -79,11 +79,9 @@ public void onInitializeClient() {
ClientPlayNetworking.registerGlobalReceiver(CommandBlockPacket.ID, (payload, ctx) -> {
ctx.client().execute(() -> MinecraftClient.getInstance().setScreen(new PlaceCommandBlockScreen()));
});

ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
client.send(() -> {
renderRegions.clear();
});
client.send(renderRegions::clear);
});
}

Expand All @@ -102,5 +100,5 @@ private static Vec3d getCameraPos() {
Vec3d c = mc.gameRenderer.getCamera().getPos();
return c;
}

}
Loading

0 comments on commit 941225e

Please sign in to comment.