Skip to content

Commit

Permalink
Improve rotation support for various Botania blocks (#4506)
Browse files Browse the repository at this point in the history
Adds support for structure block rotation and mirroring to Manatide
Bellows, Fel Pumpkin, Incense Plate, Mana Pump, and Tiny Potato blocks.
This also fixes #4201 by allowing the Wand of the Forest to rotate these
blocks when clicking their sides.
  • Loading branch information
TheRealWormbo authored Dec 13, 2023
1 parent 3d9b50a commit 877fc54
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.mixin.MobAccessor;

import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
Expand Down Expand Up @@ -62,4 +66,15 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
return defaultBlockState().setValue(BlockStateProperties.HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite());
}

@NotNull
@Override
public BlockState mirror(@NotNull BlockState state, Mirror mirror) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, mirror.mirror(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public BlockState rotate(@NotNull BlockState state, Rotation rot) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, rot.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -91,6 +93,18 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(BlockStateProperties.HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite());
}

@NotNull
@Override
public BlockState mirror(@NotNull BlockState state, Mirror mirror) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, mirror.mirror(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public BlockState rotate(@NotNull BlockState state, Rotation rot) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, rot.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -115,6 +113,18 @@ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return super.getStateForPlacement(ctx).setValue(BlockStateProperties.HORIZONTAL_FACING, ctx.getHorizontalDirection().getOpposite());
}

@NotNull
@Override
public BlockState mirror(@NotNull BlockState state, Mirror mirror) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, mirror.mirror(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public BlockState rotate(@NotNull BlockState state, Rotation rot) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, rot.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity living, ItemStack stack) {
if (stack.hasCustomHoverName() && world.getBlockEntity(pos) instanceof TinyPotatoBlockEntity tater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -64,6 +62,18 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(BlockStateProperties.HORIZONTAL_FACING, context.getHorizontalDirection());
}

@NotNull
@Override
public BlockState mirror(@NotNull BlockState state, Mirror mirror) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, mirror.mirror(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public BlockState rotate(@NotNull BlockState state, Rotation rot) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, rot.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (PlayerHelper.isTruePlayer(player)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -54,6 +56,18 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(BlockStateProperties.HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite());
}

@NotNull
@Override
public BlockState mirror(@NotNull BlockState state, Mirror mirror) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, mirror.mirror(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public BlockState rotate(@NotNull BlockState state, Rotation rot) {
return state.setValue(BlockStateProperties.HORIZONTAL_FACING, rot.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
}

@NotNull
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext ctx) {
Expand Down

0 comments on commit 877fc54

Please sign in to comment.