-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/github/kasuminova/stellarcore/mixin/psi/MixinPieceTrickPlaceBlock.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,58 @@ | ||
package github.kasuminova.stellarcore.mixin.psi; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.item.ItemBlock; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import vazkii.psi.common.spell.trick.block.PieceTrickPlaceBlock; | ||
|
||
@Mixin(PieceTrickPlaceBlock.class) | ||
public abstract class MixinPieceTrickPlaceBlock { | ||
|
||
@Inject( | ||
method = "placeBlock(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;IZZ)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lvazkii/psi/common/spell/trick/block/PieceTrickPlaceBlock;removeFromInventory(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;" | ||
), | ||
remap = false, | ||
cancellable = true | ||
) | ||
private static void injectPlaceBlock(final EntityPlayer player, final World world, final BlockPos pos, final int slot, final boolean particles, final boolean conjure, final CallbackInfo ci) { | ||
ItemStack itemBlockStack = player.inventory.getStackInSlot(slot); | ||
ItemBlock itemBlock = (ItemBlock) itemBlockStack.getItem(); | ||
EnumHand hand = player.getActiveHand(); | ||
switch (hand) { | ||
case MAIN_HAND -> stellar_core$swapItemStack(player, player.inventory.currentItem, slot); | ||
case OFF_HAND -> stellar_core$swapItemStack(player, 0, slot); | ||
} | ||
|
||
if (!world.mayPlace(itemBlock.getBlock(), pos, false, EnumFacing.UP, player)) { | ||
ci.cancel(); | ||
} | ||
|
||
switch (hand) { | ||
case MAIN_HAND -> stellar_core$swapItemStack(player, player.inventory.currentItem, slot); | ||
case OFF_HAND -> stellar_core$swapItemStack(player, 0, slot); | ||
} | ||
} | ||
|
||
@Unique | ||
private static void stellar_core$swapItemStack(final EntityPlayer player, final int currItemIdx, final int slot) { | ||
InventoryPlayer inventory = player.inventory; | ||
|
||
ItemStack tmp = inventory.getStackInSlot(slot); | ||
inventory.setInventorySlotContents(slot, inventory.getStackInSlot(currItemIdx)); | ||
inventory.setInventorySlotContents(currItemIdx, tmp); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/github/kasuminova/stellarcore/mixin/specialmobs/MixinSpecialMobReplacer.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,33 @@ | ||
package github.kasuminova.stellarcore.mixin.specialmobs; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import fathertoast.specialmobs.SpecialMobReplacer; | ||
import fathertoast.specialmobs.bestiary.EnumMobFamily; | ||
import github.kasuminova.stellarcore.common.util.StellarLog; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
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; | ||
|
||
@SuppressWarnings("MethodMayBeStatic") | ||
@Mixin(SpecialMobReplacer.class) | ||
public class MixinSpecialMobReplacer { | ||
|
||
@Inject( | ||
method = "replace", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;)V" | ||
), | ||
remap = false | ||
) | ||
private void injectReplace(final EnumMobFamily mobFamily, final boolean isSpecial, final Entity entityToReplace, final World world, final BlockPos entityPos, | ||
final CallbackInfo ci, | ||
@Local(name = "var11") final Exception var11) { | ||
StellarLog.LOG.warn("Logging exception for SpecialMobs mod.", var11); | ||
} | ||
|
||
} |
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,10 @@ | ||
{ | ||
"package": "github.kasuminova.stellarcore.mixin.psi", | ||
"refmap": "mixins.stellar_core.refmap.json", | ||
"target": "@env(DEFAULT)", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"MixinPieceTrickPlaceBlock" | ||
] | ||
} |
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,10 @@ | ||
{ | ||
"package": "github.kasuminova.stellarcore.mixin.specialmobs", | ||
"refmap": "mixins.stellar_core.refmap.json", | ||
"target": "@env(DEFAULT)", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"MixinSpecialMobReplacer" | ||
] | ||
} |