Skip to content

Commit

Permalink
feat: add mixin processor for PowderSnowBlock
Browse files Browse the repository at this point in the history
Signed-off-by: AlasDiablo <[email protected]>
  • Loading branch information
AlasDiablo committed Jan 16, 2022
1 parent 7a61a0c commit 7bdfb2b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 15 deletions.
30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
maven { url = 'https://repo.spongepowered.org/maven' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'maven-publish'

// ***************************************** //
Expand All @@ -17,25 +20,14 @@ apply plugin: 'maven-publish'
// //
// ***************************************** //
def majorVersion = 3
def minorVersion = 2
def buildVersion = 22
def minorVersion = 3
def buildVersion = 23
def isExperimental = false
version = "${majorVersion}.${minorVersion}.${buildVersion}"
if (isExperimental) {
version += '-experimental'
}

// ***************************************** //
// //
// Janoeo versioning system //
// //
// ***************************************** //
def isJanoeo = false
def janoeoProjectVersion = 6
if (isJanoeo) {
version = "${janoeoProjectVersion}.${version}"
}

group = 'fr.alasdiablo.diolib'
archivesBaseName = 'DiaboloLib'

Expand All @@ -46,7 +38,8 @@ def manifestAttributes = [
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "AlasDiablo, Safyrus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs": "diolib.mixins.json"
]

def outputFolder = file(rootProject.getRootDir().getPath() + '/output')
Expand All @@ -64,6 +57,7 @@ minecraft {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
arg "-mixin.config=diolib.mixins.json"
mods {
diolib {
source sourceSets.main
Expand All @@ -75,6 +69,7 @@ minecraft {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
arg "-mixin.config=diolib.mixins.json"
mods {
diolib {
source sourceSets.main
Expand All @@ -86,7 +81,7 @@ minecraft {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
args '--mod', 'diolib', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
args '-mixin.config=diolib.mixins.json', '--mod', 'diolib', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
diolib {
source sourceSets.main
Expand All @@ -96,13 +91,18 @@ minecraft {
}
}

mixin {
add sourceSets.main, 'diolib.mixins.refmap.json'
}

sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.18.1-39.0.17'
annotationProcessor 'org.spongepowered:mixin:0.8.4:processor'
}

jar {
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.3.23

+ Add mixin processor to add more element into `PowderSnowBlock.canEntityWalkOnPowderSnow`

### 3.2.22

+ Add missing element into SimpleUnicode
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/fr/alasdiablo/diolib/DiaboloLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import fr.alasdiablo.diolib.config.DiaboloLibConfig;
import fr.alasdiablo.diolib.event.FireworkEvent;
import fr.alasdiablo.diolib.tag.DioTags;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -17,5 +20,10 @@ public class DiaboloLib {
public DiaboloLib() {
MinecraftForge.EVENT_BUS.addListener(FireworkEvent.FIREWORK_EVENT::onEvent);
DiaboloLibConfig.init();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
}

private void setup(final FMLCommonSetupEvent commonSetupEvent) {
DioTags.init();
}
}
28 changes: 28 additions & 0 deletions src/main/java/fr/alasdiablo/diolib/mixin/PowderSnowBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.alasdiablo.diolib.mixin;

import fr.alasdiablo.diolib.tag.DioTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.PowderSnowBlock;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = PowderSnowBlock.class, priority = 0)
public class PowderSnowBlockMixin {

@Inject(method = "canEntityWalkOnPowderSnow", at = @At("RETURN"), cancellable = true)
private static void canEntityWalkOnPowderSnow(Entity entity, @NotNull CallbackInfoReturnable<Boolean> callback) {
if (!callback.getReturnValue()) {
if (entity instanceof LivingEntity livingEntity) {
var boots = livingEntity.getItemBySlot(EquipmentSlot.FEET);
if (DioTags.BOOTS_WALK_ON_POWDER_SNOW.contains(boots.getItem())) {
callback.setReturnValue(true);
}
}
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/fr/alasdiablo/diolib/tag/DioTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.alasdiablo.diolib.tag;

import fr.alasdiablo.diolib.DiaboloLib;
import fr.alasdiablo.diolib.registries.RegistryHelper;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.Tags;
import org.jetbrains.annotations.NotNull;

public class DioTags {
public static final Tags.IOptionalNamedTag<Item> BOOTS_WALK_ON_POWDER_SNOW = tag("boots_walk_on_powder_snow");

public static void init() {}

private static @NotNull Tags.IOptionalNamedTag<Item> tag(String name) {
return ItemTags.createOptional(RegistryHelper.rl(DiaboloLib.MOD_ID, name));
}
}
13 changes: 13 additions & 0 deletions src/main/resources/diolib.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"minVersion": "0.8",
"required": true,
"compatibilityLevel": "JAVA_17",
"refmap": "diolib.mixins.refmap.json",
"package": "fr.alasdiablo.diolib.mixin",
"mixins": [
"PowderSnowBlockMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 7bdfb2b

Please sign in to comment.