Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dphaldes committed Jan 24, 2024
1 parent 5228f6f commit 0e89934
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 97 deletions.
35 changes: 4 additions & 31 deletions src/main/java/com/mystchonky/arsocultas/ArsOcultas.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
package com.mystchonky.arsocultas;

import com.hollingsworth.arsnouveau.setup.proxy.ClientProxy;
import com.hollingsworth.arsnouveau.setup.proxy.IProxy;
import com.hollingsworth.arsnouveau.setup.proxy.ServerProxy;
import com.klikli_dev.occultism.client.gui.spirit.SpiritGui;
import com.klikli_dev.occultism.client.gui.spirit.SpiritTransporterGui;
import com.klikli_dev.occultism.common.container.spirit.SpiritContainer;
import com.mystchonky.arsocultas.common.config.BaseConfig;
import com.mystchonky.arsocultas.common.init.ArsOcultasContainers;
import com.mystchonky.arsocultas.common.init.ArsOcultasItems;
import com.mystchonky.arsocultas.common.init.ArsOcultasLang;
import com.mystchonky.arsocultas.common.init.Integrations;
import com.mystchonky.arsocultas.common.network.Networking;
import com.mystchonky.arsocultas.common.registrar.ArsOcultasRegistrar;
import com.tterrag.registrate.Registrate;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
Expand All @@ -38,7 +25,6 @@
@Mod(ArsOcultas.MODID)
public class ArsOcultas {
public static final String MODID = "ars_ocultas";
public static IProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new); //TODO: Change to our own

