Skip to content

Commit

Permalink
Fix compile errors + startup crashes
Browse files Browse the repository at this point in the history
I've won, but at what cost?
  • Loading branch information
BrokenK3yboard committed Dec 10, 2024
1 parent 8698af9 commit c6e00d9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ private void mutabilize() {
public void commit() {
advancement.criteria().clear();
advancement.criteria().putAll(ImmutableMap.copyOf(criteria));

List<String[]> requirementArrays = new ArrayList<>();
for(List<String> list : requirements) {
String[] arr = list.toArray(new String[list.size()]);
requirementArrays.add(arr);
}

// Can't replace this yet
String[][] arr = requirementArrays.toArray(new String[0][requirementArrays.size()]);
advancement.requirements = arr;
advancement.requirements().requirements().addAll(requirements);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
//Mash of arl's RegistryHelper and its ModData innerclass.
//You're expected to create one of these per modid instead, avoiding a dependency on Forge's "current mod id" notion.
public abstract class ZetaRegistry {
protected final Zeta z;
public final Zeta z;

// the keys of this are things like "minecraft:block", "minecraft:item" and so on
private final Multimap<ResourceLocation, Supplier<Object>> defers = ArrayListMultimap.create();

// to support calling getRegistryName before the object actually gets registered for real
protected final Map<Object, ResourceLocation> internalNames = new IdentityHashMap<>();
public final Map<Object, ResourceLocation> internalNames = new IdentityHashMap<>();

// "named color provider" system allows blocks and items to choose their own color providers in a side-safe way
// TODO: should this go somewhere else and not be so tightly-integrated? (yes - i think a Registrate-like system would be a great spot for this)
Expand Down
87 changes: 45 additions & 42 deletions src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.violetmoon.zetaimplforge;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -72,6 +75,9 @@
import org.violetmoon.zetaimplforge.registry.ForgeZetaRegistry;
import org.violetmoon.zetaimplforge.util.ForgeRaytracingUtil;

import java.util.Collection;
import java.util.function.Supplier;

/**
* ideally do not touch quark from this package, it will later be split off
*/
Expand Down Expand Up @@ -109,7 +115,7 @@ public IZetaConfigInternals makeConfigInternals(SectionDefinition rootSection) {

@Override
public ZetaRegistry createRegistry() {
return new ForgeZetaRegistry(this, bus);
return new ForgeZetaRegistry(this);
}

@Override
Expand Down Expand Up @@ -165,6 +171,7 @@ public void start(IEventBus modbus) {
modbus.addListener(this::commonSetup);
modbus.addListener(this::loadComplete);
modbus.addListener(this::entityAttributeCreation);
modbus.addListener(this::onRegisterEvent);
NeoForge.EVENT_BUS.addListener(this::addReloadListener);
NeoForge.EVENT_BUS.addListener(this::tagsUpdated);

Expand All @@ -181,7 +188,6 @@ public void start(IEventBus modbus) {
//NeoForge.EVENT_BUS.addListener(this::livingTick);
NeoForge.EVENT_BUS.addListener(this::playNoteBlock);
NeoForge.EVENT_BUS.addListener(this::lootTableLoad);
NeoForge.EVENT_BUS.addListener(this::livingConversion);
NeoForge.EVENT_BUS.addListener(this::livingConversionPre);
NeoForge.EVENT_BUS.addListener(this::livingConversionPost);
NeoForge.EVENT_BUS.addListener(this::anvilUpdate);
Expand All @@ -206,25 +212,22 @@ public void start(IEventBus modbus) {
NeoForge.EVENT_BUS.addListener(this::serverTickEnd);
NeoForge.EVENT_BUS.addListener(this::levelTickStart);
NeoForge.EVENT_BUS.addListener(this::levelTickEnd);
NeoForge.EVENT_BUS.addListener(this::playerInteract);
NeoForge.EVENT_BUS.addListener(this::playerInteractEntityInteractSpecific);
NeoForge.EVENT_BUS.addListener(this::playerInteractEntityInteract);
NeoForge.EVENT_BUS.addListener(this::playerInteractRightClickBlock);
NeoForge.EVENT_BUS.addListener(this::playerInteractRightClickItem);
NeoForge.EVENT_BUS.addListener(this::playerDestroyItem);
NeoForge.EVENT_BUS.addListener(this::mobSpawn);
//NeoForge.EVENT_BUS.addListener(this::mobSpawnFinalizeSpawn);
//NeoForge.EVENT_BUS.addListener(this::mobSpawnFinalizeSpawnLowest);
NeoForge.EVENT_BUS.addListener(this::livingChangeTarget);
//NeoForge.EVENT_BUS.addListener(this::sleepingLocationCheck);
NeoForge.EVENT_BUS.addListener(this::villagerTrades);
NeoForge.EVENT_BUS.addListener(this::anvilRepair);
NeoForge.EVENT_BUS.addListener(this::player);
NeoForge.EVENT_BUS.addListener(this::playerBreakSpeed);
NeoForge.EVENT_BUS.addListener(this::playerClone);
NeoForge.EVENT_BUS.addListener(this::playerLoggedIn);
NeoForge.EVENT_BUS.addListener(this::playerLoggedOut);
NeoForge.EVENT_BUS.addListener(this::entityItemPickup);
// NeoForge.EVENT_BUS.addListener(this::entityItemPickup); TODO: USE ItemEntityPickupEvent.PRE OR ItemEntityPickupEvent.POST INSTEAD
NeoForge.EVENT_BUS.addListener(this::blockBreak);
NeoForge.EVENT_BUS.addListener(this::blockEntityPlace);
//NeoForge.EVENT_BUS.addListener(this::blockToolModification);
Expand Down Expand Up @@ -261,6 +264,24 @@ public void entityAttributeCreation(EntityAttributeCreationEvent e) {
loadBus.fire(new ForgeZEntityAttributeCreation(e), ZEntityAttributeCreation.class);
}

// TODO: Put this back inside ZetaForgeMod, or get rid of it
public void onRegisterEvent(RegisterEvent event) {
var key = event.getRegistryKey();
ResourceLocation registryRes = key.location();
ResourceKey<Registry<Object>> keyGeneric = ResourceKey.createRegistryKey(registryRes);
Collection<Supplier<Object>> ourEntries = registry.getDefers(registryRes);

if(ourEntries != null && !ourEntries.isEmpty()) {
for(Supplier<Object> supplier : ourEntries) {
Object entry = supplier.get();
ResourceLocation name = registry.internalNames.get(entry);
registry.z.log.debug("Registering to " + registryRes + " - " + name);
event.register(keyGeneric, e-> e.register(name, entry));
}
registry.clearDeferCache(registryRes);
}
}

public void addReloadListener(AddReloadListenerEvent e) {
loadBus.fire(new ForgeZAddReloadListener(e), ZAddReloadListener.class);
}
Expand Down Expand Up @@ -301,10 +322,6 @@ public void lootTableLoad(LootTableLoadEvent e) {
playBus.fire(new ForgeZLootTableLoad(e), ZLootTableLoad.class);
}

public void livingConversion(LivingConversionEvent e) {
playBus.fire(new ForgeZLivingConversion(e), ZLivingConversion.class);
}

public void livingConversionPre(LivingConversionEvent.Pre e) {
playBus.fire(new ForgeZLivingConversion.Pre(e), ZLivingConversion.Pre.class);
}
Expand Down Expand Up @@ -345,14 +362,12 @@ public void livingDropsLowest(LivingDropsEvent e) {
playBus.fire(new ForgeZLivingDrops.Lowest(e), ZLivingDrops.Lowest.class);
}

public void playerTickStart(PlayerTickEvent e) {
if (e instanceof PlayerTickEvent.Pre)
playBus.fire(new ForgeZPlayerTick.Pre(e), ZPlayerTick.Start.class);
public void playerTickStart(PlayerTickEvent.Pre e) {
playBus.fire(new ForgeZPlayerTick.Pre(e), ZPlayerTick.Start.class);
}

public void playerTickEnd(PlayerTickEvent e) {
if (e instanceof PlayerTickEvent.Post)
playBus.fire(new ForgeZPlayerTick.Post(e), ZPlayerTick.End.class);
public void playerTickEnd(PlayerTickEvent.Post e) {
playBus.fire(new ForgeZPlayerTick.Post(e), ZPlayerTick.End.class);
}

public void babyEntitySpawn(BabyEntitySpawnEvent e) {
Expand All @@ -379,28 +394,20 @@ public void levelCaps(AttachCapabilitiesEvent<Level> e) {
playBus.fire(new ForgeZAttachCapabilities.LevelCaps(capabilityManager, e), ZAttachCapabilities.LevelCaps.class);
}*/

public void serverTickStart(ServerTickEvent e) {
if (e instanceof ServerTickEvent.Pre)
playBus.fire(new ForgeZServerTick.Pre(e), ZServerTick.Start.class);
}

public void serverTickEnd(ServerTickEvent e) {
if (e instanceof ServerTickEvent.Post)
playBus.fire(new ForgeZServerTick.Post(e), ZServerTick.End.class);
public void serverTickStart(ServerTickEvent.Pre e) {
playBus.fire(new ForgeZServerTick.Pre(e), ZServerTick.Start.class);
}

public void levelTickStart(LevelTickEvent e) {
if (e instanceof LevelTickEvent.Pre)
playBus.fire(new ForgeZLevelTick.Start(e), ZLevelTick.Start.class);
public void serverTickEnd(ServerTickEvent.Post e) {
playBus.fire(new ForgeZServerTick.Post(e), ZServerTick.End.class);
}

public void levelTickEnd(LevelTickEvent e) {
if (e instanceof LevelTickEvent.Post)
playBus.fire(new ForgeZLevelTick.End(e), ZLevelTick.End.class);
public void levelTickStart(LevelTickEvent.Pre e) {
playBus.fire(new ForgeZLevelTick.Start(e), ZLevelTick.Start.class);
}

public void playerInteract(PlayerInteractEvent e) {
playBus.fire(new ForgeZPlayerInteract(e), ZPlayerInteract.class);
public void levelTickEnd(LevelTickEvent.Post e) {
playBus.fire(new ForgeZLevelTick.End(e), ZLevelTick.End.class);
}

public void playerInteractEntityInteractSpecific(PlayerInteractEvent.EntityInteractSpecific e) {
Expand All @@ -423,17 +430,15 @@ public void playerDestroyItem(PlayerDestroyItemEvent e) {
playBus.fire(new ForgeZPlayerDestroyItem(e), ZPlayerDestroyItem.class);
}

public void mobSpawn(MobSpawnEvent e) {
playBus.fire(new ForgeZMobSpawnEvent(e), ZMobSpawnEvent.class);
}

/*public void mobSpawnFinalizeSpawn(MobSpawnEvent.FinalizeSpawn e) {
/*
public void mobSpawnFinalizeSpawn(MobSpawnEvent.FinalizeSpawn e) {
playBus.fire(new ForgeZMobSpawnEvent.FinalizeSpawn(e), ZMobSpawnEvent.CheckSpawn.class);
}
public void mobSpawnFinalizeSpawnLowest(MobSpawnEvent.FinalizeSpawn e) {
playBus.fire(new ForgeZMobSpawnEvent.FinalizeSpawn.Lowest(e), ZMobSpawnEvent.CheckSpawn.Lowest.class);
}*/
}
*/

public void livingChangeTarget(LivingChangeTargetEvent e) {
playBus.fire(new ForgeZLivingChangeTarget(e), ZLivingChangeTarget.class);
Expand All @@ -443,9 +448,11 @@ public void livingChangeTarget(LivingChangeTargetEvent e) {
playBus.fire(new ForgeZSleepingLocationCheck(e), ZSleepingLocationCheck.class);
}*/

/*
public void entityItemPickup(ItemEntityPickupEvent e) {
playBus.fire(new ForgeZEntityItemPickup(e), ZItemEntityPickup.class);
}
*/

public void blockBreak(BlockEvent.BreakEvent e) {
playBus.fire(new ForgeZBlock.Break(e), ZBlock.Break.class);
Expand All @@ -471,10 +478,6 @@ public void anvilRepair(AnvilRepairEvent e) {
playBus.fire(new ForgeZAnvilRepair(e), ZAnvilRepair.class);
}

public void player(PlayerEvent e) {
playBus.fire(new ForgeZPlayer(e), ZPlayer.class);
}

public void playerBreakSpeed(PlayerEvent.BreakSpeed e) {
playBus.fire(new ForgeZPlayer.BreakSpeed(e), ZPlayer.BreakSpeed.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
package org.violetmoon.zetaimplforge.config;

import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.config.ConfigTracker;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.common.ModConfigSpec;
import org.violetmoon.zetaimplforge.mixin.mixins.AccessorConfigTracker;

import java.io.Serial;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.concurrent.locks.ReentrantLock;

import static org.violetmoon.zetaimplforge.mixin.mixins.AccessorModConfig.zeta$initModConfig;

public class TerribleForgeConfigHackery {
private static final Method SET_CONFIG_DATA = ObfuscationReflectionHelper.findMethod(ModConfig.class, "setConfigData", CommentedConfig.class);

// private static final Method SET_CONFIG_DATA = ObfuscationReflectionHelper.findMethod(ModConfig.class, "setConfig", LoadedConfig.class, FunctionalInterface.class);
private static final Method SETUP_CONFIG_FILE = ObfuscationReflectionHelper.findMethod(ConfigTracker.class, "setupConfigFile", ModConfig.class, Path.class);

// TODO: Replace the name string + not 100% sure about this
public static void registerAndLoadConfigEarlierThanUsual(ModConfigSpec spec) {
ModContainer container = ModLoadingContext.get().getActiveContainer();
var lock = ((AccessorConfigTracker)ConfigTracker.INSTANCE).zeta$getLocksByMod().computeIfAbsent(container.getModId(), m -> new ReentrantLock());
ModConfig modConfig = zeta$initModConfig(ModConfig.Type.COMMON, spec, container, "zetaConfig", lock);
container.registerConfig(ModConfig.Type.COMMON, spec);
ModConfig modConfig = ConfigTracker.INSTANCE.registerConfig(ModConfig.Type.COMMON, spec, container, "zeta-common.toml");

ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.COMMON, Path.of(modConfig.getFileName()));

//same stuff that forge config tracker does
ConfigTracker handler = modConfig.getHandler();
//read config without setting file watcher which could cause resets. forge will load it later
CommentedFileConfig configData = readConfig(handler, FMLPaths.CONFIGDIR.get(), modConfig);
//CommentedFileConfig configData = readConfig(ConfigTracker.INSTANCE, FMLPaths.CONFIGDIR.get(), modConfig);
//CommentedFileConfig configData = handler.reader(FMLPaths.CONFIGDIR.get()).apply( modConfig);

/*
SET_CONFIG_DATA.setAccessible(true);
try {
SET_CONFIG_DATA.invoke(modConfig, configData);
SET_CONFIG_DATA.invoke(modConfig, new LoadedConfig(configData, modConfig.getFullPath(), modConfig), ModConfigEvent.Loading::new);
} catch (Exception ignored) {}
//container.dispatchConfigEvent(IConfigEvent.loading(this.config));
modConfig.save();
configData.save();
*/
}

//we need this so we dont add a second file watcher. Same as handler::reader
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import org.apache.logging.log4j.LogManager;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.mod.ZetaClientProxy;
import org.violetmoon.zeta.mod.ZetaMod;
import org.violetmoon.zeta.mod.ZetaModProxy;
import org.violetmoon.zeta.multiloader.Env;
import org.violetmoon.zeta.util.handler.ToolInteractionHandler;
import org.violetmoon.zetaimplforge.ForgeZeta;
import org.violetmoon.zetaimplforge.client.ForgeZetaClient;
import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher;
Expand All @@ -28,7 +26,7 @@ public ZetaForgeMod(IEventBus bus) {
ZetaMod.start(zeta, proxy, bus);
ZetaMod.proxy.setClientZeta(zetaClient);

NeoForge.EVENT_BUS.register(ToolInteractionHandler.class);
// NeoForge.EVENT_BUS.register(ToolInteractionHandler.class); TODO: Reimplement this
ZetaBiomeModifier.registerBiomeModifier(bus);

bus.addListener(this::setup);
Expand Down
Loading

0 comments on commit c6e00d9

Please sign in to comment.