Skip to content

Commit

Permalink
Base Migration
Browse files Browse the repository at this point in the history
- Separate of classes complete: `base` and `utils` are migrated to `com.teammoeg.chorda` package.
- A lot of refactoring! Please pull!
  • Loading branch information
yuesha-yc committed Jan 16, 2025
1 parent cfcc5a7 commit 9be7a51
Show file tree
Hide file tree
Showing 657 changed files with 2,206 additions and 2,174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.teammoeg.frostedheart.FHMain;
import com.teammoeg.frostedheart.util.RegistryUtils;
import com.teammoeg.chorda.util.RegistryUtils;

import blusunrize.immersiveengineering.common.register.IEBlocks;
import blusunrize.immersiveengineering.data.DataGenUtils;
import blusunrize.immersiveengineering.data.models.IEOBJBuilder;
import blusunrize.immersiveengineering.data.models.SplitModelBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.teammoeg.frostedheart.FHMain;
import com.teammoeg.frostedheart.bootstrap.common.FHItems;
import com.teammoeg.frostedheart.content.trade.policy.TradeBuilder;
import com.teammoeg.frostedheart.util.RegistryUtils;
import com.teammoeg.chorda.util.RegistryUtils;

import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.FinishedRecipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.gson.JsonObject;
import com.teammoeg.frostedheart.content.water.recipe.WaterLevelAndEffectRecipe;
import com.teammoeg.frostedheart.util.RegistryUtils;
import com.teammoeg.chorda.util.RegistryUtils;

import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.world.level.material.Fluid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.teammoeg.frostedheart.bootstrap.client;
package com.teammoeg.chorda;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.teammoeg.frostedheart.FHMain;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.server.packs.resources.ResourceProvider;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -15,8 +14,8 @@
import java.util.Objects;

@OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class FHShaderInstances {
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = Chorda.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class CShaders {

@Nullable
private static ShaderInstance roundRect;
Expand Down Expand Up @@ -45,23 +44,23 @@ public static void onRegisterShaders(RegisterShadersEvent event) throws IOExcept
event.registerShader(
new ShaderInstance(
provider,
FHMain.rl("ring"),
Chorda.rl("ring"),
DefaultVertexFormat.POSITION_TEX_COLOR
),
(shader) -> ring = shader
);
event.registerShader(
new ShaderInstance(
provider,
FHMain.rl("round_rect"),
Chorda.rl("round_rect"),
DefaultVertexFormat.POSITION_TEX_COLOR
),
(shader) -> roundRect = shader
);
event.registerShader(
new ShaderInstance(
provider,
FHMain.rl("round"),
Chorda.rl("round"),
DefaultVertexFormat.POSITION_TEX
),
(shader) -> round = shader
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/teammoeg/chorda/CUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.teammoeg.chorda;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.Minecraft;

public class CUtils {
public static boolean isDown(int key) {
return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), key);
}
}
102 changes: 102 additions & 0 deletions src/main/java/com/teammoeg/chorda/Chorda.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.teammoeg.chorda;

import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

//@Mod(Chorda.MODID)
public class Chorda {
public static final String MODID = "chorda";
public static final String MODNAME = "Chorda";
// Logger
public static final Logger LOGGER = LogManager.getLogger(MODNAME);
public static final Marker VERSION_CHECK = MarkerManager.getMarker("Version Check");
public static final Marker INIT = MarkerManager.getMarker("Init");
public static final Marker SETUP = MarkerManager.getMarker("Setup");
public static final Marker COMMON_INIT = MarkerManager.getMarker("Common").addParents(INIT);
public static final Marker CLIENT_INIT = MarkerManager.getMarker("Client").addParents(INIT);
public static final Marker COMMON_SETUP = MarkerManager.getMarker("Common").addParents(SETUP);
public static final Marker CLIENT_SETUP = MarkerManager.getMarker("Client").addParents(SETUP);

public static ResourceLocation rl(String path) {
return new ResourceLocation(MODID, path);
}

public Chorda() {
IEventBus mod = FMLJavaModLoadingContext.get().getModEventBus();
IEventBus forge = MinecraftForge.EVENT_BUS;

// Config
LOGGER.info(COMMON_INIT, "Loading Config");
ChordaConfig.register();

// Init
LOGGER.info(COMMON_INIT, "Initializing " + MODNAME);

// Compat init
LOGGER.info(COMMON_INIT, "Initializing Mod Compatibilities");

// Deferred Registration
// Order doesn't matter here, as that's why we use deferred registers
// See ForgeRegistries for more info
LOGGER.info(COMMON_INIT, "Registering Deferred Registers");

// Forge bus
LOGGER.info(COMMON_INIT, "Registering Forge Event Listeners");

// Mod bus
LOGGER.info(COMMON_INIT, "Registering Mod Event Listeners");

// Client setup
LOGGER.info(COMMON_INIT, "Proceeding to Client Initialization");
if (FMLEnvironment.dist == Dist.CLIENT) {
ChordaClient.init();
}
}

/**
* Setup stuff that requires deferred registers to be filled.
* @param event The event
*/
private void setup(final FMLCommonSetupEvent event) {

}

/**
* Enqueue Inter-Mod Communication
* @param event The event
*/
private void enqueueIMC(final InterModEnqueueEvent event) {

}

/**
* Process Inter-Mod Communication
* @param event The event
*/
private void processIMC(final InterModProcessEvent event) {

}

/**
* Stuff that needs to be done after everything is loaded.
* In general, not used.
* @param event The event
*/
private void loadComplete(FMLLoadCompleteEvent event) {

}

}
22 changes: 22 additions & 0 deletions src/main/java/com/teammoeg/chorda/ChordaClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.teammoeg.chorda;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

public class ChordaClient {

public static void init() {
// Client only init
IEventBus mod = FMLJavaModLoadingContext.get().getModEventBus();
IEventBus forge = MinecraftForge.EVENT_BUS;

Chorda.LOGGER.info(Chorda.CLIENT_INIT, "Initializing client");

Chorda.LOGGER.info(Chorda.CLIENT_INIT, "Registering client forge event listeners");

Chorda.LOGGER.info(Chorda.CLIENT_INIT, "Registering client mod event listeners");

Chorda.LOGGER.info(Chorda.CLIENT_INIT, "Finished initializing client");
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/teammoeg/chorda/ChordaConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.teammoeg.chorda;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;

public class ChordaConfig {

public static class Client {

Client(ForgeConfigSpec.Builder builder) {

}

}

public static class Common {

Common(ForgeConfigSpec.Builder builder) {

}

}

public static class Server {
public final ForgeConfigSpec.ConfigValue<Double> taskPerTick;

Server(ForgeConfigSpec.Builder builder) {
taskPerTick = builder.comment("Range Detection tasks to execute per tick")
.defineInRange("taskPerTick", 1, 0.005, Integer.MAX_VALUE);
}

}
public static void register() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_CONFIG);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, COMMON_CONFIG);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG);
}

