-
Notifications
You must be signed in to change notification settings - Fork 84
AccurateBlockPlacement now support FacingBlocks #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
fc894c2
ff13143
a0656d8
8fa254c
7b5e11d
149bf04
13a7f4d
a24b9c7
1085cd8
b878f56
ca07715
0d2ec7a
fa9bc70
021cea7
5ddd5b0
8180a63
3e7f511
7f7d98b
b930c95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,117 +2,167 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import net.minecraft.block.Block; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.BlockState; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.AbstractRailBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.ChestBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.ComparatorBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.DispenserBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.DetectorRailBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.FacingBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.GlazedTerracottaBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.HorizontalFacingBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.ObserverBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.PistonBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.PoweredRailBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.RailBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.RepeaterBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.StairsBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.TrapdoorBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.WallMountedBlock; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.enums.BlockHalf; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.enums.ChestType; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.enums.ComparatorMode; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.block.enums.RailShape; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.entity.player.PlayerEntity; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.item.ItemPlacementContext; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.state.property.DirectionProperty; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.state.property.Property; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.util.math.BlockPos; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.util.math.Direction; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.util.math.MathHelper; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.util.math.Vec3d; | ||||||||||||||||||||||||||||||||||
| import net.minecraft.world.World; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public class BlockPlacer | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| public class BlockPlacer { | ||||||||||||||||||||||||||||||||||
| private static Boolean HasDirectionProperty(BlockState state) { | ||||||||||||||||||||||||||||||||||
| //malilib code | ||||||||||||||||||||||||||||||||||
| for (Property<?> prop : state.getProperties()) { | ||||||||||||||||||||||||||||||||||
| if (prop instanceof DirectionProperty) { | ||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static DirectionProperty getFirstDirectionProperty(BlockState state) { | ||||||||||||||||||||||||||||||||||
| //malilib code | ||||||||||||||||||||||||||||||||||
| for (Property<?> prop : state.getProperties()) { | ||||||||||||||||||||||||||||||||||
| if (prop instanceof DirectionProperty) { | ||||||||||||||||||||||||||||||||||
| return (DirectionProperty) prop; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static Boolean IsBlockAttachableChest(Block originBlock, Direction Facing, BlockPos checkPos, World world) { | ||||||||||||||||||||||||||||||||||
| BlockState checkState = world.getBlockState(checkPos); | ||||||||||||||||||||||||||||||||||
| if (checkState == null) { | ||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (originBlock.getName().equals(checkState.getBlock().getName())) { | ||||||||||||||||||||||||||||||||||
| return checkState.get(ChestBlock.FACING).equals(Facing) && checkState.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| private static Boolean IsBlockAttachableChest(Block originBlock, Direction Facing, BlockPos checkPos, World world) { | |
| BlockState checkState = world.getBlockState(checkPos); | |
| if (checkState == null) { | |
| return false; | |
| } | |
| if (originBlock.getName().equals(checkState.getBlock().getName())) { | |
| return checkState.get(ChestBlock.FACING).equals(Facing) && checkState.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE; | |
| } | |
| private static boolean isBlockAttachableChest(Block originBlock, Direction facing, BlockPos checkPos, World world) { | |
| BlockState checkState = world.getBlockState(checkPos); | |
| if (checkState == null) { | |
| return false; | |
| } | |
| if (originBlock.getName().equals(checkState.getBlock().getName())) { | |
| return checkState.get(ChestBlock.FACING).equals(facing) && checkState.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE; | |
| } |
Also isn't there a better way than checking the name of the block? I think there must be some other method to checking the state equals.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here this could be something like
DirectionProperty directionProperty = getFirstDirectionProperty(state);
if (... && directionProperty != null)and then keep the directionProperty for use later.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| int FacingId = code % 16; | |
| facing = Direction.byId(FacingId); | |
| int facingId = code % 16; | |
| facing = Direction.byId(facingId); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only way of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it can use .Direction.rotateYClockwise() and rotateYCounterclockwise() instead of repeated facing checks, I'll try it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this and instead save the result of
getFirstDirectionPropertyin a field (since it will be needed later anyway) and check!= null