Skip to content

Commit

Permalink
Allow Double Chest placement via protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th authored Jun 28, 2022
1 parent 6dc7b62 commit 22056fc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/carpetextra/utils/BlockPlacer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package carpetextra.utils;

import org.jetbrains.annotations.Nullable;
import net.minecraft.block.BedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.ComparatorBlock;
import net.minecraft.block.RepeaterBlock;

import net.minecraft.block.enums.ChestType;
import net.minecraft.world.World;

import org.jetbrains.annotations.Nullable;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.ComparatorMode;
import net.minecraft.block.enums.SlabType;
Expand All @@ -19,6 +24,17 @@

public class BlockPlacer
{
private static boolean isBlockAttachableChest(Block originBlock, Direction facing, BlockPos checkPos, World world) {
BlockState checkState = world.getBlockState(checkPos);
if (checkState == null) {
return false;
}
if (originBlock.equals(checkState.getBlock())) {
return checkState.get(ChestBlock.FACING).equals(facing) && checkState.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE;
}
return false;
}

public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)
{
Vec3d hitPos = context.getHitPos();
Expand Down Expand Up @@ -68,6 +84,16 @@ else if (facingIndex >= 0 && facingIndex <= 5)

state = state.with(directionProp, facing);
}
if (block instanceof ChestBlock)
{
if (isBlockAttachableChest(block, facing, blockPos.offset(facing.rotateYClockwise()), context.getWorld())) {
state = state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT);
}
else if (isBlockAttachableChest(block, facing, blockPos.offset(facing.rotateYCounterclockwise()), context.getWorld())) {
state = state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT);
}
state = state.with(ChestBlock.CHEST_TYPE, ChestType.SINGLE);
}
}
else if (state.contains(Properties.AXIS))
{
Expand Down

0 comments on commit 22056fc

Please sign in to comment.