Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fabric/1.21' into fabric/1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Oganesson897 committed Aug 12, 2024
2 parents d839c35 + c6e7f3c commit a4f7b9c
Show file tree
Hide file tree
Showing 22 changed files with 333 additions and 243 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ dependencies {
exclude group: "net.fabricmc.fabric-api"
}

modImplementation("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${project.config_version}") {
exclude group: "net.fabricmc"
exclude group: "net.fabricmc.fabric-api"
}

// unit test dependencies
testImplementation(platform("org.junit:junit-bom:${project.junit_version}"))
testImplementation(platform("org.assertj:assertj-bom:${project.assertj_version}"))
Expand Down Expand Up @@ -235,6 +240,13 @@ allprojects {
includeGroup "mezz.jei"
}
}
maven {
name = "Fuzs Mod Resources"
url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/"
content {
includeGroup "fuzs.forgeconfigapiport"
}
}
mavenCentral()
}
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jade_version=15.1.5+fabric
trinkets_version=3.10.0
fabric_version=0.102.0+1.21
energy_version=3.0.0
config_version=21.0.8

# Pick which item list mod gets picked at runtime in dev
# Available options: emi, rei, none
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import java.util.Map;
import java.util.function.DoubleSupplier;

import net.neoforged.fml.ModContainer;
import fuzs.forgeconfigapiport.fabric.api.neoforge.v4.NeoForgeConfigRegistry;
import fuzs.forgeconfigapiport.fabric.api.neoforge.v4.NeoForgeModConfigEvents;

