Skip to content

Commit

Permalink
Update to 1.20.4; use new networking API on neoforge and switch aroun…
Browse files Browse the repository at this point in the history
…d system on fabric
  • Loading branch information
lukebemish committed Jan 6, 2024
1 parent 68d5e41 commit da129a8
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 99 deletions.
58 changes: 54 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,60 @@ plugins {
managedVersioning {
versionFile.set rootProject.file('version.properties')
metadataVersion.set libs.versions.minecraft
if (System.getenv('PR_NUMBER')) {
suffix.set("pr${System.getenv('PR_NUMBER')}")
} else if (System.getenv('SNAPSHOT_MAVEN_URL')) {
suffix.set('SNAPSHOT')
versionPRs()
versionSnapshots()

gitHubActions {
snapshot {
prettyName.set 'Snapshot'
workflowDispatch.set(true)
onBranches.add '1.*'
gradleJob {
buildCache()
name.set 'build'
gradlew 'Build', 'checkLicenses', 'build'
gradlew 'Publish', 'publish'
mavenSnapshot('github')
}
}
release {
prettyName.set 'Release'
workflowDispatch.set(true)
gradleJob {
buildCache()
name.set 'build'
step {
setupGitUser()
}
readOnly.set false
gradlew 'Tag Release', 'tagRelease'
gradlew 'Build', 'checkLicenses', 'build'
step {
run.set 'git push && git push --tags'
}
gradlew 'Publish', 'publish', 'modrinth', 'curseforge'
mavenRelease('github')
modPublishing()
}
}
build_pr {
prettyName.set 'Build PR'
pullRequest.set(true)
gradleJob {
name.set 'build'
gradlew 'Build', 'checkLicenses', 'build'
gradlew 'Publish', 'publish'
pullRequestArtifact()
}
}
publish_pr {
prettyName.set 'Publish PR'
publishPullRequestAction(
'github',
'dev/lukebemish/dynamicassetgenerator/dynamicassetgenerator-*',
'Build PR'
)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies {

compileOnly libs.dynassetgen.common
compileOnly libs.defaultresources.common

compileOnly libs.mixinextras.common
}

artifacts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Luke Bemish and contributors
* Copyright (C) 2023-2024 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

Expand Down Expand Up @@ -68,7 +68,7 @@ public class ModifiedOreBlock extends DropExperienceBlock {
private Property<?>[] props;

public ModifiedOreBlock(ExcavatedVariants.VariantFuture future) {
super(copyProperties(future), getXpProvider(future));
super(getXpProvider(future), copyProperties(future));
this.ore = future.ore;
this.stone = future.stone;
this.flags = Set.copyOf(future.flags);
Expand Down Expand Up @@ -119,8 +119,8 @@ private static Properties copyProperties(ExcavatedVariants.VariantFuture future)
Block stoneTarget = future.foundStone;
BlockBehaviour.Properties outProperties;
if (target != null && stoneTarget != null) {
Properties properties = Properties.copy(stoneTarget);
Properties oreProperties = Properties.copy(target);
Properties properties = Properties.ofFullCopy(stoneTarget);
Properties oreProperties = Properties.ofFullCopy(target);
properties.requiresCorrectToolForDrops();
BlockPropertiesMixin newProperties = (BlockPropertiesMixin) properties;
BlockPropertiesMixin oreProps = (BlockPropertiesMixin) oreProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2024 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

package dev.lukebemish.excavatedvariants.impl.network;

import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

public record AckOresPayload() {
public static final ResourceLocation ID = ExcavatedVariants.id("ack_ores");
public static AckOresPayload decode(FriendlyByteBuf buffer) {
return new AckOresPayload();
}

public void encode(FriendlyByteBuf buffer) {}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
/*
* Copyright (C) 2023 Luke Bemish and contributors
* Copyright (C) 2023-2024 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

package dev.lukebemish.excavatedvariants.impl;
package dev.lukebemish.excavatedvariants.impl.network;

import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public record S2CConfigAgreementPacket(Set<String> blocks) {
public record SyncOresPayload(Set<String> blocks) {
public static final ResourceLocation ID = ExcavatedVariants.id("sync_ores");

public static S2CConfigAgreementPacket decoder(FriendlyByteBuf buffer) {
public static SyncOresPayload decode(FriendlyByteBuf buffer) {
ArrayList<String> blocks = new ArrayList<>();
int i = buffer.readInt();
for (int j = 0; j < i; j++) blocks.add(buffer.readUtf());
return new S2CConfigAgreementPacket(new HashSet<>(blocks));
return new SyncOresPayload(new HashSet<>(blocks));
}

private static String ellipsis(String str, @SuppressWarnings("SameParameterValue") int length) {
if (str.length() <= length) return str;
else return str.substring(0, length - 3) + "...";
}

public void encoder(FriendlyByteBuf buffer) {
public void encode(FriendlyByteBuf buffer) {
buffer.writeInt(blocks.size());
blocks.forEach(buffer::writeUtf);
}
Expand All @@ -47,19 +43,13 @@ public void consumeMessage(Consumer<String> disconnecter) {
if (!clientOnly.isEmpty()) {
String clientOnlyStr = String.join("\n ", clientOnly.stream().toList());
ExcavatedVariants.LOGGER.error("Client contains ore variants not present on server:\n {}", clientOnlyStr);
disconnect += "\nMissing on server: " + ellipsis(clientOnly.toString(), 50);
disconnect += "\nSee log for details";
}
if (!serverOnly.isEmpty()) {
String serverOnlyStr = String.join("\n ", serverOnly.stream().toList());
ExcavatedVariants.LOGGER.error("Server contains ore variants not present on client:\n {}", serverOnlyStr);
disconnect += "\nMissing on client: " + ellipsis(serverOnly.toString(), 50);
disconnect += "\nSee log for details";
}
disconnecter.accept(disconnect);
}

public static final class ExcavatedVariantsDisconnectPacket extends ClientboundLoginDisconnectPacket {
public ExcavatedVariantsDisconnectPacket(String reason) {
super(Component.literal(reason));
}
}
}
16 changes: 16 additions & 0 deletions common/src/main/resources/mods.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import modsdotgroovy.Dependency

/*
* Copyright (C) 2023 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
Expand Down Expand Up @@ -54,6 +56,20 @@ ModsDotGroovy.make {
}
}

onForge {
dependencies = dependencies.collect { dep ->
new Dependency() {
@Override
Map asForgeMap() {
def map = dep.asForgeMap()
map.remove('mandatory')
map.put('type', this.mandatory ? 'required' : 'optional')
return map
}
}
}
}

entrypoints {
entrypoint 'main', [
'dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric.ExcavatedVariantsFabric',
Expand Down
5 changes: 0 additions & 5 deletions fabriquilt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ dependencies {
include libs.defaultresources.fabriquilt

compileOnly libs.quilt.loader

modImplementation libs.mixinextras.fabric
include libs.mixinextras.fabric
annotationProcessor libs.mixinextras.fabric
}

loom {
mixin {
useLegacyMixinAp = true
defaultRefmapName.set("${mod_id}.refmap.json")
}
runs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
/*
* Copyright (C) 2023 Luke Bemish and contributors
* Copyright (C) 2023-2024 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.S2CConfigAgreementPacket;
import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking;
import net.minecraft.network.FriendlyByteBuf;

import java.util.concurrent.CompletableFuture;
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.ClientboundDisconnectPacket;

public class ExcavatedVariantsClientFabriQuilt implements ClientModInitializer {
@Override
public void onInitializeClient() {
ClientLoginNetworking.registerGlobalReceiver(ExcavatedVariantsFabriQuilt.S2C_CONFIG_AGREEMENT_PACKET, ((client, handler, buf, listenerAdder) -> {
S2CConfigAgreementPacket msg = S2CConfigAgreementPacket.decoder(buf);
msg.consumeMessage(string -> handler.handleDisconnect(new S2CConfigAgreementPacket.ExcavatedVariantsDisconnectPacket(string)));
CompletableFuture<FriendlyByteBuf> future = new CompletableFuture<>();
future.complete(null);
return future;
ClientConfigurationNetworking.registerGlobalReceiver(SyncOresPayload.ID, ((client, handler, buf, listenerAdder) -> {
SyncOresPayload msg = SyncOresPayload.decode(buf);
msg.consumeMessage(string -> handler.handleDisconnect(new ClientboundDisconnectPacket(Component.literal(string))));
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* Copyright (C) 2023 Luke Bemish and contributors
* Copyright (C) 2023-2024 Luke Bemish and contributors
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.*;
import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload;
import dev.lukebemish.excavatedvariants.impl.worldgen.OreFinderUtil;
import dev.lukebemish.excavatedvariants.impl.worldgen.OreReplacer;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
import net.fabricmc.fabric.api.networking.v1.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.GenerationStep;
Expand All @@ -27,8 +27,6 @@
import java.util.stream.Collectors;

public class ExcavatedVariantsFabriQuilt {
public static final ResourceLocation S2C_CONFIG_AGREEMENT_PACKET = new ResourceLocation(ExcavatedVariants.MOD_ID, "config_agreement");

public static void onInitialize() {
ExcavatedVariants.init();
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Expand All @@ -51,17 +49,11 @@ public static void onInitialize() {
HyleCompat.init();
}*/

ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
var packet = new S2CConfigAgreementPacket(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet()));
var buf = PacketByteBufs.create();
packet.encoder(buf);
sender.sendPacket(sender.createPacket(S2C_CONFIG_AGREEMENT_PACKET, buf));
ServerConfigurationConnectionEvents.CONFIGURE.register((handler, server) -> {
var packet = new SyncOresPayload(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet()));
ServerConfigurationNetworking.send(handler, new SyncFabricPacket(packet));
});

ServerLoginNetworking.registerGlobalReceiver(S2C_CONFIG_AGREEMENT_PACKET, ((server, handler, understood, buf, synchronizer, responseSender) -> {
//Do I need to do anything here?
}));

Registry.register(BuiltInRegistries.FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), new OreReplacer());
}

Expand All @@ -70,4 +62,18 @@ public static void cleanup() {
RegistriesImpl.registerRegistries();
ExcavatedVariants.initPostRegister();
}

public record SyncFabricPacket(SyncOresPayload payload) implements FabricPacket {
public static PacketType<?> TYPE = PacketType.create(SyncOresPayload.ID, buf -> new SyncFabricPacket(SyncOresPayload.decode(buf)));

@Override
public void write(FriendlyByteBuf buf) {
payload.encode(buf);
}

@Override
public PacketType<?> getType() {
return TYPE;
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ artifact_id=excavatedvariants
# Gradle
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.caching=true

release_type=release
Loading

0 comments on commit da129a8

Please sign in to comment.