private static final Lazy<Registrate> REGISTRATE = Lazy.of(() -> Registrate.create(MODID));
public static final Logger LOGGER = LogManager.getLogger();
Expand All @@ -61,11 +47,8 @@ public ArsOcultas() {
ctx.registerConfig(ModConfig.Type.CLIENT, BaseConfig.CLIENT_SPEC, MODID + "/base-client.toml");

IEventBus modbus = FMLJavaModLoadingContext.get().getModEventBus();
ArsOcultasItems.register();
ArsOcultasContainers.CONTAINERS.register(modbus);
Integrations.init();
ArsOcultasLang.register();

ArsOcultasRegistrar.init(modbus);
modbus.addListener(this::commonSetup);
modbus.addListener(this::clientSetup);

Expand All @@ -77,22 +60,12 @@ public static ResourceLocation prefix(String path) {
}

private void commonSetup(final FMLCommonSetupEvent event) {
Integrations.postInit();
ArsOcultasRegistrar.commonSetup(event);
Networking.registerMessages();
}

private void clientSetup(final FMLClientSetupEvent event) {
event.enqueueWork(()-> {
MenuScreens.register(ArsOcultasContainers.SPIRIT_WRAPPER.get(), SpiritGui<SpiritContainer>::new);
MenuScreens.register(ArsOcultasContainers.SPIRIT_TRANSPORT_WRAPPER.get(), SpiritTransporterGui::new);
});
}

// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event) {
// do something when the server starts
LOGGER.info("HELLO from server starting");
ArsOcultasRegistrar.clientSetup(event);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
import com.hollingsworth.arsnouveau.common.block.tile.MobJarTile;
import com.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.mystchonky.arsocultas.ArsOcultas;
import com.mystchonky.arsocultas.client.ClientInfo;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Mod.EventBusSubscriber(modid = ArsOcultas.MODID)
public class EventHandler {
@SubscribeEvent
public static void clientTickEnd(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
ClientInfo.ticksInGame++;
}
}
// @SubscribeEvent
// public static void clientTickEnd(TickEvent.ClientTickEvent event) {
// if (event.phase == TickEvent.Phase.END) {
// ClientInfo.ticksInGame++;
// }
// }

@SubscribeEvent
public static void attachItemCapability(AttachCapabilitiesEvent<BlockEntity> event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mystchonky.arsocultas.common.glyphs;

public class GlyphLibrary {

public static String prependGlyph(String glyph) {
return "glyph_" + glyph;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public void openScreen(Player playerEntity, SpiritEntity spirit, MobJarTile tile

SpiritJob currentJob = spirit.getJob().orElse(null);
if (currentJob instanceof MenuProvider jobMenuProvider)
menuProvider = new MenuProviderWrapper<>(jobMenuProvider, spirit);
menuProvider = new SpiritMenuWrapper<>(jobMenuProvider, spirit);
else
menuProvider = new MenuProviderWrapper<>(spirit, spirit);
menuProvider = new SpiritMenuWrapper<>(spirit, spirit);

NetworkHooks.openScreen((ServerPlayer) playerEntity, menuProvider, (buf) -> buf.writeBlockPos(tile.getBlockPos()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
import com.klikli_dev.occultism.common.container.spirit.SpiritTransporterContainer;
import com.klikli_dev.occultism.common.entity.job.SpiritJob;
import com.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.mystchonky.arsocultas.common.init.ArsOcultasContainers;
import com.mystchonky.arsocultas.common.registrar.MenuTypeRegistrar;
import net.minecraft.network.chat.Component;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MenuProviderWrapper<T extends MenuProvider> implements MenuProvider {
public class SpiritMenuWrapper<T extends MenuProvider> implements MenuProvider {

private final T menuProvider;
private final SpiritEntity spirit;

public MenuProviderWrapper(T menuProvider, SpiritEntity spirit) {
public SpiritMenuWrapper(T menuProvider, SpiritEntity spirit) {
this.menuProvider = menuProvider;
this.spirit = spirit;
}

@Override
public Component getDisplayName() {
public @NotNull Component getDisplayName() {
return menuProvider.getDisplayName();
}

Expand All @@ -41,17 +42,17 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInven
public static SpiritContainer wrappedSpirit(int windowId, Inventory inv, SpiritEntity spirit) {
return new SpiritContainer(windowId, inv, spirit) {
@Override
public MenuType<?> getType() {
return ArsOcultasContainers.SPIRIT_WRAPPER.get();
public @NotNull MenuType<?> getType() {
return MenuTypeRegistrar.SPIRIT_WRAPPER.get();
}
};
}

public static SpiritTransporterContainer wrappedSpiritTransporter(int windowId, Inventory inv, SpiritEntity spirit) {
return new SpiritTransporterContainer(windowId, inv, spirit) {
@Override
public MenuType<?> getType() {
return ArsOcultasContainers.SPIRIT_TRANSPORT_WRAPPER.get();
public @NotNull MenuType<?> getType() {
return MenuTypeRegistrar.SPIRIT_TRANSPORT_WRAPPER.get();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mystchonky.arsocultas.common.registrar;

import com.klikli_dev.occultism.client.gui.spirit.SpiritGui;
import com.klikli_dev.occultism.client.gui.spirit.SpiritTransporterGui;
import com.klikli_dev.occultism.common.container.spirit.SpiritContainer;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

public class ArsOcultasRegistrar {

public static void init(IEventBus modbus) {
ItemRegistrar.register();
MenuTypeRegistrar.CONTAINERS.register(modbus);
IntegrationRegistrar.init();
LangRegistrar.register();
}

public static void commonSetup(final FMLCommonSetupEvent event) {
IntegrationRegistrar.postInit();
}

public static void clientSetup(final FMLClientSetupEvent event) {
event.enqueueWork(() -> {
MenuScreens.register(MenuTypeRegistrar.SPIRIT_WRAPPER.get(), SpiritGui<SpiritContainer>::new);
MenuScreens.register(MenuTypeRegistrar.SPIRIT_TRANSPORT_WRAPPER.get(), SpiritTransporterGui::new);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mystchonky.arsocultas.common.init;
package com.mystchonky.arsocultas.common.registrar;

import com.hollingsworth.arsnouveau.api.familiar.AbstractFamiliarHolder;
import com.hollingsworth.arsnouveau.api.mob_jar.JarBehaviorRegistry;
Expand All @@ -11,14 +11,13 @@
import java.util.ArrayList;
import java.util.List;

public class Integrations {
public class IntegrationRegistrar {


public static List<AbstractSpellPart> registeredSpells = new ArrayList<>();
public static List<AbstractFamiliarHolder> registeredFamiliars = new ArrayList<>();

public static void init() {

registerGlyphs();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.mystchonky.arsocultas.common.init;
package com.mystchonky.arsocultas.common.registrar;

import com.mystchonky.arsocultas.ArsOcultas;
import com.tterrag.registrate.Registrate;

public class ArsOcultasItems {
public class ItemRegistrar {
private static final Registrate REGISTRATE = ArsOcultas.registrate();

// public static final RegistryEntry<CreativeModeTab> ARS_OSCURA_TAB = REGISTRATE.defaultCreativeTab("ars_oscura",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mystchonky.arsocultas.common.init;
package com.mystchonky.arsocultas.common.registrar;

import com.mystchonky.arsocultas.ArsOcultas;
import com.tterrag.registrate.Registrate;

public class ArsOcultasLang {
public class LangRegistrar {

private static final Registrate REGISTRATE = ArsOcultas.registrate();

public static void register() {
Integrations.registeredSpells.forEach(spell -> {
IntegrationRegistrar.registeredSpells.forEach(spell -> {
REGISTRATE.addRawLang(ArsOcultas.MODID + ".glyph_name." + spell.getRegistryName().getPath(), spell.getName());
REGISTRATE.addRawLang(ArsOcultas.MODID + ".glyph_desc." + spell.getRegistryName().getPath(), spell.getBookDescription());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mystchonky.arsocultas.common.init;
package com.mystchonky.arsocultas.common.registrar;

import com.hollingsworth.arsnouveau.common.block.tile.MobJarTile;
import com.klikli_dev.occultism.common.container.spirit.SpiritContainer;
import com.klikli_dev.occultism.common.container.spirit.SpiritTransporterContainer;
import com.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.mystchonky.arsocultas.ArsOcultas;
import com.mystchonky.arsocultas.common.mob_jar.MenuProviderWrapper;
import com.mystchonky.arsocultas.common.mob_jar.SpiritMenuWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.inventory.MenuType;
Expand All @@ -14,7 +14,7 @@
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ArsOcultasContainers {
public class MenuTypeRegistrar {
public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(
ForgeRegistries.MENU_TYPES, ArsOcultas.MODID);

Expand All @@ -24,7 +24,7 @@ public class ArsOcultasContainers {
.create((windowId, inv, data) -> {
BlockPos pos = data.readBlockPos();
MobJarTile tile = (MobJarTile) Minecraft.getInstance().level.getBlockEntity(pos);
return MenuProviderWrapper.wrappedSpirit(windowId, inv, (SpiritEntity) tile.getEntity());
return SpiritMenuWrapper.wrappedSpirit(windowId, inv, (SpiritEntity) tile.getEntity());
}));


Expand All @@ -34,6 +34,6 @@ public class ArsOcultasContainers {
.create((windowId, inv, data) -> {
BlockPos pos = data.readBlockPos();
MobJarTile tile = (MobJarTile) Minecraft.getInstance().level.getBlockEntity(pos);
return MenuProviderWrapper.wrappedSpiritTransporter(windowId, inv, (SpiritEntity) tile.getEntity());
return SpiritMenuWrapper.wrappedSpiritTransporter(windowId, inv, (SpiritEntity) tile.getEntity());
}));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mystchonky.arsocultas.datagen;

import com.mystchonky.arsocultas.ArsOcultas;
import com.mystchonky.arsocultas.common.init.Integrations;
import com.mystchonky.arsocultas.common.registrar.IntegrationRegistrar;
import net.minecraft.data.PackOutput;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
Expand All @@ -13,6 +13,6 @@ public GlyphItemModelProvider(PackOutput packOutput, ExistingFileHelper existing

@Override
protected void registerModels() {
Integrations.registeredSpells.forEach(spell -> basicItem(spell.getRegistryName()));
IntegrationRegistrar.registeredSpells.forEach(spell -> basicItem(spell.getRegistryName()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mystchonky.arsocultas.datagen;

import com.hollingsworth.arsnouveau.api.spell.AbstractSpellPart;
import com.mystchonky.arsocultas.common.init.Integrations;
import com.mystchonky.arsocultas.common.registrar.IntegrationRegistrar;
import net.minecraft.data.DataGenerator;

public class PatchouliProvider extends com.hollingsworth.arsnouveau.common.datagen.PatchouliProvider {
Expand All @@ -12,7 +12,7 @@ public PatchouliProvider(DataGenerator generatorIn) {

@Override
public void addEntries() {
for (AbstractSpellPart spell : Integrations.registeredSpells) {
for (AbstractSpellPart spell : IntegrationRegistrar.registeredSpells) {
addGlyphPage(spell);
}
}
Expand Down

0 comments on commit 0e89934

Please sign in to comment.