-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix CampfireMixin * Fix EnchantApplyMixin. Refactor EnchantEvent to contain levels spent instead of enchantment details * Revert "Fix EnchantApplyMixin. Refactor EnchantEvent to contain levels spent instead of enchantment details" This reverts commit dff1d53. * Implement MixinPlugin. Use selective mixin loading for dev/prod environments * Split Campfire Mixin into Dev and Prod variants * Improve MixinPlugin - filter prod/dev designation and accept default * Fix EnchantApplyMixin * update mixin to remove local capture logic * fix call side to not fail on dedicated server --------- Co-authored-by: dankos <dankos@nope.com> Co-authored-by: cubiferous <-> Co-authored-by: Caltinor <62700786+Caltinor@users.noreply.github.com>
- Loading branch information
1 parent
5918d02
commit 7c49be7
Showing
6 changed files
with
89 additions
and
35 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/harmonised/pmmo/mixin/CampfireMixin_Dev.java
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,26 @@ | ||
package harmonised.pmmo.mixin; | ||
|
||
import harmonised.pmmo.api.events.FurnaceBurnEvent; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.Container; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.CampfireBlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.common.MinecraftForge; | ||
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.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@Mixin(CampfireBlockEntity.class) | ||
public class CampfireMixin_Dev { | ||
@Inject(at=@At(value = "INVOKE", | ||
target = "Lnet/minecraft/world/Containers;dropItemStack(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/item/ItemStack;)V"), | ||
method = "cookTick(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/CampfireBlockEntity;)V", | ||
locals = LocalCapture.CAPTURE_FAILHARD) | ||
private static void postFurnaceBurnEvent(Level pLevel, BlockPos pPos, BlockState pState, CampfireBlockEntity pBlockEntity, CallbackInfo ci, boolean flag, int i, ItemStack itemstack, int j, Container container, ItemStack itemstack1) { | ||
MinecraftForge.EVENT_BUS.post(new FurnaceBurnEvent(itemstack1, pLevel, pPos)); | ||
} | ||
} |
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
27 changes: 11 additions & 16 deletions
27
src/main/java/harmonised/pmmo/mixin/EnchantApplyMixin.java
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 |
---|---|---|
@@ -1,33 +1,28 @@ | ||
package harmonised.pmmo.mixin; | ||
|
||
import java.util.List; | ||
|
||
import org.spongepowered.asm.mixin.Debug; | ||
import net.minecraft.world.item.enchantment.EnchantmentInstance; | ||
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.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import harmonised.pmmo.api.events.EnchantEvent; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.EnchantmentMenu; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.EnchantmentInstance; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Debug | ||
@Mixin(EnchantmentMenu.class) | ||
public class EnchantApplyMixin { | ||
|
||
@Inject(method = "lambda$clickMenuButton$1(Lnet/minecraft/world/item/ItemStack;ILnet/minecraft/world/entity/player/Player;ILnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V", | ||
public class EnchantApplyMixin { | ||
@Inject(method = "clickMenuButton(Lnet/minecraft/world/entity/player/Player;I)Z", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/item/ItemStack;enchant(Lnet/minecraft/world/item/enchantment/Enchantment;I)V"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT) | ||
private void projectmmo$$enchantHandle(ItemStack $$stack, int $$1x, Player player, int $$3x, ItemStack $$4x, Level $$5, BlockPos $$6, CallbackInfo ci, ItemStack stack, List<?> $$8, boolean $$9, int $$11, EnchantmentInstance instance) { | ||
MinecraftForge.EVENT_BUS.post(new EnchantEvent(player, stack, instance)); | ||
target = "Lnet/minecraft/world/inventory/ContainerLevelAccess;execute(Ljava/util/function/BiConsumer;)V")) | ||
private void projectmmo$$enchantHandle(Player player, int pId, CallbackInfoReturnable<Boolean> cir) { | ||
EnchantmentMenu menu = ((EnchantmentMenu)(Object)this); | ||
ItemStack stack = menu.enchantSlots.getItem(0); | ||
for (EnchantmentInstance instance : menu.getEnchantmentList(stack, pId, menu.costs[pId])) { | ||
MinecraftForge.EVENT_BUS.post(new EnchantEvent(player, stack, instance)); | ||
} | ||
} | ||
} |
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,42 @@ | ||
package harmonised.pmmo.mixin; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import net.minecraftforge.fml.loading.FMLLoader; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
|
||
public final class MixinPlugin implements IMixinConfigPlugin { | ||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
if (mixinClassName.endsWith("_Dev") && !isDevelopmentEnv()) return false; | ||
if (mixinClassName.endsWith("_Prod") && isDevelopmentEnv()) return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) {} | ||
|
||
@Override | ||
public String getRefMapperConfig() { return null; } | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {} | ||
|
||
@Override | ||
public List<String> getMixins() { return null; } | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} | ||
|
||
private boolean isDevelopmentEnv() { | ||
return !FMLLoader.isProduction(); | ||
} | ||
} |
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