Skip to content

Commit

Permalink
Backport to 1.20.1 Fabric & Forge (#10)
Browse files Browse the repository at this point in the history
* kill neoforge

* update, fix gradle & dependencies

* 1.20.1 backport first attempt

* delete phases

* add setflammable to forge accesstransformer.cfg

* temporarily upload to jitpack

* remove from jitpack

* optimize imports

* add ConfigSync (on fabric)

* improve ConfigSync

* Revert "remove from jitpack" temporary

This reverts commit c290aca.

* do not remap configsync

* delete comments

* add javadoc

* some more fixes for config sync

* Reapply  temporary

This reverts commit 109ca7e.
  • Loading branch information
marlester-dev authored Sep 30, 2024
1 parent 580e0d9 commit 5609ec2
Show file tree
Hide file tree
Showing 65 changed files with 238 additions and 1,384 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ subprojects {
var expandProps = [
minecraft_version : minecraft_version,
forge_version : forge_version, forge_version_range: forge_version_range, forge_loader_version_range: forge_loader_version_range,
neoforge_version : neoforge_version, neoforge_version_range: neoforge_version_range, neoforge_loader_version_range: neoforge_loader_version_range,
mod_id : mod_id, mod_name: mod_name, mod_display_name: mod_display_name, mod_version: mod_version,
mod_authors : mod_authors, mod_description: mod_description,
mod_issues_url : mod_issues_url, mod_page_url: mod_page_url, mod_git_url: mod_git_url,
Expand Down
8 changes: 5 additions & 3 deletions common/src/main/java/glitchcore/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
******************************************************************************/
package glitchcore.config;

import com.electronwill.nightconfig.core.*;
import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.ConfigFormat;
import com.electronwill.nightconfig.core.UnmodifiableCommentedConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import com.electronwill.nightconfig.toml.TomlFormat;
import com.google.common.base.Predicates;
import glitchcore.core.GlitchCore;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -88,7 +90,7 @@ public Path getPath()
return this.path;
}

private static String readToml(Path path)
public static String readToml(Path path)
{
// Create parent directories as needed
path.getParent().toFile().mkdirs();
Expand Down
66 changes: 29 additions & 37 deletions common/src/main/java/glitchcore/config/ConfigSync.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package glitchcore.config;

import glitchcore.network.SyncConfigPacket;
import glitchcore.core.GlitchCore;
import glitchcore.util.Environment;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

public class ConfigSync
{
private static Map<String, Config> configs = new HashMap<>();

public static void register(Config config)
{
String relative = Environment.getConfigPath().relativize(config.getPath()).toString();
configs.put(relative, config);
}

public static Stream<SyncConfigPacket> createPackets()
{
return configs.entrySet().stream().map(e -> {
var config = e.getValue();

// Reload the config from the filesystem, but do not save it
config.read();
config.load();

return new SyncConfigPacket(e.getKey(), e.getValue().encode().getBytes(StandardCharsets.UTF_8));
});
}

public static void reload(String path, String toml)
{
var config = configs.get(path);
config.parse(toml);
config.load();
import net.minecraft.resources.ResourceLocation;

public class ConfigSync {
private static final ResourceLocation CONFIG_SYNC_CHANNEL = new ResourceLocation("glitchcorefabric", "config_sync");
private static final Map<String, Config> CONFIGS_BY_PATH = new HashMap<>();
private static boolean inited = false;
/**
* Enables sync between server and client for your config.
* NOTE: This function works only on fabric, you need to implement it yourself
* if you want to use it on forge
*
* @param config your config.
*/
public static void register(Config config) {
if (!inited) {
initSyncs();
inited = true;
}
String relative = Environment.getConfigPath().relativize(config.getPath()).toString();
CONFIGS_BY_PATH.put(relative, config);
}
private static void initSyncs() {
throw new UnsupportedOperationException();
}
private static void reload(String path, String toml) {
var config = CONFIGS_BY_PATH.get(path);
config.parse(toml);
config.load();
}
}
19 changes: 2 additions & 17 deletions common/src/main/java/glitchcore/core/GlitchCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
******************************************************************************/
package glitchcore.core;

import glitchcore.config.Config;
import glitchcore.config.ConfigSync;
import glitchcore.network.PacketHandler;
import glitchcore.network.SyncConfigPacket;
import glitchcore.util.Environment;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -18,16 +12,7 @@ public class GlitchCore
public static final String MOD_ID = "glitchcore";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

private static final ResourceLocation CHANNEL = new ResourceLocation(MOD_ID, "main");
public static final PacketHandler PACKET_HANDLER = new PacketHandler(CHANNEL);

public static void init()
{
registerPackets();
}

private static void registerPackets()
{
PACKET_HANDLER.register(new ResourceLocation(MOD_ID, "sync_config"), new SyncConfigPacket());
@Deprecated
public static void init() {
}
}
8 changes: 5 additions & 3 deletions common/src/main/java/glitchcore/event/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
package glitchcore.event;

import com.google.common.collect.ImmutableSet;
import net.jodah.typetools.TypeResolver;

import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import net.jodah.typetools.TypeResolver;

public class EventManager
{
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/glitchcore/event/RegistryEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package glitchcore.event;

import java.util.function.BiConsumer;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

import java.util.function.BiConsumer;

public final class RegistryEvent extends Event
{
@NotNull
Expand Down
2 changes: 0 additions & 2 deletions common/src/main/java/glitchcore/event/TickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
******************************************************************************/
package glitchcore.event;

import net.minecraft.world.level.Level;

public abstract class TickEvent extends Event
{
private final Phase phase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package glitchcore.event.client;

import glitchcore.event.Event;
import java.util.List;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;

import java.util.List;

public class ItemTooltipEvent extends Event
{
private final ItemStack stack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
package glitchcore.event.client;

import glitchcore.event.Event;
import java.util.function.BiConsumer;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;

import java.util.Arrays;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;

public abstract class RegisterColorsEvent<ObjColor, Obj> extends Event
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package glitchcore.event.client;

import glitchcore.event.Event;
import java.util.function.BiConsumer;
import net.minecraft.client.particle.ParticleEngine;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;

import java.util.function.BiConsumer;

public class RegisterParticleSpritesEvent extends Event
{
private final BiConsumer<ParticleType<?>, ParticleEngine.SpriteParticleRegistration<?>> registerSpriteSetFunc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
package glitchcore.event.client;

import glitchcore.event.Event;
import java.util.List;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
import net.minecraft.world.item.ItemStack;

import java.util.List;

public class RenderTooltipEvent extends Event
{
private final ItemStack stack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
package glitchcore.event.village;

import glitchcore.event.Event;
import java.util.List;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerTrades;

import java.util.List;
import java.util.function.Function;

public class VillagerTradesEvent extends Event
{
private final VillagerProfession profession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import com.google.common.collect.ImmutableList;
import glitchcore.event.Event;
import net.minecraft.world.entity.npc.VillagerTrades;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.entity.npc.VillagerTrades;

public class WandererTradesEvent extends Event
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package glitchcore.mixin.client;

import glitchcore.event.EventManager;
import glitchcore.event.player.PlayerInteractEvent;
import glitchcore.event.TickEvent;
import glitchcore.event.player.PlayerInteractEvent;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.InteractionHand;
Expand All @@ -21,8 +22,6 @@
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import javax.annotation.Nullable;

@Mixin(Minecraft.class)
public class MixinMinecraft
{
Expand Down
14 changes: 1 addition & 13 deletions common/src/main/java/glitchcore/network/CustomPacket.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package glitchcore.network;

import java.util.Optional;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;

import java.util.Optional;

public interface CustomPacket<T extends CustomPacket<T>>
{
void encode(FriendlyByteBuf buf);
Expand All @@ -13,11 +12,6 @@ public interface CustomPacket<T extends CustomPacket<T>>

void handle(T data, Context context);

default Phase getPhase()
{
return Phase.PLAY;
}

interface Context
{
boolean isClientSide();
Expand All @@ -27,10 +21,4 @@ default boolean isServerSide()
}
Optional<Player> getPlayer();
}

enum Phase
{
PLAY,
CONFIGURATION
}
}
5 changes: 0 additions & 5 deletions common/src/main/java/glitchcore/network/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
******************************************************************************/
package glitchcore.network;

import net.minecraft.network.Connection;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
import net.minecraft.server.network.ServerGamePacketListenerImpl;

public final class PacketHandler
{
Expand All @@ -27,8 +24,6 @@ public PacketHandler(ResourceLocation channelName)

public <T extends CustomPacket<T>> void sendToAll(T data, MinecraftServer server) { throw new UnsupportedOperationException(); }

public <T extends CustomPacket<T>> void sendToHandler(T data, ServerConfigurationPacketListenerImpl handler) { throw new UnsupportedOperationException(); }

public <T extends CustomPacket<T>> void sendToServer(T data) { throw new UnsupportedOperationException(); }

private void init() {}
Expand Down
Loading

0 comments on commit 5609ec2

Please sign in to comment.