ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java

195 lines
9.3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ActuallyAdditions.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod;
2024-03-04 20:21:48 +01:00
import com.mojang.serialization.Codec;
2024-03-05 16:58:45 +01:00
import com.mojang.serialization.codecs.RecordCodecBuilder;
2016-05-14 13:51:18 +02:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
2023-12-20 22:02:25 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyTags;
2022-01-08 19:54:43 +01:00
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
import de.ellpeck.actuallyadditions.mod.attachments.ActuallyAttachments;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
2021-11-21 22:03:07 +01:00
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
2022-12-30 01:02:38 +01:00
import de.ellpeck.actuallyadditions.mod.config.conditions.BoolConfigCondition;
2021-10-12 23:19:47 +02:00
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting;
import de.ellpeck.actuallyadditions.mod.data.WorldData;
2021-11-13 20:09:55 +01:00
import de.ellpeck.actuallyadditions.mod.entity.EntityWorm;
2016-07-22 20:23:51 +02:00
import de.ellpeck.actuallyadditions.mod.entity.InitEntities;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.event.CommonEvents;
2016-01-29 17:38:31 +01:00
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
2024-03-05 16:58:45 +01:00
import de.ellpeck.actuallyadditions.mod.gen.modifier.BoolConfigFeatureBiomeModifier;
2021-02-27 21:24:26 +01:00
import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers;
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.ItemCoffee;
2023-12-20 22:02:25 +01:00
import de.ellpeck.actuallyadditions.mod.items.Worm;
2016-10-31 19:05:29 +01:00
import de.ellpeck.actuallyadditions.mod.misc.BannerHelper;
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.LaserRelayConnectionHandler;
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
2023-01-19 16:27:56 +01:00
import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
2021-10-23 20:17:04 +02:00
import de.ellpeck.actuallyadditions.mod.util.ResourceReloader;
2024-03-04 20:21:48 +01:00
import net.minecraft.core.registries.BuiltInRegistries;
2024-03-02 21:23:08 +01:00
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
2024-03-05 16:58:45 +01:00
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
2024-03-04 20:21:48 +01:00
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.conditions.ICondition;
2024-03-05 16:58:45 +01:00
import net.neoforged.neoforge.common.world.BiomeModifier;
2024-03-04 20:21:48 +01:00
import net.neoforged.neoforge.event.AddReloadListenerEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
2021-02-26 22:15:48 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2015-10-02 16:48:01 +02:00
2024-03-04 20:21:48 +01:00
import java.util.function.Supplier;
2021-02-27 21:24:26 +01:00
@Mod(ActuallyAdditions.MODID)
2018-03-23 03:53:13 +01:00
public class ActuallyAdditions {
2018-05-10 11:38:58 +02:00
public static final String MODID = ActuallyAdditionsAPI.MOD_ID;
2021-02-27 21:24:26 +01:00
@Deprecated
2018-05-10 11:38:58 +02:00
public static final String NAME = "Actually Additions";
2021-02-27 21:24:26 +01:00
@Deprecated
2018-05-10 11:38:58 +02:00
public static final String VERSION = "@VERSION@";
2021-02-27 21:24:26 +01:00
@Deprecated
2018-05-10 11:38:58 +02:00
public static final String GUIFACTORY = "de.ellpeck.actuallyadditions.mod.config.GuiFactory";
2019-05-18 20:40:53 +02:00
public static final String DEPS = "required:forge@[14.23.5.2836,);before:craftingtweaks;after:fastbench@[1.3.2,)";
2021-08-22 23:19:57 +02:00
public static final Logger LOGGER = LogManager.getLogger(NAME);
2021-11-13 20:09:55 +01:00
2024-03-04 20:21:48 +01:00
private static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(BuiltInRegistries.ENTITY_TYPE, MODID);
public static final Supplier<EntityType<EntityWorm>> ENTITY_WORM = ENTITIES.register("worm", () -> EntityType.Builder.of(EntityWorm::new, MobCategory.MISC).build(MODID + ":worm"));
private static final DeferredRegister<Codec<? extends ICondition>> CONDITION_CODECS = DeferredRegister.create(NeoForgeRegistries.Keys.CONDITION_CODECS, MODID);
public static final DeferredHolder<Codec<? extends ICondition>, Codec<BoolConfigCondition>> BOOL_CONFIG_CONDITION = CONDITION_CODECS.register("bool_config_condition", () -> BoolConfigCondition.CODEC);
2024-03-05 16:58:45 +01:00
public static final DeferredRegister<Codec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
public static final Supplier<Codec<BoolConfigFeatureBiomeModifier>> BOOL_CONFIG_MODIFIER = BIOME_MODIFIER_SERIALIZERS.register("bool_config_feature_modifier", () ->
RecordCodecBuilder.create(builder -> builder.group(
Biome.LIST_CODEC.fieldOf("biomes").forGetter(BoolConfigFeatureBiomeModifier::biomes),
PlacedFeature.LIST_CODEC.fieldOf("features").forGetter(BoolConfigFeatureBiomeModifier::features),
GenerationStep.Decoration.CODEC.fieldOf("step").forGetter(BoolConfigFeatureBiomeModifier::step),
Codec.STRING.fieldOf("boolConfig").forGetter(BoolConfigFeatureBiomeModifier::boolConfig)
).apply(builder, BoolConfigFeatureBiomeModifier::new))
);
2021-11-13 20:09:55 +01:00
2018-05-10 11:38:58 +02:00
public static boolean commonCapsLoaded;
2024-03-04 20:21:48 +01:00
public ActuallyAdditions(IEventBus eventBus) {
2021-11-21 22:03:07 +01:00
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.COMMON_CONFIG);
2021-11-21 21:45:33 +01:00
ActuallyBlocks.init(eventBus);
ActuallyItems.init(eventBus);
2024-03-03 01:20:53 +01:00
ActuallyTabs.init(eventBus);
2021-10-12 23:19:47 +02:00
ActuallyRecipes.init(eventBus);
AASounds.init(eventBus);
ActuallyAttachments.init(eventBus);
2021-02-27 21:24:26 +01:00
ActuallyContainers.CONTAINERS.register(eventBus);
2021-11-13 20:09:55 +01:00
ENTITIES.register(eventBus);
2024-03-04 20:21:48 +01:00
CONDITION_CODECS.register(eventBus);
2024-03-05 16:58:45 +01:00
BIOME_MODIFIER_SERIALIZERS.register(eventBus);
eventBus.addListener(this::onConfigReload);
2023-01-19 16:27:56 +01:00
ActuallyParticles.init(eventBus);
2023-12-20 22:02:25 +01:00
ActuallyTags.init();
2021-02-27 21:24:26 +01:00
2024-03-04 20:21:48 +01:00
NeoForge.EVENT_BUS.addListener(this::serverStarted);
NeoForge.EVENT_BUS.addListener(this::serverStopped);
NeoForge.EVENT_BUS.register(new CommonEvents());
// NeoForge.EVENT_BUS.register(new DungeonLoot());
2024-03-04 20:21:48 +01:00
NeoForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent);
NeoForge.EVENT_BUS.addListener(Worm::onHoe);
2021-10-24 18:03:33 +02:00
InitFluids.init(eventBus);
2021-02-27 21:24:26 +01:00
2024-03-04 20:21:48 +01:00
eventBus.addListener(PacketHandler::register);
2021-02-27 21:24:26 +01:00
eventBus.addListener(this::setup);
2024-03-02 21:23:08 +01:00
2024-03-04 20:21:48 +01:00
if (FMLEnvironment.dist.isClient()) {
eventBus.addListener(this::clientSetup);
eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders);
eventBus.addListener(this::particleFactoryRegister);
eventBus.register(new ClientRegistryHandler());
2024-03-04 20:21:48 +01:00
}
2022-01-08 19:54:43 +01:00
IFarmerBehavior.initBehaviors();
2021-02-27 21:24:26 +01:00
}
2021-11-13 20:09:55 +01:00
private static void reloadEvent(AddReloadListenerEvent event) {
2024-03-02 21:23:08 +01:00
event.addListener(new ResourceReloader(event.getServerResources()));
2021-11-13 20:09:55 +01:00
}
2021-02-27 21:24:26 +01:00
private void setup(FMLCommonSetupEvent event) {
2016-05-14 13:51:18 +02:00
ActuallyAdditionsAPI.methodHandler = new MethodHandler();
ActuallyAdditionsAPI.connectionHandler = new LaserRelayConnectionHandler();
2022-06-24 21:23:43 +02:00
//Lenses.init();
2021-08-22 23:19:57 +02:00
// CompatUtil.registerCraftingTweaks();
2021-02-27 21:24:26 +01:00
commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities");
2016-07-03 20:57:00 +02:00
new UpdateChecker();
BannerHelper.init();
2021-02-27 21:24:26 +01:00
InitEntities.init(); // todo: [port] replace
2021-08-31 00:44:39 +02:00
//AAWorldGen gen = new AAWorldGen();
ItemCoffee.initIngredients();
CrusherCrafting.init();
2022-08-31 00:20:32 +02:00
//LensMining.init();
2021-10-23 20:17:04 +02:00
}
2024-03-02 21:23:08 +01:00
private void onConfigReload(ModConfigEvent event) {
2024-03-04 20:21:48 +01:00
Item item1 = BuiltInRegistries.ITEM.get(new ResourceLocation(CommonConfig.Other.REDSTONECONFIGURATOR.get()));
Item item2 = BuiltInRegistries.ITEM.get(new ResourceLocation(CommonConfig.Other.RELAYCONFIGURATOR.get()));
CommonConfig.Other.redstoneConfigureItem = item1 != null?item1: Items.AIR;
CommonConfig.Other.relayConfigureItem = item2 != null?item2: Items.AIR;
}
2021-02-27 21:24:26 +01:00
private void clientSetup(FMLClientSetupEvent event) {
2023-01-16 22:47:31 +01:00
ActuallyAdditionsClient.setup(event);
}
2015-06-28 03:12:32 +02:00
2024-03-03 01:20:53 +01:00
private void particleFactoryRegister(RegisterParticleProvidersEvent event) {
2023-01-19 16:27:56 +01:00
ActuallyAdditionsClient.registerParticleFactories();
}
2024-03-02 21:23:08 +01:00
public void serverStarted(ServerStartedEvent event) {
2021-02-27 21:24:26 +01:00
// TODO: [port] check if this is needed
// if (event.getServer() != null) {
// World world = event.getServer().getWorld(OVERWORLD);
// if (world != null && !world.isRemote) {
// WorldData.get(world, true).markDirty();
// }
// }
}
2024-03-02 21:23:08 +01:00
public void serverStopped(ServerStoppedEvent event) {
2021-02-27 21:24:26 +01:00
// TODO: [port] check if this is needed
WorldData.clear();
}
}