-
Bug
-
Resolution: Duplicate
-
None
-
Minecraft 1.12.2
-
None
-
Unconfirmed
Dispensers and droppers have a very odd behaviour in code. When placed into the world they are placed in the direction facing towards the player. The odd behaviour happens in the code and not visually visible to the player. But as it might be relevant for future development it might be worth looking into as there rotation is changed several times and will cause issues if not fixed. Although at the moment they are rotated into the final correct position but not when placed into the world by other means.
When talking about dispensers it is assumed that the same behaviour applies to droppers as well. They both use the same lines of code for being placed into the world. The relevant issue is that they are placed into the world in ItemBlock.java in the method onItemUse method.
They first get placed into the world by the funtion call onBlockPlaced. Then there block state is checked by the method setBlockState and lastly the method onBlockPlacedBy is called. These 3 method calls all rotate the dispenser in different directions if the dispenser is placed facing a solid block. This happens when the funtion setBlockState is called. After following the chain of methods down the line, setBlockState in world.java, setBlockState in chunk.java then onBlockAdded in BlockDispenser.java a very odd method is called. setDefaultDirection is a method that does something that seams to not make sense in the least bit. A dispenser is not supposed to rotate on its own but this method does it for the player forcing the dispenser to rotate away from the solid surface. This rotation is later corrected by the 3rd method in originating method ItemBlock. There the dispenser is finally corrected back into the correct position again.
This seams like a very odd bug and should probably be looked into. This bug first showed itself when attempting to place the dispenser into the world with a mod and later caused issues when adding movable dispensers into the game with a mod. It will create issues in future if dispensers ever become movable.
TL.DR
Remove the method setDefaultDirection from BlockDispenser.java as it has no purpose at all other then create odd behaviours in code that might become problematic in the future.
This can clearly be seen when looking at the method.
private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); boolean flag = worldIn.getBlockState(pos.north()).isFullBlock(); boolean flag1 = worldIn.getBlockState(pos.south()).isFullBlock(); if (enumfacing == EnumFacing.NORTH && flag && !flag1) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && flag1 && !flag) { enumfacing = EnumFacing.NORTH; } else { boolean flag2 = worldIn.getBlockState(pos.west()).isFullBlock(); boolean flag3 = worldIn.getBlockState(pos.east()).isFullBlock(); if (enumfacing == EnumFacing.WEST && flag2 && !flag3) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && flag3 && !flag2) { enumfacing = EnumFacing.WEST; } } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing).withProperty(TRIGGERED, Boolean.valueOf(false)), 2); } }
This block of code shows clearly that it doesn't have any purpose other then rotating the dispenser away from a solid block its been placed towards. The rotation is later corrected in a different method again to the original player intended direction making this method completely mute and pointless.
This method was investigated thoroughly and no instance other then placement into the world was it called making its purpose completely redundant.
- duplicates
-
MC-70188 Some blocks cannot be placed facing a wall with /setblock or /fill + datavalues or block states
- Resolved