Skip to content

Commit

Permalink
chore: update example project
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Jul 16, 2023
1 parent 82d075e commit 36774fe
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 176 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Please contact us on our [discord](https://discord.sekwah.com/).
# Examples
I will link examples as I switch other mods of my own over to doing multi-platform.

I will also at some point setup the forge-testmod, fabric-testmod and core-testmod as another example to also allow for basic testing of the library during dev.
I will also at some point setup the forge-testmod, fabric-testmod and core-testmod as another example to also allow for basic testing of the library during dev.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// In the old version for auto you couldnt have seperate later stages easily
// In the old version for auto you couldnt have separate later stages easily
// Thanks to release-please we can leave this mostly empty
// Need to clean up the gradle files as I know however the focus is on it working vs being best practices.
// If you have suggestions on how to improve these feel free to make th em :)

plugins {
id "com.modrinth.minotaur" version "2.+"
}
Expand Down
55 changes: 1 addition & 54 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,7 @@ minecraft {
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
//property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"

mods {
"${project.modid}" {
source sourceSets.main
}
}
}

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
//property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
"${project.modid}" {
source sourceSets.main
}
}
}

data {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
//property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

args '--mod', project.modid, '--all', '--output', file('src/generated/resources/')

mods {
"${project.modid}" {
source sourceSets.main
}
}
}
// Copy from other projects if needed
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sekwah.sekclib.core.util;
package com.sekwah.sekclib.util;

import net.minecraft.network.chat.TextColor;
import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sekwah.sekclib.core.util;
package com.sekwah.sekclib.util;

import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
Expand Down
88 changes: 17 additions & 71 deletions forge-testmod/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "org.spongepowered:mixingradle:0.7+"
classpath(group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '6.0.+', changing: true)
classpath "org.apache.httpcomponents:httpmime:4.5.14"
}
}
plugins {
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
}

apply plugin: 'net.minecraftforge.gradle'
apply plugin: "java"
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

def modid = "sekclib-testmod"
def modid = "sekclibtest"

//apply plugin: "org.spongepowered.mixin"
apply plugin: "org.spongepowered.mixin"

