-
Notifications
You must be signed in to change notification settings - Fork 62
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
AccurateBlockPlacement now support FacingBlocks #228
Conversation
chest has wierdness, so maybe should be checked next time
its not coded in tweakeroo / litematica, so we can't define its defaultstate (FACE) property.
Let's see what's still not supported.. Grindstone, however, it can be placed 'facing' correctly but it does not refelect its 'attached side' so I removed all wallmountedblocks, to prevent ghost block and errors. Doorblock needs 'hinge' too, but usually it does nothing so its remaining. |
Chest is not supported: its rotation can work correctly, but its double/single behavior is locational. Should be fixed when its solved. |
Fixed ChestBlock behavior, it mimics vanilla. |
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.
Small review, not really code review, mostly code style (not tested).
Also some changes to style could be reverted (like lines 25-26 being changed), and there's places where code look better with spaces after the commas.
private static Boolean HasDirectionProperty(BlockState state) { | ||
//malilib code | ||
for (Property<?> prop : state.getProperties()) { | ||
if (prop instanceof DirectionProperty) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
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 getFirstDirectionProperty
in a field (since it will be needed later anyway) and check != 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; | ||
} |
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.
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.
Vec3d vec3d = context.getHitPos(); | ||
BlockPos pos = context.getBlockPos(); | ||
double hitX = vec3d.x - pos.getX(); | ||
if (hitX<2) // vanilla | ||
BlockState state = block.getDefaultState(); | ||
if (hitX < 2 || !(block instanceof AbstractRailBlock) && !HasDirectionProperty(state)) // vanilla |
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.
int FacingId = code % 16; | ||
facing = Direction.byId(FacingId); |
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); |
if (facing == Direction.SOUTH) { | ||
if (IsBlockAttachableChest(block, facing, pos.west(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT); | ||
} | ||
if (IsBlockAttachableChest(block, facing, pos.east(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT); | ||
} | ||
} else if (facing == Direction.WEST) //-z +z | ||
{ | ||
if (IsBlockAttachableChest(block, facing, pos.north(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT); | ||
} | ||
if (IsBlockAttachableChest(block, facing, pos.south(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT); | ||
} | ||
} else if (facing == Direction.NORTH) //+x -x | ||
{ | ||
if (IsBlockAttachableChest(block, facing, pos.east(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT); | ||
} | ||
if (IsBlockAttachableChest(block, facing, pos.west(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT); | ||
} | ||
} else if (facing == Direction.EAST) //+z -z | ||
{ | ||
if (IsBlockAttachableChest(block, facing, pos.south(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT); | ||
} | ||
if (IsBlockAttachableChest(block, facing, pos.north(), world)) { | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT); | ||
} | ||
} | ||
return state.with(ChestBlock.CHEST_TYPE, ChestType.SINGLE); |
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
Should probably fix this |
I'll work on that |
Fixed bed bug, will not rotate when its impossible to place. but I found new bug related to this,yes, doors. will fix it soon. |
Fixed bed and door block bug. |
#release-curse-versions = 1.16.4,1.16.5 | ||
# Whether or not to build another branch on release | ||
release-extra-branch = true | ||
#release-extra-branch = true | ||
# The name of the second branch to release | ||
release-extra-branch-name = 1.17 | ||
#release-extra-branch-name = 1.17 | ||
# The "name" or id of the Curseforge version for the secondary branch | ||
# This is needed because CF uses too vague names for snapshots | ||
# Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN] | ||
release-extra-curse-version = 1.17.1 | ||
#release-extra-curse-version = 1.17.1 |
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.
Why comment those?
Closing in favour of #267. |
tested with fence gate, lentern, end portal frame, stairs, hoppers, chest(somehow buggy), barrel, redstone components, bed, bee hive, grindstone.