Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mixin and hook to prevent being LivingEquipmentChangeEvent consta… #7906

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
id 'maven-publish'
id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'org.spongepowered.mixin' version '0.7.+'
}

tasks.named('wrapper', Wrapper).configure {
Expand Down Expand Up @@ -327,11 +328,18 @@ minecraft {
}
}

mixin {
// MixinGradle Settings
add sourceSets.main, 'mixins.mekanism.refmap.json'
config 'mixins.mekanism.json'
}

def setupRunConfig(RunConfig runConfig, boolean supportsGameTests, String directory = "run") {
runConfig.workingDirectory(file(directory))
//This fixes Mixin application problems from other mods because their refMaps are SRG-based, but we're in a MCP env
runConfig.property 'mixin.env.remapRefMap', 'true'
runConfig.property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
//handled by mixin plugin
//runConfig.property 'mixin.env.remapRefMap', 'true'
//runConfig.property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
if (supportsGameTests) {
//Specify all our mods as domains to look for game tests
runConfig.property 'forge.enabledGameTestNamespaces', 'mekanism,mekanismadditions,mekanismdefense,mekanismgenerators,mekanismtools'
Expand Down Expand Up @@ -406,6 +414,7 @@ dependencies {
minecraft "net.neoforged:forge:${minecraft_version}-${forge_version}"

annotationProcessor project(":annotation-processor")
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'

testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,15 @@
}
return ret;
}

/**
* Hook of {@link net.minecraft.world.entity.LivingEntity#equipmentHasChanged(ItemStack, ItemStack)}.
*
* @param oldItem the previous stack in the slot
* @param newItem the current stack in the slot. Item will be the same as oldItem param
* @return true if the equipment has changed and needs to trigger attribute modifier calculations and the {@link net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent event}
*/
default boolean hasEquipmentChanged(ItemStack oldItem, ItemStack newItem) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
return false;//modules can't change while in an equipment slot
}
}
20 changes: 20 additions & 0 deletions src/main/java/mekanism/mixin/MixinLivingEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mekanism.mixin;

import mekanism.common.content.gear.IModuleContainerItem;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
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(LivingEntity.class)
public class MixinLivingEntity {

@Inject(method = "equipmentHasChanged", at = @At("HEAD"), cancellable = true)
public void equipmentHasChanged$handleMekGear(ItemStack oldItem, ItemStack newItem, CallbackInfoReturnable<Boolean> ci) {
if (oldItem.getItem() == newItem.getItem() && newItem.getItem() instanceof IModuleContainerItem containerItem) {
ci.setReturnValue(containerItem.hasEquipmentChanged(oldItem, newItem));
}
}
}
7 changes: 7 additions & 0 deletions src/main/resources/mixins.mekanism.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mekanism.mixin",
"refmap": "mixins.mekanism.refmap.json",
"mixins": [
"MixinLivingEntity"
]
}