use of lumien.randomthings.tileentity.TileEntityFilteredRedirectorPlate in project Random-Things by lumien231.
the class BlockFilteredRedirectorPlate method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
Vec3d motionVec = new Vec3d(entityIn.motionX, entityIn.motionY, entityIn.motionZ);
EnumFacing roughMovingFacing = EnumFacing.getFacingFromVector((float) motionVec.x, (float) motionVec.y, (float) motionVec.z).getOpposite();
Vec3d center = new Vec3d(pos).addVector(0.5, 0, 0.5);
Vec3d difVec = center.subtract(entityIn.getPositionVector());
EnumFacing facing = EnumFacing.getFacingFromVector((float) difVec.x, (float) difVec.y, (float) difVec.z).getOpposite();
EnumFacing inputSide = state.getValue(INPUT_FACING);
if ((facing == inputSide || facing == inputSide.getOpposite()) && facing == roughMovingFacing) {
TileEntityFilteredRedirectorPlate te = (TileEntityFilteredRedirectorPlate) worldIn.getTileEntity(pos);
EntityFilterItemStack[] filter = te.getFilter();
EnumFacing output = facing.getOpposite();
if (filter[0] != null) {
if (filter[0].apply(entityIn)) {
output = inputSide.rotateY();
}
}
if (filter[1] != null) {
if (filter[1].apply(entityIn)) {
output = inputSide.rotateYCCW();
}
}
Vec3d facingVec = new Vec3d(output.getDirectionVec()).scale(0.4).add(center);
float dif = facing.getOpposite().getHorizontalAngle() - output.getHorizontalAngle();
Vec3d outputMotionVec = motionVec.rotateYaw((float) Math.toRadians(dif));
entityIn.setPosition(facingVec.x, facingVec.y, facingVec.z);
entityIn.motionX = outputMotionVec.x;
entityIn.motionY = outputMotionVec.y;
entityIn.motionZ = outputMotionVec.z;
}
}
Aggregations