Skip to content

Commit

Permalink
add configs, refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
haoict committed Mar 30, 2021
1 parent 6754a44 commit 65172e5
Show file tree
Hide file tree
Showing 23 changed files with 780 additions and 628 deletions.
45 changes: 31 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.0.1'
version = "${mod_version}"
group = 'com.haoict.tiab' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'time-in-a-bottle'

Expand All @@ -28,7 +28,7 @@ minecraft {
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20201028-1.16.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
Expand All @@ -44,7 +44,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
tiab {
source sourceSets.main
}
}
Expand All @@ -60,7 +60,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
tiab {
source sourceSets.main
}
}
Expand All @@ -76,10 +76,10 @@ minecraft {
property 'forge.logging.console.level', 'debug'

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
args '--mod', 'tiab', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')

mods {
examplemod {
tiab {
source sourceSets.main
}
}
Expand All @@ -96,6 +96,11 @@ dependencies {
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.16.4-35.1.36'

compileOnly fg.deobf("mezz.jei:jei-1.16.4:${jei_version}:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.4:${jei_version}")

runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core

// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
Expand All @@ -120,20 +125,32 @@ dependencies {
jar {
manifest {
attributes([
"Specification-Title": "examplemod",
"Specification-Vendor": "examplemodsareus",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"examplemodsareus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
"Specification-Title" : "tiab",
"Specification-Vendor" : "haoictvendor",
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Vendor" : "haoictvendor",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

repositories {
maven {
// JEI
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// Mekanism
url 'https://modmaven.dev/'
}
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

Expand Down
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.daemon=false

#Mod Info
mod_version=1.1.0

#Dependencies
jei_version=7.6.1.71
mekanism_version=1.16.4-10.0.19.446
13 changes: 0 additions & 13 deletions src/main/java/com/haoict/tiab/Config.java

This file was deleted.

220 changes: 121 additions & 99 deletions src/main/java/com/haoict/tiab/Tiab.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,121 @@
package com.haoict.tiab;

import com.haoict.tiab.client.ClientProxy;
import com.haoict.tiab.entities.TiabEntityTypes;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Config.MOD_ID)
public class Tiab {
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();

public Tiab() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);

ItemRegistryHandler.init();
MinecraftForge.EVENT_BUS.register(CommandEventRegistryHandler.class);
}

private void setup(final FMLCommonSetupEvent event) {
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}

private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}

private void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
InterModComms.sendTo(Config.MOD_ID, "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}

private void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m -> m.getMessageSupplier().get()).
collect(Collectors.toList()));
}

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

// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}

@SubscribeEvent
public static void onEntityTypeRegistration(RegistryEvent.Register<EntityType<?>> entityTypeRegisterEvent) {
TiabEntityTypes.timeAcceleratorEntityType.setRegistryName("tiab:time_accelerator_entity_type");
entityTypeRegisterEvent.getRegistry().register(TiabEntityTypes.timeAcceleratorEntityType);
}
}
}
package com.haoict.tiab;

import com.haoict.tiab.client.ClientProxy;
import com.haoict.tiab.common.registries.CommandEventRegistry;
import com.haoict.tiab.common.CommonProxy;
import com.haoict.tiab.common.registries.ItemRegistry;
import com.haoict.tiab.common.entities.TiabEntityTypes;
import com.haoict.tiab.config.Constants;
import com.haoict.tiab.config.TiabConfig;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Constants.MOD_ID)
public class Tiab {
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();

/**
* Register our creative tab. Notice that we're also modifying the NBT data of the
* building gadget to remove the damage / energy indicator from the creative
* tabs icon.
*/
public static final ItemGroup TIAB_ITEM_GROUP = new ItemGroup(Constants.MOD_ID) {
@Override
public ItemStack createIcon() {
return new ItemStack(ItemRegistry.BOTTLE.get());
}
};

public Tiab() {
TiabConfig.init();

// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

ItemRegistry.init();

DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);

MinecraftForge.EVENT_BUS.register(CommandEventRegistry.class);
}

private void setup(final FMLCommonSetupEvent event) {
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}

private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}

private void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
InterModComms.sendTo(Constants.MOD_ID, "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}

private void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m -> m.getMessageSupplier().get()).
collect(Collectors.toList()));
}

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

// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}

@SubscribeEvent
public static void onEntityTypeRegistration(RegistryEvent.Register<EntityType<?>> entityTypeRegisterEvent) {
TiabEntityTypes.timeAcceleratorEntityType.setRegistryName("tiab:time_accelerator_entity_type");
entityTypeRegisterEvent.getRegistry().register(TiabEntityTypes.timeAcceleratorEntityType);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/haoict/tiab/client/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.haoict.tiab.client;

import com.haoict.tiab.client.renderer.EntityTimeAcceleratorRenderer;
import com.haoict.tiab.entities.TiabEntityTypes;
import com.haoict.tiab.common.entities.TiabEntityTypes;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

public class ClientProxy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.haoict.tiab.client.renderer;

import com.haoict.tiab.entities.EntityTimeAccelerator;
import com.haoict.tiab.common.entities.EntityTimeAccelerator;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haoict.tiab;
package com.haoict.tiab.common;

public class CommonProxy {
public CommonProxy() {
Expand Down
Loading

0 comments on commit 65172e5

Please sign in to comment.