-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Separate of classes complete: `base` and `utils` are migrated to `com.teammoeg.chorda` package. - A lot of refactoring! Please pull!
- Loading branch information
Showing
657 changed files
with
2,206 additions
and
2,174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <init>(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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.