-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If an error happens on place, untransform
- Loading branch information
Showing
1 changed file
with
14 additions
and
30 deletions.
There are no files selected for viewing
44 changes: 14 additions & 30 deletions
44
...java/org/valkyrienskies/mod/mixin/feature/block_placement_orientation/MixinBlockItem.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,50 +1,34 @@ | ||
package org.valkyrienskies.mod.mixin.feature.block_placement_orientation; | ||
|
||
import net.minecraft.world.InteractionResult; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.At.Shift; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
import org.valkyrienskies.mod.common.PlayerUtil; | ||
|
||
@Mixin(BlockItem.class) | ||
public abstract class MixinBlockItem { | ||
|
||
@Inject( | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;" | ||
), | ||
method = "place", | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void transformPlayerWhenPlacing(final BlockPlaceContext ignore, | ||
final CallbackInfoReturnable<InteractionResult> cir, final BlockPlaceContext context) { | ||
if (context == null || context.getPlayer() == null) { | ||
return; | ||
} | ||
|
||
PlayerUtil.transformPlayerTemporarily(context.getPlayer(), context.getLevel(), context.getClickedPos()); | ||
} | ||
|
||
@Inject( | ||
@WrapOperation( | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;", | ||
shift = Shift.AFTER | ||
target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;" | ||
), | ||
method = "place" | ||
) | ||
private void untransformPlayerAfterPlacing(final BlockPlaceContext context, | ||
final CallbackInfoReturnable<InteractionResult> cir) { | ||
if (context.getPlayer() == null) { | ||
return; | ||
private BlockState transformPlayerWhenPlacing(BlockItem _instance, BlockPlaceContext _ctx, Operation<BlockState> original, final BlockPlaceContext ctx) { | ||
if (ctx == null || ctx.getPlayer() == null) { | ||
return null; | ||
} | ||
|
||
PlayerUtil.untransformPlayer(context.getPlayer()); | ||
return PlayerUtil.transformPlayerTemporarily( | ||
ctx.getPlayer(), | ||
ctx.getLevel(), | ||
ctx.getClickedPos(), | ||
original::call | ||
); | ||
} | ||
} |