forked from maruohon/litematica
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-fix: A more reliable way to fix the Stair Shape Mirroring via a Mi…
…xin into the Stairs Block Mirror function.
- Loading branch information
1 parent
c8650e5
commit 8d6932f
Showing
11 changed files
with
1,949 additions
and
2,003 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
71 changes: 71 additions & 0 deletions
71
src/main/java/fi/dy/masa/litematica/mixin/MixinStairsBlock.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,71 @@ | ||
package fi.dy.masa.litematica.mixin; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.StairsBlock; | ||
import net.minecraft.block.enums.StairShape; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
import net.minecraft.util.math.Direction; | ||
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; | ||
|
||
import fi.dy.masa.litematica.config.Configs; | ||
|
||
import static net.minecraft.block.StairsBlock.FACING; | ||
import static net.minecraft.block.StairsBlock.SHAPE; | ||
|
||
@Mixin(StairsBlock.class) | ||
public abstract class MixinStairsBlock extends Block | ||
{ | ||
public MixinStairsBlock(Settings settings) | ||
{ | ||
super(settings); | ||
} | ||
|
||
@Inject(method = "mirror", at = @At(value = "HEAD"), cancellable = true) | ||
private void litematica_fixStairsMirror(BlockState state, BlockMirror mirror, CallbackInfoReturnable<BlockState> cir) | ||
{ | ||
if (Configs.Generic.FIX_STAIRS_MIRROR.getBooleanValue()) | ||
{ | ||
Direction direction = state.get(FACING); | ||
StairShape stairShape = state.get(SHAPE); | ||
|
||
// Fixes X Axis for FRONT_BACK being inverted for INNER_LEFT / INNER_RIGHT | ||
if (direction.getAxis() == Direction.Axis.X && mirror == BlockMirror.FRONT_BACK) | ||
{ | ||
cir.setReturnValue( | ||
switch (stairShape) | ||
{ | ||
case INNER_LEFT -> state.rotate(BlockRotation.CLOCKWISE_180).with(SHAPE, StairShape.INNER_RIGHT); | ||
case INNER_RIGHT -> state.rotate(BlockRotation.CLOCKWISE_180).with(SHAPE, StairShape.INNER_LEFT); | ||
case OUTER_LEFT -> state.rotate(BlockRotation.CLOCKWISE_180).with(SHAPE, StairShape.OUTER_RIGHT); | ||
case OUTER_RIGHT -> state.rotate(BlockRotation.CLOCKWISE_180).with(SHAPE, StairShape.OUTER_LEFT); | ||
default -> state.rotate(BlockRotation.CLOCKWISE_180); | ||
} | ||
); | ||
|
||
cir.cancel(); | ||
} | ||
// Fixes missing Axis STAIR_SHAPE flips | ||
else if ((direction.getAxis() == Direction.Axis.X && mirror == BlockMirror.LEFT_RIGHT) || | ||
(direction.getAxis() == Direction.Axis.Z && mirror == BlockMirror.FRONT_BACK)) | ||
{ | ||
cir.setReturnValue( | ||
switch (stairShape) | ||
{ | ||
case INNER_LEFT -> state.with(SHAPE, StairShape.INNER_RIGHT); | ||
case INNER_RIGHT -> state.with(SHAPE, StairShape.INNER_LEFT); | ||
case OUTER_LEFT -> state.with(SHAPE, StairShape.OUTER_RIGHT); | ||
case OUTER_RIGHT -> state.with(SHAPE, StairShape.OUTER_LEFT); | ||
default -> state; | ||
} | ||
); | ||
|
||
cir.cancel(); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.