public static final ForgeConfigSpec CLIENT_CONFIG;
public static final ForgeConfigSpec COMMON_CONFIG;
public static final ForgeConfigSpec SERVER_CONFIG;
public static final Client CLIENT;
public static final Common COMMON;
public static final Server SERVER;

static {
ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();
CLIENT = new Client(CLIENT_BUILDER);
CLIENT_CONFIG = CLIENT_BUILDER.build();
ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder();
COMMON = new Common(COMMON_BUILDER);
COMMON_CONFIG = COMMON_BUILDER.build();
ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder();
SERVER = new Server(SERVER_BUILDER);
SERVER_CONFIG = SERVER_BUILDER.build();
}
}
96 changes: 96 additions & 0 deletions src/main/java/com/teammoeg/chorda/ChordaNetwork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.teammoeg.chorda;

import com.teammoeg.chorda.network.FHContainerDataSync;
import com.teammoeg.chorda.network.FHContainerOperation;
import com.teammoeg.chorda.network.FHMessage;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.simple.SimpleChannel;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class ChordaNetwork {
private static SimpleChannel CHANNEL;
private static Map<Class<? extends FHMessage>, ResourceLocation> classesId = new HashMap<>();

public static SimpleChannel get() {
return CHANNEL;
}

private static int iid = 0;

/**
* Register Message Type, would automatically use method in FHMessage as serializer and &lt;init&gt;(PacketBuffer) as deserializer
*/
public static synchronized <T extends FHMessage> void registerMessage(String name, Class<T> msg) {
classesId.put(msg, Chorda.rl(name));
try {
Constructor<T> ctor = msg.getConstructor(FriendlyByteBuf.class);
CHANNEL.registerMessage(++iid, msg, FHMessage::encode, pb -> {
try {
return ctor.newInstance(pb);
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException |
InvocationTargetException e) {
e.printStackTrace();
throw new RuntimeException("Can not create message " + msg.getSimpleName()+e.getMessage(), e);
}
}, FHMessage::handle);
} catch (NoSuchMethodException | SecurityException e1) {
Chorda.LOGGER.error("Can not register message " + msg.getSimpleName());
e1.printStackTrace();
}
}

/**
* Register Message Type, should provide a deserializer
*/
public static synchronized <T extends FHMessage> void registerMessage(String name, Class<T> msg, Function<FriendlyByteBuf, T> func) {
classesId.put(msg, Chorda.rl(name));
CHANNEL.registerMessage(++iid, msg, FHMessage::encode, func, FHMessage::handle);
//CHANNEL.registerMessage(++iid,msg,FHMessage::encode,func,FHMessage::handle);
}

public static ResourceLocation getId(Class<? extends FHMessage> cls) {
return classesId.get(cls);
}

public static void register() {
String VERSION = ModList.get().getModContainerById(Chorda.MODID).get().getModInfo().getVersion().toString();
Chorda.LOGGER.info("FH Network Version: " + VERSION);
CHANNEL = NetworkRegistry.newSimpleChannel(Chorda.rl("network"), () -> VERSION, VERSION::equals, VERSION::equals);

//Fundamental Message
registerMessage("container_operation", FHContainerOperation.class);
registerMessage("container_sync", FHContainerDataSync.class);

}

public static void sendPlayer(ServerPlayer p, FHMessage message) {
send(PacketDistributor.PLAYER.with(() -> p), message);
}

public static void send(PacketDistributor.PacketTarget target, FHMessage message) {
CHANNEL.send(target, message);
}

public static void sendToServer(FHMessage message) {
CHANNEL.sendToServer(message);
}

public static void sendToAll(FHMessage message) {
send(PacketDistributor.ALL.noArg(), message);
}

public static void sendToTrackingChunk(LevelChunk levelChunk, FHMessage packet) {
send(PacketDistributor.TRACKING_CHUNK.with(() -> levelChunk), packet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

package com.teammoeg.frostedheart.base.block;
package com.teammoeg.chorda.block;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

package com.teammoeg.frostedheart.base.block;
package com.teammoeg.chorda.block;

import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import net.minecraft.world.level.block.state.BlockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with Caupona. If not, see <https://www.gnu.org/licenses/>.
*/

package com.teammoeg.frostedheart.base.block;
package com.teammoeg.chorda.block;

import java.util.function.Supplier;

Expand Down
Loading

0 comments on commit 9be7a51

Please sign in to comment.