def branch = System.getenv("GITHUB_REF")
def snapshotName = null;
Expand Down Expand Up @@ -103,6 +100,8 @@ minecraft {
//property 'mixin.env.remapRefMap', 'true'
//property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"

ideaModule "SekCLib.forge-testmod.main"

mods {
"${modid}" {
source sourceSets.main
Expand All @@ -120,6 +119,8 @@ minecraft {
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

ideaModule "SekCLib.forge-testmod.main"

mods {
"${modid}" {
source sourceSets.main
Expand All @@ -137,6 +138,8 @@ minecraft {
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

ideaModule "SekCLib.forge-testmod.main"

args '--mod', modid, '--all', '--output', file('src/generated/resources/')

mods {
Expand All @@ -157,39 +160,20 @@ dependencies {
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

//implementation 'org.spongepowered:mixin:0.8.5'
//annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation 'org.spongepowered:mixin:0.8.5'
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'

implementation project(":forge")
// Trick intellij to allow for better editing in here for the discord task
// compile "org.apache.httpcomponents:httpmime:4.5.13"
//implementation fg.deobf("curse.maven:torohealth-damage-indicators-245733:3556931")

//implementation fg.deobf("curse.maven:hwyla:${project.hwyla_fileid}")

//include('org.ow2.asm:asm-debug-all:5.2')

// 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"

// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

}

// Readd if mixins start being used
//mixin {
// add sourceSets.main, "mixins.${project.modid}.refmap.json"
//
// debug.verbose = true
// debug.export = true
//}
mixin {
add sourceSets.main, "mixins.${modid}.refmap.json"

debug.verbose = true
debug.export = true
}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
Expand Down Expand Up @@ -301,41 +285,3 @@ task discordupload {
}
}
}

tasks.curseforge.enabled = System.getenv("CURSE_API") != null

curseforge {
logger.info("Curse api: " + System.getenv("CURSE_API"))
if (System.getenv("CURSE_API") != null) {
apiKey = System.getenv("CURSE_API")
}
project {
id = project.curse_project_id
// TODO add code to reference this but also cut the latest change logs in for the files
changelog = getReleaseChangelog()
changelogType = 'markdown'
releaseType = 'release'
addGameVersion '1.20'
addGameVersion '1.20.1'

mainArtifact(jar){

}
addArtifact srcJar
addArtifact deobfJar
}
}

// https://github.com/modrinth/minotaur
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = project.modrinth_slug
versionType = "release"
uploadFile = jar
additionalFiles = [srcJar, deobfJar]
// Split string into array


gameVersions = project.game_versions.tokenize(",")
changelog = getReleaseChangelog()
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package com.sekwah.sekclibtest;

import com.sekwah.sekclib.capabilitysync.capabilitysync.RegisterCapabilitySyncEvent;
import com.sekwah.sekclibtest.capabilities.CapabilityHandler;
import com.sekwah.sekclibtest.capabilities.IDiamondData;
import com.sekwah.sekclibtest.capabilities.DiamondData;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(SekCLibTest.MOD_ID)
@Mod.EventBusSubscriber(modid = SekCLibTest.MOD_ID)
public class SekCLibTest {
public static final String MOD_ID = "sekclibtest";

public SekCLibTest() {
System.out.println("HELLO");
// You can do it this way or use a EventBusSubscriber that points to the MOD bus.
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
eventBus.addListener(this::registerCapabilities);
eventBus.addListener(this::registerCapabilitySync);
}

private void registerCapabilities(RegisterCapabilitiesEvent event) {
event.register(IDiamondData.class);
}

public void registerCapabilitySync(RegisterCapabilitySyncEvent event) {
event.registerPlayerCap(new ResourceLocation(SekCLibTest.MOD_ID, "test_data"), CapabilityHandler.DIAMOND_DATA, DiamondData.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sekwah.sekclibtest.capabilities;

import com.sekwah.sekclibtest.SekCLibTest;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = SekCLibTest.MOD_ID)
public class CapabilityHandler {
public static final Capability<IDiamondData> DIAMOND_DATA = CapabilityManager.get(new CapabilityToken<>() {});

@SubscribeEvent
public static void attachCapability(AttachCapabilitiesEvent<Entity> event) {
event.addCapability(new ResourceLocation(SekCLibTest.MOD_ID, "diamond_infected_data"), new DiamondData());
}

@SubscribeEvent
public static void livingHurt(LivingHurtEvent event) {
var entity = event.getEntity();
entity.getCapability(DIAMOND_DATA).ifPresent(testData -> {
testData.setDiamond(true);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.sekwah.sekclibtest.capabilities;

import com.sekwah.sekclib.capabilitysync.capabilitysync.annotation.Sync;
import net.minecraft.core.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class DiamondData implements IDiamondData, ICapabilityProvider {


private final LazyOptional<IDiamondData> holder = LazyOptional.of(() -> this);

@Sync(syncGlobally = true)
private boolean diamondMode = false;

@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
return CapabilityHandler.DIAMOND_DATA.orEmpty(cap, holder);
}

@Override
public boolean isDiamond() {
return this.diamondMode;
}

@Override
public void setDiamond(boolean isDiamond) {
this.diamondMode = isDiamond;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sekwah.sekclibtest.capabilities;

public interface IDiamondData {
boolean isDiamond();
void setDiamond(boolean isDiamond);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.sekwah.sekclibtest.mixins.client;

import com.sekwah.sekclibtest.SekCLibTest;
import com.sekwah.sekclibtest.capabilities.CapabilityHandler;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Wolf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntityRenderer.class)
public class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> {

@Shadow protected M model;
private ResourceLocation diamond = new ResourceLocation(SekCLibTest.MOD_ID, "textures/entity/diamond_block.png");

@Inject(method = "getRenderType", at = @At("HEAD"), cancellable = true)
protected void getEntityTexture(T target, boolean p_115323_, boolean p_115324_, boolean p_115325_, CallbackInfoReturnable<RenderType> cir) {
target.getCapability(CapabilityHandler.DIAMOND_DATA).ifPresent(diamondInfectedData -> {
if(diamondInfectedData.isDiamond()) {
ResourceLocation resourcelocation = diamond;
if (p_115324_) {
cir.setReturnValue(RenderType.itemEntityTranslucentCull(resourcelocation));
} else if (p_115323_) {
cir.setReturnValue(this.model.renderType(resourcelocation));
} else {
cir.setReturnValue(p_115325_ ? RenderType.outline(resourcelocation) : null);
}
cir.cancel();
}
});
}
}
3 changes: 3 additions & 0 deletions forge-testmod/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
COMMENT: This file exists purely for dev time,
anything added here should be mirrored in the build.gradle.
MixinConfigs: mixins.sekclibtest.json
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 36774fe

Please sign in to comment.