import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.neoforge.common.ModConfigSpec;
import net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
import net.neoforged.neoforge.common.ModConfigSpec.DoubleValue;
Expand All @@ -51,26 +52,23 @@ public final class AEConfig {

private static AEConfig instance;

private AEConfig(ModContainer container) {
container.registerConfig(ModConfig.Type.CLIENT, client.spec);
container.registerConfig(ModConfig.Type.COMMON, common.spec);
container.getEventBus().addListener((ModConfigEvent.Loading evt) -> {
if (evt.getConfig().getSpec() == common.spec) {
private AEConfig(String modId) {
NeoForgeConfigRegistry.INSTANCE.register(modId, ModConfig.Type.CLIENT, client.spec);
NeoForgeConfigRegistry.INSTANCE.register(modId, ModConfig.Type.COMMON, common.spec);
NeoForgeModConfigEvents.loading(modId).register(config -> {
if (config.getSpec() == common.spec) {
common.sync();
}
});
container.getEventBus().addListener((ModConfigEvent.Reloading evt) -> {
if (evt.getConfig().getSpec() == common.spec) {
NeoForgeModConfigEvents.reloading(modId).register(config -> {
if (config.getSpec() == common.spec) {
common.sync();
}
});
}

public static void register(ModContainer container) {
if (!container.getModId().equals(AppEng.MOD_ID)) {
throw new IllegalArgumentException();
}
instance = new AEConfig(container);
public static void register(String modId) {
instance = new AEConfig(modId);
}

// Tunnels
Expand Down
205 changes: 103 additions & 102 deletions src/main/java/appeng/core/AppEngBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@
import java.util.Collection;
import java.util.Collections;

import appeng.core.network.CustomAppEngPayload;
import appeng.hooks.ToolItemHook;
import appeng.util.NetworkUtil;
import com.mojang.brigadier.CommandDispatcher;

import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.gametest.framework.GameTestRegistry;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

import net.minecraft.commands.CommandSourceStack;
Expand All @@ -37,21 +47,6 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterGameTestsEvent;
import net.neoforged.neoforge.event.server.ServerAboutToStartEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.neoforged.neoforge.registries.NewRegistryEvent;
import net.neoforged.neoforge.registries.RegisterEvent;
import net.neoforged.neoforge.registries.RegistryBuilder;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

import appeng.api.ids.AEComponents;
import appeng.api.parts.CableRenderMode;
Expand Down Expand Up @@ -112,90 +107,95 @@ public abstract class AppEngBase implements AppEng {

static AppEngBase INSTANCE;

public AppEngBase(IEventBus modEventBus, ModContainer container) {
private MinecraftServer currentServer;

public AppEngBase() {
if (INSTANCE != null) {
throw new IllegalStateException();
}
INSTANCE = this;

AEConfig.register(container);
AEConfig.register("ae2");

InitGridServices.init();
InitBlockEntityMoveStrategies.init();

AEParts.init();
AEBlocks.DR.register(modEventBus);
AEItems.DR.register(modEventBus);
AEBlockEntities.DR.register(modEventBus);
AEComponents.DR.register(modEventBus);
AEEntities.DR.register(modEventBus);
InitStructures.register(modEventBus);

modEventBus.addListener(this::registerRegistries);
modEventBus.addListener(MainCreativeTab::initExternal);
modEventBus.addListener(InitNetwork::init);
modEventBus.addListener(ChunkLoadingService.getInstance()::register);
modEventBus.addListener(InitCapabilityProviders::register);
modEventBus.addListener(EventPriority.LOWEST, InitCapabilityProviders::registerGenericAdapters);
modEventBus.addListener((RegisterEvent event) -> {
if (event.getRegistryKey() == Registries.SOUND_EVENT) {
registerSounds(BuiltInRegistries.SOUND_EVENT);
} else if (event.getRegistryKey() == Registries.CREATIVE_MODE_TAB) {
registerCreativeTabs(BuiltInRegistries.CREATIVE_MODE_TAB);
} else if (event.getRegistryKey() == Registries.CUSTOM_STAT) {
InitStats.init(event.getRegistry(Registries.CUSTOM_STAT));
} else if (event.getRegistryKey() == Registries.TRIGGER_TYPE) {
InitAdvancementTriggers.init(event.getRegistry(Registries.TRIGGER_TYPE));
} else if (event.getRegistryKey() == Registries.PARTICLE_TYPE) {
InitParticleTypes.init(event.getRegistry(Registries.PARTICLE_TYPE));
} else if (event.getRegistryKey() == Registries.MENU) {
InitMenuTypes.init(event.getRegistry(Registries.MENU));
} else if (event.getRegistryKey() == Registries.RECIPE_TYPE) {
InitRecipeTypes.init(event.getRegistry(Registries.RECIPE_TYPE));
} else if (event.getRegistryKey() == Registries.RECIPE_SERIALIZER) {
InitRecipeSerializers.init(event.getRegistry(Registries.RECIPE_SERIALIZER));
} else if (event.getRegistryKey() == Registries.RECIPE_SERIALIZER) {
InitRecipeSerializers.init(event.getRegistry(Registries.RECIPE_SERIALIZER));
} else if (event.getRegistryKey() == Registries.CHUNK_GENERATOR) {
Registry.register(BuiltInRegistries.CHUNK_GENERATOR, SpatialStorageDimensionIds.CHUNK_GENERATOR_ID,
SpatialStorageChunkGenerator.CODEC);
} else if (event.getRegistryKey() == Registries.VILLAGER_PROFESSION) {
InitVillager.initProfession(event.getRegistry(Registries.VILLAGER_PROFESSION));
} else if (event.getRegistryKey() == Registries.POINT_OF_INTEREST_TYPE) {
InitVillager.initPointOfInterestType(event.getRegistry(Registries.POINT_OF_INTEREST_TYPE));
} else if (event.getRegistryKey() == AEKeyType.REGISTRY_KEY) {
registerKeyTypes(event.getRegistry(AEKeyType.REGISTRY_KEY));
}
});

NeoForge.EVENT_BUS.addListener(InitVillager::initTrades);

modEventBus.addListener(Integrations::enqueueIMC);
modEventBus.addListener(this::commonSetup);

modEventBus.addListener(this::registerTests);
// AEBlocks.DR.register(modEventBus);
// AEItems.DR.register(modEventBus);
// AEBlockEntities.DR.register(modEventBus);
// AEComponents.DR.register(modEventBus);
// AEEntities.DR.register(modEventBus);
// InitStructures.register(modEventBus);

// modEventBus.addListener(this::registerRegistries);
// modEventBus.addListener(MainCreativeTab::initExternal);
// modEventBus.addListener(InitNetwork::init);
// modEventBus.addListener(ChunkLoadingService.getInstance()::register);
// modEventBus.addListener(InitCapabilityProviders::register);
// modEventBus.addListener(EventPriority.LOWEST, InitCapabilityProviders::registerGenericAdapters);
// modEventBus.addListener((RegisterEvent event) -> {
// if (event.getRegistryKey() == Registries.SOUND_EVENT) {
// registerSounds(BuiltInRegistries.SOUND_EVENT);
// } else if (event.getRegistryKey() == Registries.CREATIVE_MODE_TAB) {
// registerCreativeTabs(BuiltInRegistries.CREATIVE_MODE_TAB);
// } else if (event.getRegistryKey() == Registries.CUSTOM_STAT) {
// InitStats.init(event.getRegistry(Registries.CUSTOM_STAT));
// } else if (event.getRegistryKey() == Registries.TRIGGER_TYPE) {
// InitAdvancementTriggers.init(event.getRegistry(Registries.TRIGGER_TYPE));
// } else if (event.getRegistryKey() == Registries.PARTICLE_TYPE) {
// InitParticleTypes.init(event.getRegistry(Registries.PARTICLE_TYPE));
// } else if (event.getRegistryKey() == Registries.MENU) {
// InitMenuTypes.init(event.getRegistry(Registries.MENU));
// } else if (event.getRegistryKey() == Registries.RECIPE_TYPE) {
// InitRecipeTypes.init(event.getRegistry(Registries.RECIPE_TYPE));
// } else if (event.getRegistryKey() == Registries.RECIPE_SERIALIZER) {
// InitRecipeSerializers.init(event.getRegistry(Registries.RECIPE_SERIALIZER));
// } else if (event.getRegistryKey() == Registries.RECIPE_SERIALIZER) {
// InitRecipeSerializers.init(event.getRegistry(Registries.RECIPE_SERIALIZER));
// } else if (event.getRegistryKey() == Registries.CHUNK_GENERATOR) {
// Registry.register(BuiltInRegistries.CHUNK_GENERATOR, SpatialStorageDimensionIds.CHUNK_GENERATOR_ID,
// SpatialStorageChunkGenerator.CODEC);
// } else if (event.getRegistryKey() == Registries.VILLAGER_PROFESSION) {
// InitVillager.initProfession(event.getRegistry(Registries.VILLAGER_PROFESSION));
// } else if (event.getRegistryKey() == Registries.POINT_OF_INTEREST_TYPE) {
// InitVillager.initPointOfInterestType(event.getRegistry(Registries.POINT_OF_INTEREST_TYPE));
// } else if (event.getRegistryKey() == AEKeyType.REGISTRY_KEY) {
// registerKeyTypes(event.getRegistry(AEKeyType.REGISTRY_KEY));
// }
// });

InitNetwork.init();

registerCreativeTabs(BuiltInRegistries.CREATIVE_MODE_TAB);
// registerDimension();
// registerBlocks(BuiltInRegistries.BLOCK);
// registerItems(BuiltInRegistries.ITEM);
// registerEntities(BuiltInRegistries.ENTITY_TYPE);
// registerParticleTypes(BuiltInRegistries.PARTICLE_TYPE);
// registerBlockEntities(BuiltInRegistries.BLOCK_ENTITY_TYPE);
// registerMenuTypes(BuiltInRegistries.MENU);
// registerRecipeSerializers(BuiltInRegistries.RECIPE_SERIALIZER);
// registerStructures(BuiltInRegistries.STRUCTURE_TYPE);
registerSounds(BuiltInRegistries.SOUND_EVENT);

//NeoForge.EVENT_BUS.addListener(InitVillager::initTrades);

postRegistrationInitialization();

TickHandler.instance().init();

NeoForge.EVENT_BUS.addListener(this::onServerAboutToStart);
NeoForge.EVENT_BUS.addListener(this::serverStopped);
NeoForge.EVENT_BUS.addListener(this::serverStopping);
NeoForge.EVENT_BUS.addListener(this::registerCommands);
ServerLifecycleEvents.SERVER_STARTING.register(this::onServerAboutToStart);
ServerLifecycleEvents.SERVER_STOPPED.register(this::serverStopped);
ServerLifecycleEvents.SERVER_STOPPING.register(this::serverStopping);
ServerLifecycleEvents.SERVER_STARTING.register(this::registerCommands);

NeoForge.EVENT_BUS.addListener(WrenchHook::onPlayerUseBlockEvent);
NeoForge.EVENT_BUS.addListener(SkyStoneBreakSpeed::handleBreakFaster);
UseBlockCallback.EVENT.register(WrenchHook::onPlayerUseBlock);
UseBlockCallback.EVENT.register(ToolItemHook::onPlayerUseBlock);

HotkeyActions.init();
}

private void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(this::postRegistrationInitialization).whenComplete((res, err) -> {
if (err != null) {
AELog.warn(err);
}
});
}

/**
* Runs after all mods have had time to run their registrations into registries.
*/
Expand All @@ -217,32 +217,37 @@ public void registerKeyTypes(Registry<AEKeyType> registry) {
Registry.register(registry, AEKeyType.fluids().getId(), AEKeyType.fluids());
}

public void registerCommands(ServerStartingEvent evt) {
CommandDispatcher<CommandSourceStack> dispatcher = evt.getServer().getCommands().getDispatcher();
public void registerCommands(MinecraftServer server) {
CommandDispatcher<CommandSourceStack> dispatcher = server.getCommands().getDispatcher();
new AECommand().register(dispatcher);
}

public void registerSounds(Registry<SoundEvent> registry) {
AppEngSounds.register(registry);
}

public void registerRegistries(NewRegistryEvent e) {
var registry = e.create(new RegistryBuilder<>(AEKeyType.REGISTRY_KEY)
.sync(true)
.maxId(127));
AEKeyTypesInternal.setRegistry(registry);
}
// public void registerRegistries(NewRegistryEvent e) {
// var registry = e.create(new RegistryBuilder<>(AEKeyType.REGISTRY_KEY)
// .sync(true)
// .maxId(127));
// AEKeyTypesInternal.setRegistry(registry);
// }

private void onServerAboutToStart(final ServerAboutToStartEvent evt) {
ChunkLoadingService.getInstance().onServerAboutToStart(evt);
private void onServerAboutToStart(MinecraftServer server) {
this.currentServer = server;
ChunkLoadingService.getInstance().onServerAboutToStart();
}

private void serverStopping(final ServerStoppingEvent event) {
ChunkLoadingService.getInstance().onServerStopping(event);
private void serverStopping(MinecraftServer server) {
this.currentServer = server;
ChunkLoadingService.getInstance().onServerStopping();
}

private void serverStopped(final ServerStoppedEvent event) {
private void serverStopped(MinecraftServer server) {
TickHandler.instance().shutdown();
if (this.currentServer == server) {
this.currentServer = null;
}
}

public void registerCreativeTabs(Registry<CreativeModeTab> registry) {
Expand All @@ -265,11 +270,7 @@ public Collection<ServerPlayer> getPlayers() {
public void sendToAllNearExcept(Player p, double x, double y, double z,
double dist, Level level, ClientboundPacket packet) {
if (level instanceof ServerLevel serverLevel) {
ServerPlayer except = null;
if (p instanceof ServerPlayer) {
except = (ServerPlayer) p;
}
PacketDistributor.sendToPlayersNear(serverLevel, except, x, y, z, dist, packet);
NetworkUtil.sendToPlayersNear(serverLevel, x, y, z, dist, packet);
}
}

Expand All @@ -286,7 +287,7 @@ public CableRenderMode getCableRenderMode() {
@Nullable
@Override
public MinecraftServer getCurrentServer() {
return ServerLifecycleHooks.getCurrentServer();
return currentServer;
}

protected final CableRenderMode getCableRenderModeForPlayer(@Nullable Player player) {
Expand All @@ -300,9 +301,9 @@ protected final CableRenderMode getCableRenderModeForPlayer(@Nullable Player pla
return CableRenderMode.STANDARD;
}

private void registerTests(RegisterGameTestsEvent e) {
private void registerTests() {
if ("true".equals(System.getProperty("appeng.tests"))) {
e.register(GameTestPlotAdapter.class);
GameTestRegistry.register(GameTestPlotAdapter.class);
}
}
}
Loading

0 comments on commit a4f7b9c

Please sign in to comment.